Ported simplify() to XS and removed dependency on Boost::Geometry::Utils
This commit is contained in:
parent
df8d889481
commit
132d170f73
1
Build.PL
1
Build.PL
@ -7,7 +7,6 @@ use Config;
|
|||||||
use File::Spec;
|
use File::Spec;
|
||||||
|
|
||||||
my %prereqs = qw(
|
my %prereqs = qw(
|
||||||
Boost::Geometry::Utils 0.15
|
|
||||||
Encode::Locale 0
|
Encode::Locale 0
|
||||||
ExtUtils::MakeMaker 6.80
|
ExtUtils::MakeMaker 6.80
|
||||||
ExtUtils::ParseXS 3.22
|
ExtUtils::ParseXS 3.22
|
||||||
|
@ -33,7 +33,6 @@ our $var = "$FindBin::Bin/var";
|
|||||||
|
|
||||||
use Encode;
|
use Encode;
|
||||||
use Encode::Locale;
|
use Encode::Locale;
|
||||||
use Boost::Geometry::Utils 0.15;
|
|
||||||
use Moo 1.003001;
|
use Moo 1.003001;
|
||||||
|
|
||||||
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
|
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
|
||||||
|
@ -4,7 +4,6 @@ use warnings;
|
|||||||
|
|
||||||
# an ExPolygon is a polygon with holes
|
# an ExPolygon is a polygon with holes
|
||||||
|
|
||||||
use Boost::Geometry::Utils;
|
|
||||||
use List::Util qw(first);
|
use List::Util qw(first);
|
||||||
use Math::Geometry::Voronoi;
|
use Math::Geometry::Voronoi;
|
||||||
use Slic3r::Geometry qw(X Y A B point_in_polygon epsilon scaled_epsilon);
|
use Slic3r::Geometry qw(X Y A B point_in_polygon epsilon scaled_epsilon);
|
||||||
|
@ -56,11 +56,11 @@ MultiPoint::is_valid() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
Points
|
Points
|
||||||
MultiPoint::_douglas_peucker(Points &points, double tolerance)
|
MultiPoint::_douglas_peucker(const Points &points, const double tolerance)
|
||||||
{
|
{
|
||||||
Points results;
|
Points results;
|
||||||
double dmax = 0;
|
double dmax = 0;
|
||||||
int index = 0;
|
size_t index = 0;
|
||||||
Line full(points.front(), points.back());
|
Line full(points.front(), points.back());
|
||||||
for (Points::const_iterator it = points.begin() + 1; it != points.end(); ++it) {
|
for (Points::const_iterator it = points.begin() + 1; it != points.end(); ++it) {
|
||||||
double d = it->distance_to(full);
|
double d = it->distance_to(full);
|
||||||
|
@ -21,7 +21,7 @@ class MultiPoint
|
|||||||
virtual Lines lines() const = 0;
|
virtual Lines lines() const = 0;
|
||||||
double length() const;
|
double length() const;
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
static Points _douglas_peucker(Points &points, double tolerance);
|
static Points _douglas_peucker(const Points &points, const double tolerance);
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
void from_SV(SV* poly_sv);
|
void from_SV(SV* poly_sv);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "Point.hpp"
|
#include "Point.hpp"
|
||||||
#include "Line.hpp"
|
#include "Line.hpp"
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ Point::distance_to(const Line &line) const
|
|||||||
double n = (line.b.x - line.a.x) * (line.a.y - this->y)
|
double n = (line.b.x - line.a.x) * (line.a.y - this->y)
|
||||||
- (line.a.x - this->x) * (line.b.y - line.a.y);
|
- (line.a.x - this->x) * (line.b.y - line.a.y);
|
||||||
|
|
||||||
return abs(n) / line.length();
|
return std::abs(n) / line.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
|
@ -3,11 +3,19 @@
|
|||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
void
|
void
|
||||||
simplify(double tolerance)
|
SurfaceCollection::simplify(double tolerance)
|
||||||
{
|
{
|
||||||
for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
|
Surfaces ss;
|
||||||
throw "Unimplemented";
|
for (Surfaces::const_iterator it_s = this->surfaces.begin(); it_s != this->surfaces.end(); ++it_s) {
|
||||||
|
ExPolygons expp;
|
||||||
|
it_s->expolygon.simplify(tolerance, expp);
|
||||||
|
for (ExPolygons::const_iterator it_e = expp.begin(); it_e != expp.end(); ++it_e) {
|
||||||
|
Surface s = *it_s;
|
||||||
|
s.expolygon = *it_e;
|
||||||
|
ss.push_back(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this->surfaces = ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Slic3r::XS;
|
use Slic3r::XS;
|
||||||
use Test::More tests => 6;
|
use Test::More tests => 7;
|
||||||
|
|
||||||
my $points = [
|
my $points = [
|
||||||
[100, 100],
|
[100, 100],
|
||||||
@ -34,4 +34,12 @@ is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
|
|||||||
ok abs($polyline->length - ($len-($len/3))) < 1, 'clip_end';
|
ok abs($polyline->length - ($len-($len/3))) < 1, 'clip_end';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $polyline = Slic3r::Polyline->new(
|
||||||
|
[0,0], [50,50], [100,0], [125,-25], [150,50],
|
||||||
|
);
|
||||||
|
$polyline->simplify(25);
|
||||||
|
is_deeply $polyline->pp, [ [0, 0], [50, 50], [125, -25], [150, 50] ], 'Douglas-Peucker';
|
||||||
|
}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
Loading…
Reference in New Issue
Block a user