From 8597b575417c1e1ca9d51fe2a3e032646e340840 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 13 Sep 2013 14:32:46 +0200 Subject: [PATCH] Fix compilation of Boost intersection --- xs/src/ExPolygon.cpp | 2 ++ xs/src/ExPolygon.hpp | 36 ++++-------------------------------- xs/src/Point.hpp | 2 ++ xs/src/Polygon.cpp | 8 ++++++++ xs/src/Polygon.hpp | 9 +++++++-- xs/src/Polyline.hpp | 8 ++++---- xs/t/14_geometry.t | 25 +++++++++++++------------ xs/xsp/Geometry.xsp | 2 +- 8 files changed, 41 insertions(+), 51 deletions(-) diff --git a/xs/src/ExPolygon.cpp b/xs/src/ExPolygon.cpp index 7ab702fb..e19b442a 100644 --- a/xs/src/ExPolygon.cpp +++ b/xs/src/ExPolygon.cpp @@ -119,10 +119,12 @@ ExPolygon::from_SV_check(SV* expoly_sv) } } +#ifndef NOBOOST bool ExPolygon::encloses_point(Point* point) const { return boost::geometry::covered_by(*point, *this); } +#endif } diff --git a/xs/src/ExPolygon.hpp b/xs/src/ExPolygon.hpp index 20ac64f3..be70cac9 100644 --- a/xs/src/ExPolygon.hpp +++ b/xs/src/ExPolygon.hpp @@ -29,7 +29,7 @@ typedef std::vector ExPolygons; } -// Boost.Geometry +#ifndef NOBOOST namespace boost { namespace geometry { namespace traits { @@ -55,47 +55,19 @@ namespace boost { { static Polygons get(ExPolygon& p) { - return Polygons(Polygons::iterator(p.holes.begin()), Polygons::iterator(p.holes.end())); + return p.holes; } static const Polygons get(ExPolygon const& p) { - return Polygons(Polygons::const_iterator(p.holes.begin()), Polygons::const_iterator(p.holes.end())); + return p.holes; } }; } } } // namespace boost::geometry::traits -#include -namespace boost -{ - // Specialize metafunctions. - template <> - struct range_iterator { typedef Polygons::iterator type; }; - - template<> - struct range_const_iterator { typedef Polygons::const_iterator type; }; - -} // namespace 'boost' - - -// The required Range functions. -namespace Slic3r { - inline Polygons::iterator range_begin(ExPolygon& r) - {return r.holes.begin();} - - inline Polygons::const_iterator range_begin(const ExPolygon& r) - {return r.holes.begin();} - - inline Polygons::iterator range_end(ExPolygon& r) - {return r.holes.end();} - - inline Polygons::const_iterator range_end(const ExPolygon& r) - {return r.holes.end();} -} - #include BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(ExPolygons); -// end Boost.Geometry +#endif #endif diff --git a/xs/src/Point.hpp b/xs/src/Point.hpp index e56c254a..c52be2f9 100644 --- a/xs/src/Point.hpp +++ b/xs/src/Point.hpp @@ -32,9 +32,11 @@ class Point } +#ifndef NOBOOST #include #include BOOST_GEOMETRY_REGISTER_POINT_2D(Point, long, cs::cartesian, x, y); BOOST_GEOMETRY_REGISTER_MULTI_POINT(Points); +#endif #endif diff --git a/xs/src/Polygon.cpp b/xs/src/Polygon.cpp index db7c2b2f..60e2d7d5 100644 --- a/xs/src/Polygon.cpp +++ b/xs/src/Polygon.cpp @@ -118,10 +118,18 @@ Polygon::is_valid() const return this->points.size() >= 3; } +#ifndef NOBOOST bool Polygon::encloses_point(Point* point) const { return boost::geometry::covered_by(*point, *this); } +void +Polygon::push_back(const Point& point) +{ + this->points.push_back(point); +} +#endif + } diff --git a/xs/src/Polygon.hpp b/xs/src/Polygon.hpp index b2454b34..8d97c83f 100644 --- a/xs/src/Polygon.hpp +++ b/xs/src/Polygon.hpp @@ -24,14 +24,19 @@ class Polygon : public MultiPoint { bool make_counter_clockwise(); bool make_clockwise(); bool is_valid() const; + + #ifndef NOBOOST bool encloses_point(Point* point) const; + void push_back(const Point& point); + typedef const Point& const_reference; + #endif }; typedef std::vector Polygons; } -// Boost.Geometry +#ifndef NOBOOST #include BOOST_GEOMETRY_REGISTER_RING(Polygon); @@ -76,6 +81,6 @@ namespace Slic3r { inline Points::const_iterator range_end(const Polygon& poly) {return poly.points.end();} } -// end Boost.Geometry +#endif #endif diff --git a/xs/src/Polyline.hpp b/xs/src/Polyline.hpp index cadbf22e..609e8a4b 100644 --- a/xs/src/Polyline.hpp +++ b/xs/src/Polyline.hpp @@ -15,17 +15,18 @@ class Polyline : public MultiPoint { double length() const; void clip_end(double d); - // for Boost.Geometry: + #ifndef NOBOOST std::size_t size() const; void clear(); const Point& operator[] (const int nIndex) const; + #endif }; typedef std::vector Polylines; } -// Boost.Geometry +#ifndef NOBOOST #include #include BOOST_GEOMETRY_REGISTER_LINESTRING(Polyline) @@ -85,7 +86,6 @@ namespace Slic3r { inline Points::const_iterator range_end(const Polyline& poly) {return poly.points.end();} } -// end B -// end Boost.Geometry +#endif #endif diff --git a/xs/t/14_geometry.t b/xs/t/14_geometry.t index f148f9f7..9a49715e 100644 --- a/xs/t/14_geometry.t +++ b/xs/t/14_geometry.t @@ -8,14 +8,6 @@ use Test::More tests => 1; ok 'okay'; -if (0) { - my $points = [ map { Slic3r::Point->new(20*$_, 10*$_), Slic3r::Point->new(5*$_, 2*$_) } (1..10) ]; - my $hull = Slic3r::Geometry::convex_hull($points); - ok $hull->is_counter_clockwise, 'convex_hull is ccw'; - use XXX; XXX $hull->pp; - is_deeply $hull->pp, [ [5,2], [20,10], [200,100], [50,20], [5,2] ], 'convex_hull'; -} - my $square = [ # ccw [100, 100], [200, 100], @@ -28,12 +20,21 @@ my $hole_in_square = [ # cw [160, 160], [160, 140], ]; -my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square); -my $polyline = Slic3r::Polyline->new([0,150], [300,150]); if (0) { - my $polylines = Slic3r::Geometry::expolygons_polylines_intersection([$expolygon], [$polyline]); - use XXX; XXX map $_->pp, @$polylines; + my $points = [ map Slic3r::Point->new(@$_), @$square ]; + my $hull = Slic3r::Geometry::convex_hull($points); + ok $hull->is_counter_clockwise, 'convex_hull is ccw'; + ok !$hull->[-1]->coincides_with($hull->first_point), 'hull polygon is open'; + use XXX; XXX $hull->pp; + is_deeply $hull->pp, [ [5,2], [20,10], [200,100], [50,20], [5,2] ], 'convex_hull'; +} + +if (0) { + my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square); + my $polyline = Slic3r::Polyline->new([0,150], [300,150]); + my $result = Slic3r::Geometry::expolygons_polylines_intersection([$expolygon], [$polyline]); + use XXX; XXX (map $_->pp, @$result); # fails because Boost isn't honoring winding order and closure yet } diff --git a/xs/xsp/Geometry.xsp b/xs/xsp/Geometry.xsp index fcf12a6f..1dbf014f 100644 --- a/xs/xsp/Geometry.xsp +++ b/xs/xsp/Geometry.xsp @@ -17,7 +17,7 @@ convex_hull(points) const char* CLASS = "Slic3r::Polygon"; CODE: RETVAL = new Polygon; - boost::geometry::convex_hull(points, RETVAL->points); + boost::geometry::convex_hull(points, *RETVAL); OUTPUT: RETVAL