Removed various Point::ccw() and Point::ccw_angle() methods, they were

provided for Perl bindings and their semantic was confusing.
Implemented free function angle() to measure angle between two vectors.
Reworked Polygon::convex/concave_points(), changed the meaning of their
angle threshold parameter.
Removed some unused methods from Perl bindings and tests.
Reworked the "wipe inside at the external perimeter" function
after Point::ccw_angle() was removed.
This commit is contained in:
Vojtech Bubnik 2022-03-31 12:20:46 +02:00 committed by PavelMikus
parent 156a60017d
commit 7d02647ebf
13 changed files with 146 additions and 188 deletions

View file

@ -108,38 +108,6 @@ bool Point::nearest_point(const Points &points, Point* point) const
return true;
}
/* Three points are a counter-clockwise turn if ccw > 0, clockwise if
* ccw < 0, and collinear if ccw = 0 because ccw is a determinant that
* gives the signed area of the triangle formed by p1, p2 and this point.
* In other words it is the 2D cross product of p1-p2 and p1-this, i.e.
* z-component of their 3D cross product.
* We return double because it must be big enough to hold 2*max(|coordinate|)^2
*/
double Point::ccw(const Point &p1, const Point &p2) const
{
static_assert(sizeof(coord_t) == 4, "Point::ccw() requires a 32 bit coord_t");
return cross2((p2 - p1).cast<int64_t>(), (*this - p1).cast<int64_t>());
// return cross2((p2 - p1).cast<double>(), (*this - p1).cast<double>());
}
double Point::ccw(const Line &line) const
{
return this->ccw(line.a, line.b);
}
// returns the CCW angle between this-p1 and this-p2
// i.e. this assumes a CCW rotation from p1 to p2 around this
double Point::ccw_angle(const Point &p1, const Point &p2) const
{
const Point v1 = *this - p1;
const Point v2 = p2 - *this;
int64_t dot = int64_t(v1(0)) * int64_t(v2(0)) + int64_t(v1(1)) * int64_t(v2(1));
int64_t cross = int64_t(v1(0)) * int64_t(v2(1)) - int64_t(v1(1)) * int64_t(v2(0));
float angle = float(atan2(float(cross), float(dot)));
// we only want to return only positive angles
return angle <= 0 ? angle + 2*PI : angle;
}
Point Point::projection_onto(const MultiPoint &poly) const
{
Point running_projection = poly.first_point();