Ported some minor methods to XS

This commit is contained in:
Alessandro Ranellucci 2014-11-15 23:06:15 +01:00
parent 379cde30e2
commit 28466750e6
9 changed files with 58 additions and 42 deletions

View file

@ -209,6 +209,19 @@ Polygon::centroid() const
return Point(x_temp/(6*area_temp), y_temp/(6*area_temp));
}
std::string
Polygon::wkt() const
{
std::ostringstream wkt;
wkt << "POLYGON((";
for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) {
wkt << p->x << " " << p->y;
if (p != this->points.end()-1) wkt << ",";
}
wkt << "))";
return wkt.str();
}
#ifdef SLIC3RXS
REGISTER_CLASS(Polygon, "Polygon");

View file

@ -3,6 +3,7 @@
#include <myinit.h>
#include <vector>
#include <string>
#include "Line.hpp"
#include "MultiPoint.hpp"
#include "Polyline.hpp"
@ -36,6 +37,7 @@ class Polygon : public MultiPoint {
void simplify(double tolerance, Polygons &polygons) const;
void triangulate_convex(Polygons* polygons) const;
Point centroid() const;
std::string wkt() const;
#ifdef SLIC3RXS
void from_SV_check(SV* poly_sv);

View file

@ -1,6 +1,7 @@
#include "Polyline.hpp"
#include "Line.hpp"
#include "Polygon.hpp"
#include <iostream>
namespace Slic3r {
@ -162,6 +163,34 @@ Polyline::split_at(const Point &point, Polyline* p1, Polyline* p2) const
}
}
bool
Polyline::is_straight() const
{
/* Check that each segment's direction is equal to the line connecting
first point and last point. (Checking each line against the previous
one would cause the error to accumulate.) */
double dir = Line(this->first_point(), this->last_point()).direction();
Lines lines = this->lines();
for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
if (!line->parallel_to(dir)) return false;
}
return true;
}
std::string
Polyline::wkt() const
{
std::ostringstream wkt;
wkt << "LINESTRING((";
for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) {
wkt << p->x << " " << p->y;
if (p != this->points.end()-1) wkt << ",";
}
wkt << "))";
return wkt.str();
}
#ifdef SLIC3RXS
REGISTER_CLASS(Polyline, "Polyline");

View file

@ -3,6 +3,7 @@
#include "Line.hpp"
#include "MultiPoint.hpp"
#include <string>
namespace Slic3r {
@ -23,6 +24,8 @@ class Polyline : public MultiPoint {
void equally_spaced_points(double distance, Points* points) const;
void simplify(double tolerance);
void split_at(const Point &point, Polyline* p1, Polyline* p2) const;
bool is_straight() const;
std::string wkt() const;
#ifdef SLIC3RXS
void from_SV_check(SV* poly_sv);