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
-
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
from coordinatesDeclaration
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
-
Determine whether a point is on the line
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 }
-
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
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
-
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
-
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 receiverDeclaration
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)