2013-07-14 15:53:53 +02:00
|
|
|
#ifndef slic3r_Polygon_hpp_
|
|
|
|
#define slic3r_Polygon_hpp_
|
|
|
|
|
2015-12-08 00:39:54 +01:00
|
|
|
#include "libslic3r.h"
|
2013-07-15 20:31:43 +02:00
|
|
|
#include <vector>
|
2014-11-15 23:06:15 +01:00
|
|
|
#include <string>
|
2013-07-16 21:04:14 +02:00
|
|
|
#include "Line.hpp"
|
|
|
|
#include "MultiPoint.hpp"
|
2013-07-14 16:09:54 +02:00
|
|
|
#include "Polyline.hpp"
|
2013-07-14 15:53:53 +02:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-11-22 02:16:10 +01:00
|
|
|
class Polygon;
|
|
|
|
typedef std::vector<Polygon> Polygons;
|
|
|
|
|
2013-07-15 23:28:23 +02:00
|
|
|
class Polygon : public MultiPoint {
|
|
|
|
public:
|
2014-01-07 15:40:38 +01:00
|
|
|
operator Polygons() const;
|
2014-05-08 11:07:37 +02:00
|
|
|
operator Polyline() const;
|
2014-04-28 20:14:20 +02:00
|
|
|
Point& operator[](Points::size_type idx);
|
|
|
|
const Point& operator[](Points::size_type idx) const;
|
2014-12-07 19:53:22 +01:00
|
|
|
|
|
|
|
Polygon() {};
|
|
|
|
explicit Polygon(const Points &points): MultiPoint(points) {};
|
2014-04-24 16:40:10 +02:00
|
|
|
Point last_point() const;
|
2016-03-19 15:33:58 +01:00
|
|
|
virtual Lines lines() const;
|
2015-01-19 18:53:04 +01:00
|
|
|
Polyline split_at_vertex(const Point &point) const;
|
2016-09-13 13:30:00 +02:00
|
|
|
// Split a closed polygon into an open polyline, with the split point duplicated at both ends.
|
2015-01-19 18:53:04 +01:00
|
|
|
Polyline split_at_index(int index) const;
|
2016-09-13 13:30:00 +02:00
|
|
|
// Split a closed polygon into an open polyline, with the split point duplicated at both ends.
|
2015-01-19 18:53:04 +01:00
|
|
|
Polyline split_at_first_point() const;
|
|
|
|
Points equally_spaced_points(double distance) const;
|
2013-08-26 22:50:26 +02:00
|
|
|
double area() const;
|
|
|
|
bool is_counter_clockwise() const;
|
2013-08-27 01:26:44 +02:00
|
|
|
bool is_clockwise() const;
|
2013-07-16 21:09:29 +02:00
|
|
|
bool make_counter_clockwise();
|
|
|
|
bool make_clockwise();
|
2013-08-26 23:27:51 +02:00
|
|
|
bool is_valid() const;
|
2016-09-13 13:30:00 +02:00
|
|
|
// Does an unoriented polygon contain a point?
|
|
|
|
// Tested by counting intersections along a horizontal line.
|
2014-11-23 20:14:13 +01:00
|
|
|
bool contains(const Point &point) const;
|
2013-11-21 20:25:24 +01:00
|
|
|
Polygons simplify(double tolerance) const;
|
|
|
|
void simplify(double tolerance, Polygons &polygons) const;
|
2014-04-24 16:59:36 +02:00
|
|
|
void triangulate_convex(Polygons* polygons) const;
|
2014-05-22 19:34:49 +02:00
|
|
|
Point centroid() const;
|
2014-11-15 23:06:15 +01:00
|
|
|
std::string wkt() const;
|
2015-01-19 18:53:04 +01:00
|
|
|
Points concave_points(double angle = PI) const;
|
|
|
|
Points convex_points(double angle = PI) const;
|
2013-07-15 23:28:23 +02:00
|
|
|
};
|
2013-07-15 16:21:09 +02:00
|
|
|
|
2016-09-13 13:30:00 +02:00
|
|
|
extern BoundingBox get_extents(const Polygon &poly);
|
|
|
|
extern BoundingBox get_extents(const Polygons &polygons);
|
|
|
|
|
2013-07-14 15:53:53 +02:00
|
|
|
}
|
|
|
|
|
2014-04-24 13:43:24 +02:00
|
|
|
// start Boost
|
|
|
|
#include <boost/polygon/polygon.hpp>
|
|
|
|
namespace boost { namespace polygon {
|
|
|
|
template <>
|
|
|
|
struct geometry_concept<Polygon>{ typedef polygon_concept type; };
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct polygon_traits<Polygon> {
|
|
|
|
typedef coord_t coordinate_type;
|
|
|
|
typedef Points::const_iterator iterator_type;
|
|
|
|
typedef Point point_type;
|
|
|
|
|
|
|
|
// Get the begin iterator
|
|
|
|
static inline iterator_type begin_points(const Polygon& t) {
|
|
|
|
return t.points.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the end iterator
|
|
|
|
static inline iterator_type end_points(const Polygon& t) {
|
|
|
|
return t.points.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the number of sides of the polygon
|
|
|
|
static inline std::size_t size(const Polygon& t) {
|
|
|
|
return t.points.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the winding direction of the polygon
|
|
|
|
static inline winding_direction winding(const Polygon& t) {
|
|
|
|
return unknown_winding;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct polygon_mutable_traits<Polygon> {
|
|
|
|
// expects stl style iterators
|
|
|
|
template <typename iT>
|
|
|
|
static inline Polygon& set_points(Polygon& polygon, iT input_begin, iT input_end) {
|
|
|
|
polygon.points.clear();
|
|
|
|
while (input_begin != input_end) {
|
|
|
|
polygon.points.push_back(Point());
|
|
|
|
boost::polygon::assign(polygon.points.back(), *input_begin);
|
|
|
|
++input_begin;
|
|
|
|
}
|
|
|
|
// skip last point since Boost will set last point = first point
|
|
|
|
polygon.points.pop_back();
|
|
|
|
return polygon;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct geometry_concept<Polygons> { typedef polygon_set_concept type; };
|
|
|
|
|
|
|
|
//next we map to the concept through traits
|
|
|
|
template <>
|
|
|
|
struct polygon_set_traits<Polygons> {
|
|
|
|
typedef coord_t coordinate_type;
|
|
|
|
typedef Polygons::const_iterator iterator_type;
|
|
|
|
typedef Polygons operator_arg_type;
|
|
|
|
|
|
|
|
static inline iterator_type begin(const Polygons& polygon_set) {
|
|
|
|
return polygon_set.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline iterator_type end(const Polygons& polygon_set) {
|
|
|
|
return polygon_set.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
//don't worry about these, just return false from them
|
|
|
|
static inline bool clean(const Polygons& polygon_set) { return false; }
|
|
|
|
static inline bool sorted(const Polygons& polygon_set) { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct polygon_set_mutable_traits<Polygons> {
|
|
|
|
template <typename input_iterator_type>
|
|
|
|
static inline void set(Polygons& polygons, input_iterator_type input_begin, input_iterator_type input_end) {
|
|
|
|
polygons.assign(input_begin, input_end);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} }
|
|
|
|
// end Boost
|
|
|
|
|
2013-07-14 15:53:53 +02:00
|
|
|
#endif
|