Implement rest of LineSegment2D members.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m24s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 27s

This commit is contained in:
2024-10-07 15:36:48 -04:00
parent 143b7e7279
commit 29db4f0792
2 changed files with 44 additions and 1 deletions

View File

@@ -135,7 +135,8 @@ namespace J3ML::Geometry
/** @param d [out] If specified, this parameter receives the normalized distance along
this line segment which specifies the closest point on this line segment to
the specified point.
@return The distance between this line segment and the given object. */
@return The distance between this line segment and the given object.
@see */
float Distance(const Vector2& point) const;
float Distance(const Vector2& point, float& d) const;

View File

@@ -121,3 +121,45 @@ Vector2 Geometry::LineSegment2D::ClosestPoint(const Geometry::LineSegment2D &oth
return Vector2::Zero;
}
float Geometry::LineSegment2D::Distance(const Vector2 &point) const { float d; return Distance(point, d); }
float Geometry::LineSegment2D::Distance(const Vector2 &point, float &d) const {
/// See Christer Ericson's Real-Time Collision Detection, p. 130.
Vector2 closestPoint = ClosestPoint(point, d);
return closestPoint.Distance(point);
}
float Geometry::LineSegment2D::Distance(const Geometry::LineSegment2D &other) const { float d, d2; return Distance(other, d, d2);}
float Geometry::LineSegment2D::Distance(const Geometry::LineSegment2D &other, float &d) const { float d2; return Distance(other, d, d2); }
float Geometry::LineSegment2D::Distance(const Geometry::LineSegment2D &other, float &d, float &d2) const {
ClosestPoint(other, d, d2);
return GetPoint(d).Distance(other.GetPoint(d2));
}
float Geometry::LineSegment2D::DistanceSq(const Geometry::LineSegment2D &other) const {
float d, d2;
ClosestPoint(other, d, d2);
return GetPoint(d).DistanceSq(other.GetPoint(d2));
}
float Geometry::LineSegment2D::DistanceSq(const Vector2 &point) const {
float d;
/// See Christer Ericson's Real-Time Collision Detection, p.130.
Vector2 closestPoint = ClosestPoint(point, d);
return closestPoint.DistanceSq(point);
}
bool Geometry::LineSegment2D::Intersects(const Geometry::LineSegment2D &lineSegment, float epsilon) const {
return Distance(lineSegment) <= epsilon;
}
void Geometry::LineSegment2D::ProjectToAxis(const Vector2 &direction, float &outMin, float &outMax) const {
outMin = Vector2::Dot(direction, A);
outMax = Vector2::Dot(direction, B);
if (outMax < outMin)
Swap(outMin, outMax);
}