diff --git a/cgal_skeleton_core/Makefile b/cgal_skeleton_core/Makefile index c9a1d7c..208ce2d 100644 --- a/cgal_skeleton_core/Makefile +++ b/cgal_skeleton_core/Makefile @@ -21,7 +21,7 @@ WASI_SOURCES := \ exception_stubs.cpp \ INCLUDES := -I$(CACHEDIR)/$(CGAL)/include -I$(CACHEDIR)/$(BOOST) -CXXFLAGS := -std=c++20 -g -Wall -Wextra -O2 +CXXFLAGS := -std=c++20 -g -Wall -Wextra -O2 -DCGAL_ALWAYS_ROUND_TO_NEAREST WASI_CXXFLAGS := -DCGAL_ALWAYS_ROUND_TO_NEAREST -DCGAL_CORE_USE_BOOST_BACKEND -DCGAL_DISABLE_GMP -DCGAL_USE_BOOST_MP -DFE_UPWARD=FE_TONEAREST -D_WASI_EMULATED_PROCESS_CLOCKS $(CXXFLAGS) LDFLAGS := HOST_LDFLAGS := $(LDFLAGS) -lgmp -lmpfr diff --git a/cgal_skeleton_core/skeleton_wrapper.cpp b/cgal_skeleton_core/skeleton_wrapper.cpp index 1e0af3d..78d7561 100644 --- a/cgal_skeleton_core/skeleton_wrapper.cpp +++ b/cgal_skeleton_core/skeleton_wrapper.cpp @@ -1,12 +1,25 @@ -#include +#include #include #include +#include +#include +#include +#include #include #include #include #include +#include -typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +// Use exact rational arithmetic throughout to avoid filtered predicates +typedef boost::multiprecision::number>> Exact_NT; +typedef CGAL::Simple_cartesian Exact_K; + +// Input kernel with doubles for reading coordinates +typedef CGAL::Simple_cartesian Input_K; + +// Use exact kernel for computation +typedef Exact_K K; typedef K::Point_2 Point; typedef CGAL::Polygon_2 Polygon_2; typedef CGAL::Straight_skeleton_2 Ss; @@ -14,7 +27,6 @@ typedef std::shared_ptr SsPtr; int main() { - // Read polygon from stdin Polygon_2 poly; std::string line; @@ -26,7 +38,8 @@ int main() std::istringstream iss(line); double x, y; if (iss >> x >> y) { - poly.push_back(Point(x, y)); + // Convert double to exact rational + poly.push_back(Point(Exact_NT(x), Exact_NT(y))); } else { std::cerr << "Error: Invalid input line: " << line << std::endl; return EXIT_FAILURE; @@ -38,13 +51,11 @@ int main() return EXIT_FAILURE; } - // Ensure counter-clockwise orientation if (!poly.is_counterclockwise_oriented()) { poly.reverse_orientation(); } - // Create interior straight skeleton - SsPtr ss = CGAL::create_interior_straight_skeleton_2(poly.vertices_begin(), poly.vertices_end()); + SsPtr ss = CGAL::create_interior_straight_skeleton_2(poly.vertices_begin(), poly.vertices_end(), K()); if (!ss) { std::cerr << "Error: Failed to create straight skeleton" << std::endl; @@ -64,6 +75,7 @@ int main() auto v_target = he->opposite()->vertex(); // Get times (distance from boundary) + // Convert from exact rational to double for output double t1 = CGAL::to_double(v_source->time()); double t2 = CGAL::to_double(v_target->time());