mirror of https://github.com/vitalif/Slic3r
Fix compilation of Boost intersection
parent
c0afa13051
commit
8597b57541
|
@ -119,10 +119,12 @@ ExPolygon::from_SV_check(SV* expoly_sv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NOBOOST
|
||||||
bool
|
bool
|
||||||
ExPolygon::encloses_point(Point* point) const
|
ExPolygon::encloses_point(Point* point) const
|
||||||
{
|
{
|
||||||
return boost::geometry::covered_by(*point, *this);
|
return boost::geometry::covered_by(*point, *this);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ typedef std::vector<ExPolygon> ExPolygons;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boost.Geometry
|
#ifndef NOBOOST
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace geometry {
|
namespace geometry {
|
||||||
namespace traits {
|
namespace traits {
|
||||||
|
@ -55,47 +55,19 @@ namespace boost {
|
||||||
{
|
{
|
||||||
static Polygons get(ExPolygon& p)
|
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)
|
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
|
} // namespace boost::geometry::traits
|
||||||
|
|
||||||
#include <boost/range.hpp>
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
// Specialize metafunctions.
|
|
||||||
template <>
|
|
||||||
struct range_iterator<ExPolygon> { typedef Polygons::iterator type; };
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct range_const_iterator<ExPolygon> { 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/multi/geometries/register/multi_polygon.hpp>
|
#include <boost/geometry/multi/geometries/register/multi_polygon.hpp>
|
||||||
BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(ExPolygons);
|
BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(ExPolygons);
|
||||||
// end Boost.Geometry
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,9 +32,11 @@ class Point
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NOBOOST
|
||||||
#include <boost/geometry/geometries/register/point.hpp>
|
#include <boost/geometry/geometries/register/point.hpp>
|
||||||
#include <boost/geometry/multi/geometries/register/multi_point.hpp>
|
#include <boost/geometry/multi/geometries/register/multi_point.hpp>
|
||||||
BOOST_GEOMETRY_REGISTER_POINT_2D(Point, long, cs::cartesian, x, y);
|
BOOST_GEOMETRY_REGISTER_POINT_2D(Point, long, cs::cartesian, x, y);
|
||||||
BOOST_GEOMETRY_REGISTER_MULTI_POINT(Points);
|
BOOST_GEOMETRY_REGISTER_MULTI_POINT(Points);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -118,10 +118,18 @@ Polygon::is_valid() const
|
||||||
return this->points.size() >= 3;
|
return this->points.size() >= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NOBOOST
|
||||||
bool
|
bool
|
||||||
Polygon::encloses_point(Point* point) const
|
Polygon::encloses_point(Point* point) const
|
||||||
{
|
{
|
||||||
return boost::geometry::covered_by(*point, *this);
|
return boost::geometry::covered_by(*point, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Polygon::push_back(const Point& point)
|
||||||
|
{
|
||||||
|
this->points.push_back(point);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,19 @@ class Polygon : public MultiPoint {
|
||||||
bool make_counter_clockwise();
|
bool make_counter_clockwise();
|
||||||
bool make_clockwise();
|
bool make_clockwise();
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
|
|
||||||
|
#ifndef NOBOOST
|
||||||
bool encloses_point(Point* point) const;
|
bool encloses_point(Point* point) const;
|
||||||
|
void push_back(const Point& point);
|
||||||
|
typedef const Point& const_reference;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Polygon> Polygons;
|
typedef std::vector<Polygon> Polygons;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boost.Geometry
|
#ifndef NOBOOST
|
||||||
#include <boost/geometry/geometries/register/ring.hpp>
|
#include <boost/geometry/geometries/register/ring.hpp>
|
||||||
BOOST_GEOMETRY_REGISTER_RING(Polygon);
|
BOOST_GEOMETRY_REGISTER_RING(Polygon);
|
||||||
|
|
||||||
|
@ -76,6 +81,6 @@ namespace Slic3r {
|
||||||
inline Points::const_iterator
|
inline Points::const_iterator
|
||||||
range_end(const Polygon& poly) {return poly.points.end();}
|
range_end(const Polygon& poly) {return poly.points.end();}
|
||||||
}
|
}
|
||||||
// end Boost.Geometry
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,17 +15,18 @@ class Polyline : public MultiPoint {
|
||||||
double length() const;
|
double length() const;
|
||||||
void clip_end(double d);
|
void clip_end(double d);
|
||||||
|
|
||||||
// for Boost.Geometry:
|
#ifndef NOBOOST
|
||||||
std::size_t size() const;
|
std::size_t size() const;
|
||||||
void clear();
|
void clear();
|
||||||
const Point& operator[] (const int nIndex) const;
|
const Point& operator[] (const int nIndex) const;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Polyline> Polylines;
|
typedef std::vector<Polyline> Polylines;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boost.Geometry
|
#ifndef NOBOOST
|
||||||
#include <boost/geometry/geometries/register/linestring.hpp>
|
#include <boost/geometry/geometries/register/linestring.hpp>
|
||||||
#include <boost/geometry/multi/geometries/register/multi_linestring.hpp>
|
#include <boost/geometry/multi/geometries/register/multi_linestring.hpp>
|
||||||
BOOST_GEOMETRY_REGISTER_LINESTRING(Polyline)
|
BOOST_GEOMETRY_REGISTER_LINESTRING(Polyline)
|
||||||
|
@ -85,7 +86,6 @@ namespace Slic3r {
|
||||||
inline Points::const_iterator
|
inline Points::const_iterator
|
||||||
range_end(const Polyline& poly) {return poly.points.end();}
|
range_end(const Polyline& poly) {return poly.points.end();}
|
||||||
}
|
}
|
||||||
// end B
|
#endif
|
||||||
// end Boost.Geometry
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,14 +8,6 @@ use Test::More tests => 1;
|
||||||
|
|
||||||
ok 'okay';
|
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
|
my $square = [ # ccw
|
||||||
[100, 100],
|
[100, 100],
|
||||||
[200, 100],
|
[200, 100],
|
||||||
|
@ -28,12 +20,21 @@ my $hole_in_square = [ # cw
|
||||||
[160, 160],
|
[160, 160],
|
||||||
[160, 140],
|
[160, 140],
|
||||||
];
|
];
|
||||||
my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
|
|
||||||
my $polyline = Slic3r::Polyline->new([0,150], [300,150]);
|
|
||||||
|
|
||||||
if (0) {
|
if (0) {
|
||||||
my $polylines = Slic3r::Geometry::expolygons_polylines_intersection([$expolygon], [$polyline]);
|
my $points = [ map Slic3r::Point->new(@$_), @$square ];
|
||||||
use XXX; XXX map $_->pp, @$polylines;
|
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
|
# fails because Boost isn't honoring winding order and closure yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ convex_hull(points)
|
||||||
const char* CLASS = "Slic3r::Polygon";
|
const char* CLASS = "Slic3r::Polygon";
|
||||||
CODE:
|
CODE:
|
||||||
RETVAL = new Polygon;
|
RETVAL = new Polygon;
|
||||||
boost::geometry::convex_hull(points, RETVAL->points);
|
boost::geometry::convex_hull(points, *RETVAL);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue