Rectangle

open class Rectangle : Polygon, CGDrawable, SVGDrawable, RayTracable
extension Rectangle: Intersectable
extension Rectangle: Hashable

A rectangle

  • x

    Origin X coordinate

    Declaration

    Swift

    public var x: Double
  • y

    Origin Y coordinate

    Declaration

    Swift

    public var y: Double
  • Width of the rectangle

    Declaration

    Swift

    public var width: Double
  • Height of the rectangle

    Declaration

    Swift

    public var height: Double
  • Instantiate a new Rectangle

    Declaration

    Swift

    public init(x: Double, y: Double, width: Double, height: Double)

    Parameters

    x

    Origin X coordinate

    y

    Origin Y coordinate

    width

    Width of the rectangle

    height

    Height of the rectangle

  • Instantiate a new Rectangle

    Declaration

    Swift

    public convenience init(centerX: Double, centerY: Double, width: Double, height: Double)

    Parameters

    x

    Origin X coordinate

    y

    Origin Y coordinate

    width

    Width of the rectangle

    height

    Height of the rectangle

  • Instantiate a new Rectangle

    Declaration

    Swift

    public init(center: Vector, width: Double, height: Double)

    Parameters

    x

    Origin X coordinate

    y

    Origin Y coordinate

    width

    Width of the rectangle

    height

    Height of the rectangle

  • A Rectangle that contains the receiver

    Declaration

    Swift

    public var boundingBox: Rectangle { get }
  • Returns the coordinates of the center of the Rectangle

    Declaration

    Swift

    public var center: Vector { get set }
  • A Line representing the top edge

    Declaration

    Swift

    public var topEdge: Line { get }
  • A Line representing the bottom edge

    Declaration

    Swift

    public var bottomEdge: Line { get }
  • A Line representing the left edge

    Declaration

    Swift

    public var leftEdge: Line { get }
  • A Line representing the right edge

    Declaration

    Swift

    public var rightEdge: Line { get }
  • Coordinate of the top-left corner

    Declaration

    Swift

    public var topLeft: Vector { get }
  • Coordinate of the top-right corner

    Declaration

    Swift

    public var topRight: Vector { get }
  • Coordinate of the bottom-left corner

    Declaration

    Swift

    public var bottomLeft: Vector { get }
  • Coordinate of the botom-left corner

    Declaration

    Swift

    public var bottomRight: Vector { get }
  • The minimum x coordinate

    Declaration

    Swift

    public var minX: Double { get }
  • The minimum y coordinate

    Declaration

    Swift

    public var minY: Double { get }
  • The maximum x coordinate

    Declaration

    Swift

    public var maxX: Double { get }
  • The maximum y coordinate

    Declaration

    Swift

    public var maxY: Double { get }
  • Returns the point on the rectangle where the specified angle originating from the center intersects

    Declaration

    Swift

    public func point(at angle: Radians) -> Vector

    Parameters

    theta

    Angle in radians

  • Declaration

    Swift

    public func angle(ofPoint point: Vector) -> Radians
  • Determine whether the specified point is in the rectangle

    Tests whether the point is between the left and right edges, and top and bottom edges

    Declaration

    Swift

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

    Parameters

    point

    Whether the point is inside the rectangle

  • Draw the receiver in the specified context

    Declaration

    Swift

    open 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

    open func debugDraw(in context: CGContext)

    Parameters

    context

    Context in which to draw

  • Create a XMLElement representing the receiver

    Declaration

    Swift

    open func svgElement() -> XMLElement
  • Create a grid of rectangles contained by the receiver.

    Declaration

    Swift

    public func frames(rows: Int, columns: Int, margin: Int = 50) -> [Rectangle]

    Parameters

    rows

    Number of rows

    columns

    Number of columns

    margin

    Margin between frames

    Return Value

    An array of the new Rectangles

RayTracable

  • Calculate the intersection point of a ray and the the Rectangle

    Adapted from Amy Williams et al.

    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

  • Create a Bézier path of the rectangle between the two points.

    This method returns a single BezierPath which draws lines from the start to end, passing through each corner.

    Declaration

    Swift

    public func bezierCurve(start: Radians, end: Radians) -> [BezierPath]

    Parameters

    start

    Starting angle

    end

    Ending Angle

    Return Value

    An array of BezierPath which draw the shape

  • 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: Rectangle, rhs: Rectangle) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)