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

This commit is contained in:
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

@ -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;
}
}