Implement rest of LineSegment2D members.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user