Return MultiPoint::first_point() by reference.

This commit is contained in:
bubnikv 2019-09-27 19:47:30 +02:00
parent 6d11bfe96a
commit 0abde9a2a8
2 changed files with 12 additions and 32 deletions

View File

@ -3,11 +3,6 @@
namespace Slic3r { namespace Slic3r {
MultiPoint::operator Points() const
{
return this->points;
}
void MultiPoint::scale(double factor) void MultiPoint::scale(double factor)
{ {
for (Point &pt : points) for (Point &pt : points)
@ -57,18 +52,7 @@ void MultiPoint::rotate(double angle, const Point &center)
} }
} }
void MultiPoint::reverse() double MultiPoint::length() const
{
std::reverse(this->points.begin(), this->points.end());
}
Point MultiPoint::first_point() const
{
return this->points.front();
}
double
MultiPoint::length() const
{ {
Lines lines = this->lines(); Lines lines = this->lines();
double len = 0; double len = 0;
@ -78,8 +62,7 @@ MultiPoint::length() const
return len; return len;
} }
int int MultiPoint::find_point(const Point &point) const
MultiPoint::find_point(const Point &point) const
{ {
for (const Point &pt : this->points) for (const Point &pt : this->points)
if (pt == point) if (pt == point)
@ -87,21 +70,18 @@ MultiPoint::find_point(const Point &point) const
return -1; // not found return -1; // not found
} }
bool bool MultiPoint::has_boundary_point(const Point &point) const
MultiPoint::has_boundary_point(const Point &point) const
{ {
double dist = (point.projection_onto(*this) - point).cast<double>().norm(); double dist = (point.projection_onto(*this) - point).cast<double>().norm();
return dist < SCALED_EPSILON; return dist < SCALED_EPSILON;
} }
BoundingBox BoundingBox MultiPoint::bounding_box() const
MultiPoint::bounding_box() const
{ {
return BoundingBox(this->points); return BoundingBox(this->points);
} }
bool bool MultiPoint::has_duplicate_points() const
MultiPoint::has_duplicate_points() const
{ {
for (size_t i = 1; i < points.size(); ++i) for (size_t i = 1; i < points.size(); ++i)
if (points[i-1] == points[i]) if (points[i-1] == points[i])
@ -109,8 +89,7 @@ MultiPoint::has_duplicate_points() const
return false; return false;
} }
bool bool MultiPoint::remove_duplicate_points()
MultiPoint::remove_duplicate_points()
{ {
size_t j = 0; size_t j = 0;
for (size_t i = 1; i < points.size(); ++i) { for (size_t i = 1; i < points.size(); ++i) {
@ -129,8 +108,7 @@ MultiPoint::remove_duplicate_points()
return false; return false;
} }
bool bool MultiPoint::intersection(const Line& line, Point* intersection) const
MultiPoint::intersection(const Line& line, Point* intersection) const
{ {
Lines lines = this->lines(); Lines lines = this->lines();
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it) { for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it) {

View File

@ -17,7 +17,8 @@ class MultiPoint
public: public:
Points points; Points points;
operator Points() const; operator Points() const { return this->points; }
MultiPoint() {} MultiPoint() {}
MultiPoint(const MultiPoint &other) : points(other.points) {} MultiPoint(const MultiPoint &other) : points(other.points) {}
MultiPoint(MultiPoint &&other) : points(std::move(other.points)) {} MultiPoint(MultiPoint &&other) : points(std::move(other.points)) {}
@ -32,8 +33,9 @@ public:
void rotate(double angle) { this->rotate(cos(angle), sin(angle)); } void rotate(double angle) { this->rotate(cos(angle), sin(angle)); }
void rotate(double cos_angle, double sin_angle); void rotate(double cos_angle, double sin_angle);
void rotate(double angle, const Point &center); void rotate(double angle, const Point &center);
void reverse(); void reverse() { std::reverse(this->points.begin(), this->points.end()); }
Point first_point() const;
const Point& first_point() const { return this->points.front(); }
virtual const Point& last_point() const = 0; virtual const Point& last_point() const = 0;
virtual Lines lines() const = 0; virtual Lines lines() const = 0;
size_t size() const { return points.size(); } size_t size() const { return points.size(); }