LineFloatingPoint
public protocol LineFloatingPoint : LineDivisible, PointProjectableType, SignedDistanceMeasurableType where Self.Vector : VectorFloatingPoint
Protocol for objects that form geometric lines with two floating-point vectors representing two points on the line.
-
mirror(point:
Default implementation) Mirrors a vector along this line such that the point is the same distance to the line, with a relative angle to its starting point that is the negative of the current point’s angle to the its starting point.
Default Implementation
Declaration
Swift
func mirror(point: Vector) -> Vector
-
projectUnclamped(_:
Default implementation) Performs a vector projection of a given vector with respect to this line. The resulting vector lies within the infinite line formed by extending
a <-> b
.Default Implementation
Declaration
Swift
func projectUnclamped(_ vector: Vector) -> Vector
-
projectedMagnitude(_:
Default implementation) Returns the result of creating a projection of this line’s start point projected towards this line’s end point, with a total magnitude of
scalar
.For
scalar == 0
, returnsself.a
, forscalar == self.length
, returnsself.b
.Default Implementation
Declaration
Swift
func projectedMagnitude(_ scalar: Magnitude) -> Vector
Parameters
scalar
A non-normalized magnitude that describes the length along the slope of this line to generate the point out of.
-
projectedNormalizedMagnitude(_:
Default implementation) Returns the result of creating a projection of this line’s start point projected towards this line’s end point, with a normalized magnitude of
scalar
.For
scalar == 0
, returnsself.a
, forscalar == 1
, returnsself.b
.Default Implementation
Declaration
Swift
func projectedNormalizedMagnitude(_ scalar: Magnitude) -> Vector
Parameters
scalar
A normalized magnitude that describes the length along the slope of this line to generate the point out of. Values outside the range [0, 1] are allowed and equate to projections past the endpoints of the line.
-
Returns
true
if a normalized, projectedscalar
representing a segment of this line with the same starting point and direction, withlength = self.length * scalar
, lies within the boundaries of this line.For infinite lines, all projected scalars lie within the line, while in line segments bounded with start/end points, only values laying in (0-1) are contained on the line.
Declaration
Swift
func containsProjectedNormalizedMagnitude(_ scalar: Magnitude) -> Bool
-
Returns a projected normalized magnitude that is guaranteed to be contained in this line.
Declaration
Swift
func clampProjectedNormalizedMagnitude(_ scalar: Magnitude) -> Magnitude
-
distanceSquared(to:
Default implementation) Returns the squared distance between this line and a given vector.
Seealso
distance(to:)
Default Implementation
Declaration
Swift
func distanceSquared(to vector: Vector) -> Vector.Scalar
-
distance(to:
Default implementation) Returns the distance between this line and a given vector.
Equivalent to
self.distanceSquared(to: vector).squareRoot()
.Seealso
distanceSquared(to:)
Default Implementation
Declaration
Swift
func distance(to vector: Vector) -> Vector.Scalar
-
project(_:
Extension method) Returns the closest point on this line to a given point.
The point is limited to the line’s bounds using
clampProjectedNormalizedMagnitude(_:)
, so it’s guaranteed to be withina <-> b
.Seealso
projectUnclamped(_:)
Declaration
Swift
@inlinable func project(_ vector: Vector) -> Vector
-
signedDistance(to:
Extension method) Declaration
Swift
func signedDistance(to point: Vector) -> Vector.Scalar