mirror of https://github.com/vitalif/Slic3r
Make boost::geometry::intersection() compile
parent
39c88a79e8
commit
c0afa13051
|
@ -35,6 +35,22 @@ typedef std::vector<Polygon> Polygons;
|
|||
#include <boost/geometry/geometries/register/ring.hpp>
|
||||
BOOST_GEOMETRY_REGISTER_RING(Polygon);
|
||||
|
||||
#include <boost/geometry/core/point_order.hpp>
|
||||
#include <boost/geometry/core/closure.hpp>
|
||||
namespace boost { namespace geometry { namespace traits {
|
||||
template<>
|
||||
struct point_order<Polygon>
|
||||
{
|
||||
static const order_selector value = counterclockwise;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct closure<Polygon>
|
||||
{
|
||||
static const closure_selector value = open;
|
||||
};
|
||||
}}}
|
||||
|
||||
#include <boost/range.hpp>
|
||||
namespace boost
|
||||
{
|
||||
|
|
|
@ -61,5 +61,23 @@ Polyline::clip_end(double d)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t
|
||||
Polyline::size() const
|
||||
{
|
||||
return this->points.size();
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::clear()
|
||||
{
|
||||
this->points.clear();
|
||||
}
|
||||
|
||||
const Point&
|
||||
Polyline::operator[] (const int nIndex) const
|
||||
{
|
||||
return this->points[nIndex];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,11 @@ class Polyline : public MultiPoint {
|
|||
SV* to_SV_clone_ref() const;
|
||||
double length() const;
|
||||
void clip_end(double d);
|
||||
|
||||
// for Boost.Geometry:
|
||||
std::size_t size() const;
|
||||
void clear();
|
||||
const Point& operator[] (const int nIndex) const;
|
||||
};
|
||||
|
||||
typedef std::vector<Polyline> Polylines;
|
||||
|
@ -26,6 +31,35 @@ typedef std::vector<Polyline> Polylines;
|
|||
BOOST_GEOMETRY_REGISTER_LINESTRING(Polyline)
|
||||
BOOST_GEOMETRY_REGISTER_MULTI_LINESTRING(Polylines);
|
||||
|
||||
namespace boost { namespace geometry { namespace traits {
|
||||
template<>
|
||||
struct clear<Polyline>
|
||||
{
|
||||
static inline void apply(Polyline& polyline)
|
||||
{
|
||||
polyline.points.clear();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct resize<Polyline>
|
||||
{
|
||||
static inline void apply(Polyline& polyline, std::size_t new_size)
|
||||
{
|
||||
polyline.points.resize(new_size);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct push_back<Polyline>
|
||||
{
|
||||
static inline void apply(Polyline& polyline, Point const& point)
|
||||
{
|
||||
polyline.points.push_back(point);
|
||||
}
|
||||
};
|
||||
}}}
|
||||
|
||||
#include <boost/range.hpp>
|
||||
namespace boost
|
||||
{
|
||||
|
|
|
@ -6,10 +6,35 @@ use warnings;
|
|||
use Slic3r::XS;
|
||||
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],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
];
|
||||
my $hole_in_square = [ # cw
|
||||
[140, 140],
|
||||
[140, 160],
|
||||
[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;
|
||||
# fails because Boost isn't honoring winding order and closure yet
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
@ -21,7 +21,6 @@ convex_hull(points)
|
|||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
/*
|
||||
Polylines
|
||||
expolygons_polylines_intersection(expolygons, polylines)
|
||||
ExPolygons expolygons
|
||||
|
@ -30,6 +29,5 @@ expolygons_polylines_intersection(expolygons, polylines)
|
|||
boost::geometry::intersection(expolygons, polylines, RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
*/
|
||||
|
||||
%}
|
||||
|
|
Loading…
Reference in New Issue