2013-07-15 22:57:22 +02:00
|
|
|
#ifndef slic3r_MultiPoint_hpp_
|
|
|
|
#define slic3r_MultiPoint_hpp_
|
|
|
|
|
2015-12-08 00:39:54 +01:00
|
|
|
#include "libslic3r.h"
|
2013-07-15 22:57:22 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2014-05-22 19:34:49 +02:00
|
|
|
#include "Line.hpp"
|
|
|
|
#include "Point.hpp"
|
2013-07-15 22:57:22 +02:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2014-05-22 19:34:49 +02:00
|
|
|
class BoundingBox;
|
2018-01-08 13:44:10 +01:00
|
|
|
class BoundingBox3;
|
2014-05-22 19:34:49 +02:00
|
|
|
|
2013-07-15 22:57:22 +02:00
|
|
|
class MultiPoint
|
|
|
|
{
|
2017-06-08 11:02:29 +02:00
|
|
|
public:
|
2013-07-15 22:57:22 +02:00
|
|
|
Points points;
|
2014-05-22 19:34:49 +02:00
|
|
|
|
|
|
|
operator Points() const;
|
2014-12-07 19:53:22 +01:00
|
|
|
MultiPoint() {};
|
2017-01-19 13:43:29 +01:00
|
|
|
MultiPoint(const MultiPoint &other) : points(other.points) {}
|
|
|
|
MultiPoint(MultiPoint &&other) : points(std::move(other.points)) {}
|
|
|
|
explicit MultiPoint(const Points &_points): points(_points) {}
|
|
|
|
MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; }
|
|
|
|
MultiPoint& operator=(MultiPoint &&other) { points = std::move(other.points); return *this; }
|
2013-07-15 22:57:22 +02:00
|
|
|
void scale(double factor);
|
|
|
|
void translate(double x, double y);
|
2014-11-09 15:27:34 +01:00
|
|
|
void translate(const Point &vector);
|
2017-06-08 14:02:37 +02:00
|
|
|
void rotate(double angle) { this->rotate(cos(angle), sin(angle)); }
|
|
|
|
void rotate(double cos_angle, double sin_angle);
|
2014-04-24 13:43:24 +02:00
|
|
|
void rotate(double angle, const Point ¢er);
|
2013-07-15 22:57:22 +02:00
|
|
|
void reverse();
|
2014-04-24 16:40:10 +02:00
|
|
|
Point first_point() const;
|
|
|
|
virtual Point last_point() const = 0;
|
2013-10-27 22:57:25 +01:00
|
|
|
virtual Lines lines() const = 0;
|
|
|
|
double length() const;
|
2016-09-13 09:46:41 +02:00
|
|
|
bool is_valid() const { return this->points.size() >= 2; }
|
|
|
|
|
2017-06-08 11:02:29 +02:00
|
|
|
int find_point(const Point &point) const;
|
2015-01-06 20:52:36 +01:00
|
|
|
bool has_boundary_point(const Point &point) const;
|
2017-06-08 11:02:29 +02:00
|
|
|
int closest_point_index(const Point &point) const {
|
|
|
|
int idx = -1;
|
|
|
|
if (! this->points.empty()) {
|
|
|
|
idx = 0;
|
|
|
|
double dist_min = this->points.front().distance_to(point);
|
|
|
|
for (int i = 1; i < int(this->points.size()); ++ i) {
|
|
|
|
double d = this->points[i].distance_to(point);
|
|
|
|
if (d < dist_min) {
|
|
|
|
dist_min = d;
|
|
|
|
idx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
const Point* closest_point(const Point &point) const { return this->points.empty() ? nullptr : &this->points[this->closest_point_index(point)]; }
|
2015-01-19 18:53:04 +01:00
|
|
|
BoundingBox bounding_box() const;
|
2016-04-15 18:01:08 +02:00
|
|
|
// Return true if there are exact duplicates.
|
|
|
|
bool has_duplicate_points() const;
|
|
|
|
// Remove exact duplicates, return true if any duplicate has been removed.
|
|
|
|
bool remove_duplicate_points();
|
2017-01-19 13:43:29 +01:00
|
|
|
void append(const Point &point) { this->points.push_back(point); }
|
|
|
|
void append(const Points &src) { this->append(src.begin(), src.end()); }
|
|
|
|
void append(const Points::const_iterator &begin, const Points::const_iterator &end) { this->points.insert(this->points.end(), begin, end); }
|
|
|
|
void append(Points &&src)
|
|
|
|
{
|
2017-01-20 14:39:44 +01:00
|
|
|
if (this->points.empty()) {
|
2017-01-19 13:43:29 +01:00
|
|
|
this->points = std::move(src);
|
2017-01-20 14:39:44 +01:00
|
|
|
} else {
|
|
|
|
this->points.insert(this->points.end(), src.begin(), src.end());
|
|
|
|
src.clear();
|
|
|
|
}
|
2017-01-19 13:43:29 +01:00
|
|
|
}
|
|
|
|
|
2016-03-19 15:33:58 +01:00
|
|
|
bool intersection(const Line& line, Point* intersection) const;
|
2017-06-08 11:02:29 +02:00
|
|
|
bool first_intersection(const Line& line, Point* intersection) const;
|
2016-05-20 06:24:05 +02:00
|
|
|
std::string dump_perl() const;
|
2014-05-22 19:34:49 +02:00
|
|
|
|
2013-11-22 16:01:50 +01:00
|
|
|
static Points _douglas_peucker(const Points &points, const double tolerance);
|
2013-07-15 22:57:22 +02:00
|
|
|
};
|
|
|
|
|
2018-01-08 13:44:10 +01:00
|
|
|
class MultiPoint3
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Points3 points;
|
|
|
|
|
|
|
|
void append(const Point3& point) { this->points.push_back(point); }
|
|
|
|
|
|
|
|
void translate(double x, double y);
|
|
|
|
void translate(const Point& vector);
|
|
|
|
virtual Lines3 lines() const = 0;
|
|
|
|
double length() const;
|
|
|
|
bool is_valid() const { return this->points.size() >= 2; }
|
|
|
|
|
|
|
|
BoundingBox3 bounding_box() const;
|
|
|
|
|
|
|
|
// Remove exact duplicates, return true if any duplicate has been removed.
|
|
|
|
bool remove_duplicate_points();
|
|
|
|
};
|
|
|
|
|
2016-09-13 13:30:00 +02:00
|
|
|
extern BoundingBox get_extents(const MultiPoint &mp);
|
2016-11-07 22:49:11 +01:00
|
|
|
extern BoundingBox get_extents_rotated(const std::vector<Point> &points, double angle);
|
|
|
|
extern BoundingBox get_extents_rotated(const MultiPoint &mp, double angle);
|
2016-09-13 13:30:00 +02:00
|
|
|
|
|
|
|
} // namespace Slic3r
|
2013-07-15 22:57:22 +02:00
|
|
|
|
|
|
|
#endif
|