From c90e5095f03de967d03e2e611c058d1832f47f13 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 12 Mar 2024 09:01:54 +0100 Subject: [PATCH] Improve example --- .../Segment_Delaunay_graph_2/data/V.wkt | 1 + .../Segment_Delaunay_graph_2/data/square.wkt | 1 + .../sdg-inscribed-circle.cpp | 39 ++++++++++++------- 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/V.wkt create mode 100644 Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/square.wkt diff --git a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/V.wkt b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/V.wkt new file mode 100644 index 000000000000..9a36437c06db --- /dev/null +++ b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/V.wkt @@ -0,0 +1 @@ +POLYGON ((1 0, 3 0, 4 4, 3 4, 2 1, 1 4, 0 4)) diff --git a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/square.wkt b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/square.wkt new file mode 100644 index 000000000000..2f8e861119b0 --- /dev/null +++ b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/data/square.wkt @@ -0,0 +1 @@ +POLYGON ((0 0, 4 0, 4 4, 0 4)) diff --git a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-inscribed-circle.cpp b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-inscribed-circle.cpp index fde585f37d9c..4ac704d718fe 100644 --- a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-inscribed-circle.cpp +++ b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-inscribed-circle.cpp @@ -25,9 +25,9 @@ typedef CGAL::Segment_Delaunay_graph_traits_2 Gt; typedef CGAL::Segment_Delaunay_graph_2 SDG2; -int main() +int main(int argc, char* argv[]) { - std::ifstream ifs("data/polygon.wkt"); + std::ifstream ifs((argc>1)? argv[1]:"data/polygon.wkt"); assert( ifs ); Polygon_with_holes pwh; @@ -39,20 +39,31 @@ int main() sdg.insert_segments(boundary_polygon.edges_begin(), boundary_polygon.edges_end()); - double sd = 0; + double sd = 0, sqdist = 0; SDG2::Finite_faces_iterator fit = sdg.finite_faces_begin(); - for(; fit != sdg.finite_faces_end(); ++fit){ - if(fit->vertex(0)->site().is_segment() && fit->vertex(1)->site().is_segment() && fit->vertex(2)->site().is_segment()){ - Segment_2 s0 = fit->vertex(0)->site().segment(); - - - Point_2 p = sdg.primal(fit); - std::cout << p << std::endl; - if (boundary_polygon.bounded_side(p) == CGAL::ON_BOUNDED_SIDE) { - double point_segment_sqdist = CGAL::squared_distance(p, s0); - sd = std::max(point_segment_sqdist, sd); + for (; fit != sdg.finite_faces_end(); ++fit) { + Point_2 pp = sdg.primal(fit); + std::cout << "Point " << pp << std::endl; + std::cout << "equidistant to:" << std::endl; + for (int i = 0; i < 3; ++i) { + assert(!sdg.is_infinite(fit->vertex(i))); + if (fit->vertex(i)->site().is_segment()) { + Segment_2 s = fit->vertex(i)->site().segment(); + double sqdist = CGAL::squared_distance(pp, s); + std::cout << " segment " << s << " at distance " << sqrt(sqdist) << std::endl; + } + else { + Point_2 p = fit->vertex(i)->site().point(); + double sqdist = CGAL::squared_distance(pp, p); + std::cout << " point " << p << " at distance " << sqrt(sqdist) << std::endl; + } + } + if (boundary_polygon.bounded_side(pp) == CGAL::ON_BOUNDED_SIDE) { + sd = std::max(sqdist, sd); + } + else { + std::cout << " but ignored as not on bounded side" << std::endl; } - } } std::cout << "radius of largest inscribed circle: " << sqrt(sd) << std::endl; return 0;