From 27663d80ba8e1f33c196beadc8ea7caa80eaf230 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 4 Apr 2021 21:15:13 +0200 Subject: [PATCH] SVG sample more points for space name position check --- src/serializers/SvgSerializer.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/serializers/SvgSerializer.cpp b/src/serializers/SvgSerializer.cpp index aa2b081bdb..e852d448ca 100644 --- a/src/serializers/SvgSerializer.cpp +++ b/src/serializers/SvgSerializer.cpp @@ -1308,15 +1308,28 @@ void SvgSerializer::write(const geometry_data& data) { 10 * ((pa.X() - pb.X()) * (pa.X() - pb.X())) + 1 * ((pa.Y() - pb.Y()) * (pa.Y() - pb.Y())) ); - if (d > furthest_points_distance) { - gp_Pnt p3d((pa.XYZ() + pb.XYZ()) / 2.); - gp_Pnt2d p2d(p3d.X(), p3d.Y()); - if (fcls.Perform(p2d) == TopAbs_IN) { + if (d > furthest_points_distance) { + + // Sample some points on the line and assure it's inside. + bool all_inside = true; + for (int i = 5; i < 95; ++i) { + gp_Pnt p3d((pa.XYZ() + pb.XYZ()) * i / 100.); + gp_Pnt2d p2d(p3d.X(), p3d.Y()); + + if (fcls.Perform(p2d) != TopAbs_IN) { + all_inside = false; + } + } + + if (all_inside) { + gp_Pnt p3d((pa.XYZ() + pb.XYZ()) * 0.5); + gp_Pnt2d p2d(p3d.X(), p3d.Y()); furthest_points = { &pa, &pb }; furthest_points_distance = d; center_point = p3d; } + } } }