diff options
Diffstat (limited to 'xs/src/libslic3r/MultiPoint.hpp')
-rw-r--r-- | xs/src/libslic3r/MultiPoint.hpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/xs/src/libslic3r/MultiPoint.hpp b/xs/src/libslic3r/MultiPoint.hpp index 0970e9a67..02086ded8 100644 --- a/xs/src/libslic3r/MultiPoint.hpp +++ b/xs/src/libslic3r/MultiPoint.hpp @@ -34,8 +34,10 @@ public: Point first_point() const; virtual Point last_point() const = 0; virtual Lines lines() const = 0; + size_t size() const { return points.size(); } + bool empty() const { return points.empty(); } double length() const; - bool is_valid() const { return this->points.size() >= 2; } + bool is_valid() const { return this->points.size() >= 2; } int find_point(const Point &point) const; bool has_boundary_point(const Point &point) const; @@ -103,6 +105,23 @@ extern BoundingBox get_extents(const MultiPoint &mp); extern BoundingBox get_extents_rotated(const std::vector<Point> &points, double angle); extern BoundingBox get_extents_rotated(const MultiPoint &mp, double angle); +inline double length(const Points &pts) { + double total = 0; + if (! pts.empty()) { + auto it = pts.begin(); + for (auto it_prev = it ++; it != pts.end(); ++ it, ++ it_prev) + total += it->distance_to(*it_prev); + } + return total; +} + +inline double area(const Points &polygon) { + double area = 0.; + for (size_t i = 0, j = polygon.size() - 1; i < polygon.size(); j = i ++) + area += double(polygon[j].x + polygon[i].x) * double(polygon[i].y - polygon[j].y); + return area; +} + } // namespace Slic3r #endif |