mirror of https://github.com/vitalif/Slic3r
Ported Polygon->encloses_point()
parent
7c2510853b
commit
1e2babde34
|
@ -27,12 +27,6 @@ sub remove_acute_vertices {
|
||||||
polygon_remove_acute_vertices($self);
|
polygon_remove_acute_vertices($self);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub encloses_point {
|
|
||||||
my $self = shift;
|
|
||||||
my ($point) = @_;
|
|
||||||
return Boost::Geometry::Utils::point_covered_by_polygon($point->pp, [$self->pp]);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub grow {
|
sub grow {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->split_at_first_point->grow(@_);
|
return $self->split_at_first_point->grow(@_);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ClipperUtils.hpp"
|
#include "ClipperUtils.hpp"
|
||||||
#include "Polygon.hpp"
|
#include "Polygon.hpp"
|
||||||
#include "Polyline.hpp"
|
#include "Polyline.hpp"
|
||||||
|
#include <boost/geometry/algorithms/covered_by.hpp>
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
@ -117,4 +118,10 @@ Polygon::is_valid() const
|
||||||
return this->points.size() >= 3;
|
return this->points.size() >= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Polygon::encloses_point(Point* point) const
|
||||||
|
{
|
||||||
|
return boost::geometry::covered_by(*point, *this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,42 @@ 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;
|
||||||
|
bool encloses_point(Point* point) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Polygon> Polygons;
|
typedef std::vector<Polygon> Polygons;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Boost.Geometry
|
||||||
|
#include <boost/geometry/geometries/register/ring.hpp>
|
||||||
|
BOOST_GEOMETRY_REGISTER_RING(Polygon);
|
||||||
|
|
||||||
|
#include <boost/range.hpp>
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template<>
|
||||||
|
struct range_iterator<Polygon>
|
||||||
|
{ typedef Points::iterator type; };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct range_const_iterator<Polygon>
|
||||||
|
{ typedef Points::const_iterator type; };
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
inline Points::iterator
|
||||||
|
range_begin(Polygon& poly) {return poly.points.begin();}
|
||||||
|
|
||||||
|
inline Points::iterator
|
||||||
|
range_end(Polygon& poly) {return poly.points.end();}
|
||||||
|
|
||||||
|
inline Points::const_iterator
|
||||||
|
range_begin(const Polygon& poly) {return poly.points.begin();}
|
||||||
|
|
||||||
|
inline Points::const_iterator
|
||||||
|
range_end(const Polygon& poly) {return poly.points.end();}
|
||||||
|
}
|
||||||
|
// end Boost.Geometry
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,7 +36,7 @@ Polyline::to_SV_clone_ref() const
|
||||||
double
|
double
|
||||||
Polyline::length() const
|
Polyline::length() const
|
||||||
{
|
{
|
||||||
return boost::geometry::length(this->points);
|
return boost::geometry::length(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,36 @@ typedef std::vector<Polyline> Polylines;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Boost.Geometry
|
||||||
#include <boost/geometry/geometries/register/linestring.hpp>
|
#include <boost/geometry/geometries/register/linestring.hpp>
|
||||||
BOOST_GEOMETRY_REGISTER_LINESTRING(Points)
|
BOOST_GEOMETRY_REGISTER_LINESTRING(Polyline)
|
||||||
|
|
||||||
|
#include <boost/range.hpp>
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template<>
|
||||||
|
struct range_iterator<Polyline>
|
||||||
|
{ typedef Points::iterator type; };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct range_const_iterator<Polyline>
|
||||||
|
{ typedef Points::const_iterator type; };
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
inline Points::iterator
|
||||||
|
range_begin(Polyline& poly) {return poly.points.begin();}
|
||||||
|
|
||||||
|
inline Points::iterator
|
||||||
|
range_end(Polyline& poly) {return poly.points.end();}
|
||||||
|
|
||||||
|
inline Points::const_iterator
|
||||||
|
range_begin(const Polyline& poly) {return poly.points.begin();}
|
||||||
|
|
||||||
|
inline Points::const_iterator
|
||||||
|
range_end(const Polyline& poly) {return poly.points.end();}
|
||||||
|
}
|
||||||
|
// end B
|
||||||
|
// end Boost.Geometry
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 14;
|
use Test::More tests => 17;
|
||||||
|
|
||||||
my $square = [ # ccw
|
my $square = [ # ccw
|
||||||
[100, 100],
|
[100, 100],
|
||||||
|
@ -46,6 +46,10 @@ ok $polygon->is_counter_clockwise, 'is_counter_clockwise';
|
||||||
|
|
||||||
ok ref($polygon->first_point) eq 'Slic3r::Point', 'first_point';
|
ok ref($polygon->first_point) eq 'Slic3r::Point', 'first_point';
|
||||||
|
|
||||||
|
ok $polygon->encloses_point(Slic3r::Point->new(150, 150)), 'encloses_point';
|
||||||
|
ok $polygon->encloses_point(Slic3r::Point->new(100, 150)), 'encloses_point';
|
||||||
|
ok !$polygon->encloses_point(Slic3r::Point->new(0, 50)), 'encloses_point';
|
||||||
|
|
||||||
# this is not a test: this just demonstrates bad usage, where $polygon->clone gets
|
# this is not a test: this just demonstrates bad usage, where $polygon->clone gets
|
||||||
# DESTROY'ed before the derived object ($point), causing bad memory access
|
# DESTROY'ed before the derived object ($point), causing bad memory access
|
||||||
if (0) {
|
if (0) {
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
bool is_valid();
|
bool is_valid();
|
||||||
Point* first_point()
|
Point* first_point()
|
||||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
|
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %};
|
||||||
|
bool encloses_point(Point* point);
|
||||||
%{
|
%{
|
||||||
|
|
||||||
Polygon*
|
Polygon*
|
||||||
|
|
Loading…
Reference in New Issue