DirectionalRay

public struct DirectionalRay<Vector> : GeometricType where Vector : VectorFloatingPoint
extension DirectionalRay: LineType
extension DirectionalRay: Equatable where Vector: Equatable, Scalar: Equatable
extension DirectionalRay: Hashable where Vector: Hashable, Scalar: Hashable
extension DirectionalRay: Encodable where Vector: Encodable, Scalar: Encodable
extension DirectionalRay: Decodable where Vector: Decodable, Scalar: Decodable
extension DirectionalRay: LineAdditive where Vector: VectorAdditive
extension DirectionalRay: LineMultiplicative where Vector: VectorMultiplicative
extension DirectionalRay: LineSigned where Vector: VectorSigned
extension DirectionalRay: LineFloatingPoint & PointProjectableType & SignedDistanceMeasurableType where Vector: VectorFloatingPoint
extension DirectionalRay: LineReal where Vector: VectorReal

Represents an N-dimensional geometric ray which projects a line from a starting point in a specified direction to infinity.

  • Declaration

    Swift

    public typealias Scalar = Vector.Scalar
  • The starting position of this ray

    Declaration

    Swift

    public var start: Vector
  • A unit vector relative to start which indicates the direction of this ray.

    Must have length > 0.

    Declaration

    Swift

    @UnitVector
    public var direction: Vector { get set }
  • Initializes a directional ray with a given start position and direction vectors.

    The direction will be normalized before initializing.

    Precondition

    direction.length > 0

    Declaration

    Swift

    public init(start: Vector, direction: Vector)
  • Initializes a directional ray with a given line’s endpoints.

    The direction will be normalized before initializing.

    Precondition

    line.length > 0

    Declaration

    Swift

    public init<Line>(_ line: Line) where Vector == Line.Vector, Line : LineType
  • Initializes a directional ray with a line passing through a and b.

    The ray’s start point matches a.

    The direction will be normalized before initializing.

    Precondition

    line.length > 0

    Declaration

    Swift

    public init(a: Vector, b: Vector)
  • a

    Equivalent to start.

    Declaration

    Swift

    public var a: Vector { get }
  • b

    Equivalent to start + direction.

    Declaration

    Swift

    public var b: Vector { get }
  • Declaration

    Swift

    @inlinable
    public var category: LineCategory { get }

Available where Vector: VectorAdditive

  • Returns a Line representation of this directional ray, where line.a matches start and line.b matches start + direction.

    Declaration

    Swift

    var asLine: Line<Vector> { get }
  • Returns a Ray representation of this directional ray, where ray.start matches start and ray.b matches start + direction.

    Declaration

    Swift

    var asRay: Ray<Vector> { get }
  • Gets the slope of this directional ray.

    For directional rays this value always equates to direction.

    Declaration

    Swift

    public var lineSlope: Vector { get }
  • Declaration

    Swift

    public func offsetBy(_ vector: Vector) -> DirectionalRay<Vector>

Available where Vector: VectorMultiplicative

  • Precondition

    factor > Vector.zero

    Declaration

    Swift

    public func withPointsScaledBy(_ factor: Vector) -> DirectionalRay<Vector>
  • Declaration

    Swift

    public func withPointsScaledBy(
        _ factor: Vector,
        around center: Vector
    ) -> Self

Available where Vector: VectorFloatingPoint

  • Performs a vector projection of a given vector with respect to this directional ray, returning a scalar value representing the magnitude of the projected point laying on the infinite line defined by points start <-> start + direction.

    By multiplying the result of this function by direction and adding start, the projected point as it lays on this directional ray line can be obtained. This can also be achieved by using projectedMagnitude(_:).

    let ray = DirectionalRay2D(x: 1, y: 1, dx: 1, dy: 0)
    
    print(ray.projectAsScalar(.init(x: 5, y: 0))) // Prints "4"
    

    Declaration

    Swift

    @inlinable
    public func projectAsScalar(_ vector: Vector) -> Vector.Scalar
  • Returns the result of creating a projection of this ray’s start point projected in the direction of this ray’s direction, with a total magnitude of scalar.

    let ray = DirectionalRay2D(x: 1, y: 1, dx: 1, dy: 0)
    
    print(ray.projectedMagnitude(4)) // Prints "(x: 5, y: 0)"
    

    Declaration

    Swift

    @inlinable
    public func projectedMagnitude(_ scalar: Vector.Scalar) -> Vector
  • Returns true for all positive scalar values, which describes a ray.

    Declaration

    Swift

    public func containsProjectedNormalizedMagnitude(_ scalar: Vector.Scalar) -> Bool
  • Returns a projected normalized magnitude that is guaranteed to be contained in this line.

    For DirectionalRay, this is a clamped inclusive (0-∞ range.

    Declaration

    Swift

    public func clampProjectedNormalizedMagnitude(_ scalar: Vector.Scalar) -> Vector.Scalar