LineSegment
public struct LineSegment<Vector> : LineType, CustomStringConvertible where Vector : VectorType
extension LineSegment: Equatable where Vector: Equatable, Scalar: Equatable
extension LineSegment: Hashable where Vector: Hashable, Scalar: Hashable
extension LineSegment: Encodable where Vector: Encodable, Scalar: Encodable
extension LineSegment: Decodable where Vector: Decodable, Scalar: Decodable
extension LineSegment: BoundableType where Vector: VectorComparable
extension LineSegment: LineAdditive where Vector: VectorAdditive
extension LineSegment: LineMultiplicative where Vector: VectorMultiplicative
extension LineSegment: LineSigned where Vector: VectorSigned
extension LineSegment: LineDivisible where Vector: VectorDivisible
extension LineSegment: LineFloatingPoint & PointProjectableType & SignedDistanceMeasurableType where Vector: VectorFloatingPoint
extension LineSegment: LineReal where Vector: VectorReal
Represents a line segment as a pair of start and end N-dimensional vectors which describe a closed interval.
-
Declaration
Swift
public typealias Scalar = Vector.Scalar
-
The bounded start of this line segment, inclusive.
Declaration
Swift
public var start: Vector
-
The bounded end of this line segment, inclusive.
Declaration
Swift
public var end: Vector
-
Alias for
start
.Declaration
Swift
public var a: Vector { get }
-
Alias for
b
.Declaration
Swift
public var b: Vector { get }
-
Declaration
Swift
@inlinable public var category: LineCategory { get }
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public init(start: Vector, end: Vector)
-
Declaration
Swift
public func offsetBy(_ vector: Vector) -> LineSegment<Vector>
-
Declaration
Swift
public func withPointsScaledBy(_ factor: Vector) -> LineSegment<Vector>
-
Declaration
Swift
public func withPointsScaledBy( _ factor: Vector, around center: Vector ) -> Self
-
Gets the center point of this line segment.
Declaration
Swift
public var center: Vector { get }
-
Returns the length of this line.
Seealso
lengthSquared
Declaration
Swift
public var length: Scalar { get }
-
Returns a
DirectionalRay
representation of this ray, where the result’sstart
matchesstart
anddirection
matches(end - start).normalized()
.Precondition
(self.end - self.start).length > 0
Declaration
Swift
public var asDirectionalRay: DirectionalRay<Vector> { get }
-
Returns
true
for projected scalars (0-1), which describes a line segment.Declaration
Swift
public func containsProjectedNormalizedMagnitude( _ scalar: Vector.Scalar ) -> Bool
-
Returns the squared distance between this line and a given vector.
The projected point on which the distance is taken is capped between the start and end points.
let line = LineSegment2D(x1: 1, y1: 1, x2: 3, y2: 1) let point1 = Vector2D(x: 0, y: 0) let point2 = Vector2D(x: 2, y: 0) let point3 = Vector2D(x: 4, y: 0) print(line.distanceSquared(to: point1)) // Prints "2" print(line.distanceSquared(to: point2)) // Prints "1" print(line.distanceSquared(to: point3)) // Prints "2"
Declaration
Swift
@inlinable public func distanceSquared(to vector: Vector) -> Scalar