Line

open class Line : Shape, Intersectable, RayTracable
extension Line: CGDrawable
extension Line: SVGDrawable
extension Line: CustomStringConvertible
extension Line: Hashable

Represents a line between two points

  • The starting point of the line

    Declaration

    Swift

    public var start: Vector
  • end

    The ending point of the line

    Declaration

    Swift

    public var end: Vector
  • The length of the line

    Declaration

    Swift

    public var length: Double { get }
  • The midpoint of the line

    Declaration

    Swift

    public var center: Vector { get }
  • Instantiate a new Line

    Declaration

    Swift

    public init(_ start: Vector, _ end: Vector)

    Parameters

    start

    Starting point

    end

    Ending point

  • Instantiate a new Line from coordinates

    Declaration

    Swift

    public init(_ x1: Double, _ y1: Double, _ x2: Double, _ y2: Double)

    Parameters

    x1

    Starting X coordinate

    y1

    Starting Y coordinate

    x2

    Ending X coordinate

    y2

    Ending Y coordinate

  • Instantiate a new Line from a center point

    Declaration

    Swift

    public convenience init(center: Vector, direction: Radians, length: Double)

    Parameters

    center

    The center of the line

    direction

    The direction of the line

    length

    The length of the line

  • Determine whether a point is on the line

    From https://gamedev.stackexchange.com/a/57746

    Declaration

    Swift

    public func contains(_ point: Vector) -> Bool

    Parameters

    point

    Whether the point is on the line

  • A Rectangle that contains the receiver

    Declaration

    Swift

    public var boundingBox: Rectangle { get }
  • Calculate the vector normal of the line

    Declaration

    Swift

    public func normal() -> Vector

    Return Value

    A Vector whose heading is perpendicular to the line

  • Returns the angle of the line based on the slope

    Declaration

    Swift

    public func angle() -> Radians
  • Calculate the intersection point of a ray and a plane defined by the Line

    Declaration

    Swift

    public func rayPlaneIntersection(origin: Vector, dir: Vector) -> Vector?

    Parameters

    origin

    Origin of the ray

    dir

    Direction of the ray

    Return Value

    The point of intersection, if the ray intersections the plane

  • Return a point at the specified distance of the line

    Declaration

    Swift

    public func point(at distance: Double) -> Vector

    Parameters

    distance

    Distance from the end point

  • Linear interpolate the vector to another vector

    Declaration

    Swift

    public func lerp(_ percent: Double) -> Vector

    Parameters

    percent

    the amount of interpolation; some value between 0.0 and 1.0

    Return Value

    A Vector between the original two

RayTracable

  • Calculate the intersection point of a ray and the Line

    Declaration

    Swift

    public func rayIntersection(_ ray: Ray) -> Vector?

    Parameters

    origin

    Origin of the ray

    dir

    Direction of the ray

    Return Value

    The point of intersection, if the ray intersections the line

  • Declaration

    Swift

    public func modifyRay(_ ray: Ray)
  • Calculate points of intersection with another shape.

    Declaration

    Swift

    func intersections(with otherShape: Intersectable) -> [Vector]

    Parameters

    otherShape

    The shape with which to find intersection points

    Return Value

    An array of Vectors

  • Calculate points of intersection with a Line

    Declaration

    Swift

    func intersection(with otherShape: Line) -> [Vector]

    Parameters

    otherShape

    The shape with which to find intersection points

    Return Value

    An array of Vectors

  • Calculate points of intersection with a Circle

    Declaration

    Swift

    func intersection(with otherShape: Circle) -> [Vector]

    Parameters

    otherShape

    The shape with which to find intersection points

    Return Value

    An array of Vectors

  • Calculate points of intersection with a Rectangle

    Declaration

    Swift

    func intersection(with otherShape: Rectangle) -> [Vector]

    Parameters

    otherShape

    The shape with which to find intersection points

    Return Value

    An array of Vectors

  • Draw the receiver in the specified context

    Declaration

    Swift

    public func draw(in context: CGContext)

    Parameters

    context

    Context in which to draw

  • Draw a representation of the receiver meant for debugging the shape in the specified context

    Declaration

    Swift

    public func debugDraw(in context: CGContext)

    Parameters

    context

    Context in which to draw

  • Create a XMLElement representing the receiver

    Declaration

    Swift

    public func svgElement() -> XMLElement
  • A textual representation of this instance.

    Declaration

    Swift

    public var description: String { get }
  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    Declaration

    Swift

    public static func == (lhs: Line, rhs: Line) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)