Move semantics on MultiPoint, Polygon, Polyline.
Append methods on Polyline. squared length function on point->DistanceTo
This commit is contained in:
parent
50cdf8e6d1
commit
0b90ebd74e
6 changed files with 69 additions and 35 deletions
|
@ -130,24 +130,6 @@ MultiPoint::remove_duplicate_points()
|
|||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
MultiPoint::append(const Point &point)
|
||||
{
|
||||
this->points.push_back(point);
|
||||
}
|
||||
|
||||
void
|
||||
MultiPoint::append(const Points &points)
|
||||
{
|
||||
this->append(points.begin(), points.end());
|
||||
}
|
||||
|
||||
void
|
||||
MultiPoint::append(const Points::const_iterator &begin, const Points::const_iterator &end)
|
||||
{
|
||||
this->points.insert(this->points.end(), begin, end);
|
||||
}
|
||||
|
||||
bool
|
||||
MultiPoint::intersection(const Line& line, Point* intersection) const
|
||||
{
|
||||
|
|
|
@ -18,7 +18,11 @@ class MultiPoint
|
|||
|
||||
operator Points() const;
|
||||
MultiPoint() {};
|
||||
explicit MultiPoint(const Points &_points): points(_points) {};
|
||||
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; }
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void translate(const Point &vector);
|
||||
|
@ -38,9 +42,17 @@ class MultiPoint
|
|||
bool has_duplicate_points() const;
|
||||
// Remove exact duplicates, return true if any duplicate has been removed.
|
||||
bool remove_duplicate_points();
|
||||
void append(const Point &point);
|
||||
void append(const Points &points);
|
||||
void append(const Points::const_iterator &begin, const Points::const_iterator &end);
|
||||
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)
|
||||
{
|
||||
if (this->points.empty())
|
||||
this->points = std::move(src);
|
||||
else
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(this->points));
|
||||
}
|
||||
|
||||
bool intersection(const Line& line, Point* intersection) const;
|
||||
std::string dump_perl() const;
|
||||
|
||||
|
|
|
@ -174,14 +174,6 @@ Point::nearest_waypoint(const Points &points, const Point &dest, Point* point) c
|
|||
return true;
|
||||
}
|
||||
|
||||
double
|
||||
Point::distance_to(const Point &point) const
|
||||
{
|
||||
double dx = ((double)point.x - this->x);
|
||||
double dy = ((double)point.y - this->y);
|
||||
return sqrt(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
/* distance to the closest point of line */
|
||||
double
|
||||
Point::distance_to(const Line &line) const
|
||||
|
|
|
@ -54,7 +54,8 @@ class Point
|
|||
size_t nearest_waypoint_index(const Points &points, const Point &point) const;
|
||||
bool nearest_point(const Points &points, Point* point) const;
|
||||
bool nearest_waypoint(const Points &points, const Point &dest, Point* point) const;
|
||||
double distance_to(const Point &point) const;
|
||||
double distance_to(const Point &point) const { return sqrt(distance_to_sq(point)); }
|
||||
double distance_to_sq(const Point &point) const { double dx = double(point.x - this->x); double dy = double(point.y - this->y); return dx*dx + dy*dy; }
|
||||
double distance_to(const Line &line) const;
|
||||
double perp_distance_to(const Line &line) const;
|
||||
double ccw(const Point &p1, const Point &p2) const;
|
||||
|
|
|
@ -14,14 +14,19 @@ class Polygon;
|
|||
typedef std::vector<Polygon> Polygons;
|
||||
|
||||
class Polygon : public MultiPoint {
|
||||
public:
|
||||
public:
|
||||
operator Polygons() const;
|
||||
operator Polyline() const;
|
||||
Point& operator[](Points::size_type idx);
|
||||
const Point& operator[](Points::size_type idx) const;
|
||||
|
||||
Polygon() {};
|
||||
explicit Polygon(const Points &points): MultiPoint(points) {};
|
||||
Polygon() {}
|
||||
explicit Polygon(const Points &points): MultiPoint(points) {}
|
||||
Polygon(const Polygon &other) : MultiPoint(other.points) {}
|
||||
Polygon(Polygon &&other) : MultiPoint(std::move(other.points)) {}
|
||||
Polygon& operator=(const Polygon &other) { points = other.points; return *this; }
|
||||
Polygon& operator=(Polygon &&other) { points = std::move(other.points); return *this; }
|
||||
|
||||
Point last_point() const;
|
||||
virtual Lines lines() const;
|
||||
Polyline split_at_vertex(const Point &point) const;
|
||||
|
|
|
@ -15,7 +15,36 @@ typedef std::vector<Polyline> Polylines;
|
|||
typedef std::vector<ThickPolyline> ThickPolylines;
|
||||
|
||||
class Polyline : public MultiPoint {
|
||||
public:
|
||||
public:
|
||||
Polyline() {};
|
||||
Polyline(const Polyline &other) : MultiPoint(other.points) {}
|
||||
Polyline(Polyline &&other) : MultiPoint(std::move(other.points)) {}
|
||||
Polyline& operator=(const Polyline &other) { points = other.points; return *this; }
|
||||
Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; }
|
||||
|
||||
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)
|
||||
{
|
||||
if (this->points.empty())
|
||||
this->points = std::move(src);
|
||||
else
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(this->points));
|
||||
}
|
||||
void append(const Polyline &src)
|
||||
{
|
||||
points.insert(points.end(), src.points.begin(), src.points.end());
|
||||
}
|
||||
|
||||
void append(Polyline &&src)
|
||||
{
|
||||
if (this->points.empty())
|
||||
this->points = std::move(src.points);
|
||||
else
|
||||
std::move(std::begin(src.points), std::end(src.points), std::back_inserter(this->points));
|
||||
}
|
||||
|
||||
operator Polylines() const;
|
||||
operator Line() const;
|
||||
Point last_point() const;
|
||||
|
@ -63,6 +92,19 @@ inline Lines to_lines(const Polylines &polys)
|
|||
return lines;
|
||||
}
|
||||
|
||||
inline void polylines_append(Polylines &dst, const Polylines &src)
|
||||
{
|
||||
dst.insert(dst.end(), src.begin(), src.end());
|
||||
}
|
||||
|
||||
inline void polylines_append(Polylines &dst, Polylines &&src)
|
||||
{
|
||||
if (dst.empty())
|
||||
dst = std::move(src);
|
||||
else
|
||||
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
||||
}
|
||||
|
||||
class ThickPolyline : public Polyline {
|
||||
public:
|
||||
std::vector<coordf_t> width;
|
||||
|
|
Loading…
Add table
Reference in a new issue