Rectangle

public struct Rectangle : ConvexPolygonProtocol
extension Rectangle: AdditiveSemigroup
extension Rectangle: Equatable
extension Rectangle: CustomStringConvertible

A structure that contains the location and dimensions of a rectangle.

Todo

Consider storing vertices as with Polygon, as opposed to being computed.

Type Properties

  • Rectangle with origin and size values of zero.

    Declaration

    Swift

    public static let zero: Rectangle

Instance Properties

  • A Rectangle geometrically equivalent to this one, with positive height and width.

    Declaration

    Swift

    public var normalized: Rectangle { get }
  • Vertices comprising Rectangle.

    Declaration

    Swift

    public var vertices: VertexCollection { get }
  • Minimum X value.

    Declaration

    Swift

    public var minX: Double { get }
  • Horizontal midpoint.

    Declaration

    Swift

    public var midX: Double { get }
  • Maximum X value.

    Declaration

    Swift

    public var maxX: Double { get }
  • Minimum Y value.

    Declaration

    Swift

    public var minY: Double { get }
  • Vertical midpoint.

    Declaration

    Swift

    public var midY: Double { get }
  • Maximum Y value.

    Declaration

    Swift

    public var maxY: Double { get }
  • Declaration

    Swift

    public var isEmpty: Bool { get }

    Return Value

    true if the height or width properties of size are 0. Otherwise, false.

  • Center point.

    Declaration

    Swift

    public var center: Point { get }
  • Origin.

    Declaration

    Swift

    public let origin: Point
  • Size.

    Declaration

    Swift

    public let size: Size

Initializers

  • Creates a Rectangle with the given origin and the given size.

    Declaration

    Swift

    public init(origin: Point = Point(), size: Size = Size())
  • Creates a Rectangle with the given center and the given size.

    Declaration

    Swift

    public init(center: Point, size: Size)
  • Creates a Rectangle with the given x, y, width, and height values.

    Declaration

    Swift

    public init(x: Double, y: Double, width: Double, height: Double)
  • Creates a Rectangle with the given width and height, with an origin of Point().

    Declaration

    Swift

    public init(width: Double, height: Double)
  • Creates a Rectangle with the given minX, minY, maxX, and maxY values.

    Declaration

    Swift

    public init(minX: Double, minY: Double, maxX: Double, maxY: Double)
  • Creates a Rectangle with the given vertices.

    Warning

    Will crash if given invalid vertices.

    Declaration

    Swift

    public init<S>(vertices: S) where S : Sequence, S.Element == Point
  • Creates a Rectangle with the given polygon.

    Throws

    PolygonError if the given polygon is not rectangular.

    Declaration

    Swift

    public init(_ polygon: Polygon) throws

Instance Methods

  • Declaration

    Swift

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

    Return Value

    true if the given point is contained herein. Otherwise, false.

  • Declaration

    Swift

    public func translatedBy(x: Double = 0, y: Double = 0) -> Rectangle

    Return Value

    Rectangle translated by the given x and y values.

  • Declaration

    Swift

    public func translated(by point: Point) -> Rectangle

    Return Value

    Rectangle translated by the given point.

  • Declaration

    Swift

    public func scaled(by value: Double, around anchor: ScaleAnchor) -> Rectangle

    Return Value

    Rectangle with dimensions scaled by the given value around the given anchor.

  • Declaration

    Swift

    public func scaledBy(
        width widthScale: Double = 1,
        height heightScale: Double = 1,
        around anchor: ScaleAnchor
    ) -> Rectangle

    Return Value

    Rectangle with dimensions scaled by the given width and height, around the given anchor.

  • Declaration

    Swift

    public static func + (lhs: Rectangle, rhs: Rectangle) -> Rectangle

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }