Ported Polygon->split_at()

This commit is contained in:
Alessandro Ranellucci 2013-08-26 22:39:35 +02:00
parent f8ac3aa68f
commit 1f734807b9
7 changed files with 19 additions and 20 deletions

View file

@ -26,7 +26,7 @@ Point::rotate(double angle, Point* center)
}
bool
Point::coincides_with(Point* point)
Point::coincides_with(const Point* point) const
{
return this->x == point->x && this->y == point->y;
}

View file

@ -19,7 +19,7 @@ class Point
void scale(double factor);
void translate(double x, double y);
void rotate(double angle, Point* center);
bool coincides_with(Point* point);
bool coincides_with(const Point* point) const;
};
typedef std::vector<Point> Points;

View file

@ -23,6 +23,18 @@ Polygon::lines()
return lines;
}
Polyline*
Polygon::split_at(const Point* point)
{
// find index of point
for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
if ((*it).coincides_with(point)) {
return this->split_at_index(it - this->points.begin());
}
}
throw "Point not found";
}
Polyline*
Polygon::split_at_index(int index)
{

View file

@ -13,6 +13,7 @@ class Polygon : public MultiPoint {
public:
SV* to_SV_ref();
Lines lines();
Polyline* split_at(const Point* point);
Polyline* split_at_index(int index);
Polyline* split_at_first_point();
bool is_counter_clockwise();