Ported simplify() to XS and removed dependency on Boost::Geometry::Utils

svg-paths
Alessandro Ranellucci 2013-11-22 16:01:50 +01:00
parent df8d889481
commit 132d170f73
8 changed files with 25 additions and 12 deletions

View File

@ -7,7 +7,6 @@ use Config;
use File::Spec;
my %prereqs = qw(
Boost::Geometry::Utils 0.15
Encode::Locale 0
ExtUtils::MakeMaker 6.80
ExtUtils::ParseXS 3.22

View File

@ -33,7 +33,6 @@ our $var = "$FindBin::Bin/var";
use Encode;
use Encode::Locale;
use Boost::Geometry::Utils 0.15;
use Moo 1.003001;
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed

View File

@ -4,7 +4,6 @@ use warnings;
# an ExPolygon is a polygon with holes
use Boost::Geometry::Utils;
use List::Util qw(first);
use Math::Geometry::Voronoi;
use Slic3r::Geometry qw(X Y A B point_in_polygon epsilon scaled_epsilon);

View File

@ -56,11 +56,11 @@ MultiPoint::is_valid() const
}
Points
MultiPoint::_douglas_peucker(Points &points, double tolerance)
MultiPoint::_douglas_peucker(const Points &points, const double tolerance)
{
Points results;
double dmax = 0;
int index = 0;
size_t index = 0;
Line full(points.front(), points.back());
for (Points::const_iterator it = points.begin() + 1; it != points.end(); ++it) {
double d = it->distance_to(full);

View File

@ -21,7 +21,7 @@ class MultiPoint
virtual Lines lines() const = 0;
double length() 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
void from_SV(SV* poly_sv);

View File

@ -1,6 +1,6 @@
#include "Point.hpp"
#include "Line.hpp"
#include <math.h>
#include <cmath>
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)
- (line.a.x - this->x) * (line.b.y - line.a.y);
return abs(n) / line.length();
return std::abs(n) / line.length();
}
#ifdef SLIC3RXS

View File

@ -3,11 +3,19 @@
namespace Slic3r {
void
simplify(double tolerance)
SurfaceCollection::simplify(double tolerance)
{
for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
throw "Unimplemented";
Surfaces ss;
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;
}
}

View File

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 6;
use Test::More tests => 7;
my $points = [
[100, 100],
@ -34,4 +34,12 @@ is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
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__