ConstructableRectangleType

public protocol ConstructableRectangleType : RectangleType

Protocol for rectangle geometric types that can be constructed with location and size.

Rectangle types that cannot be constructed with arbitrary location or sizes (e.g. NSquare has location but size is restricted to a single side length scalar) should not conform to this protocol, instead use base protocol RectangleType.

  • Initializes a new instance of a ConstructableRectangleType with the given location and size vectors.

    Declaration

    Swift

    init(location: Vector, size: Vector)
  • withLocation(_:) Default implementation

    Returns a new rectangle that matches this rectangles’s size with a new location.

    let rect = Rectangle2D(x: 20, y: 30, width: 50, height: 50)
    
    let result = rect.withLocation(.init(x: 5, y: 10))
    
    print(result) // Prints "(location: (x: 5, y: 10), size: (width: 50, height: 50))"
    

    Default Implementation

    Declaration

    Swift

    func withLocation(_ location: Vector) -> Self
  • withSize(_:) Default implementation

    Returns a new rectangle that matches this rectangles’s location with a new size.

    let rect = Rectangle2D(x: 20, y: 30, width: 50, height: 50)
    
    let result = rect.withSize(.init(x: 25, y: 25))
    
    print(result) // Prints "(location: (x: 20, y: 30), size: (width: 25, height: 25))"
    

    Default Implementation

    Declaration

    Swift

    func withSize(_ size: Vector) -> Self

Available where Vector: Vector2Type

  • x Extension method

    Gets or sets the X position of this Rectangle.

    Declaration

    Swift

    var x: Vector.Scalar { get set }
  • y Extension method

    Gets or sets the Y position of this Rectangle.

    Declaration

    Swift

    var y: Vector.Scalar { get set }
  • width Extension method

    Gets or sets the width of this Rectangle.

    Declaration

    Swift

    var width: Vector.Scalar { get set }
  • height Extension method

    Gets or sets the height of this Rectangle.

    Declaration

    Swift

    var height: Vector.Scalar { get set }
  • init(x:y:width:height:) Extension method

    Initializes a Rectangle with the coordinates of a 2D rectangle.

    Declaration

    Swift

    init(x: Vector.Scalar, y: Vector.Scalar, width: Vector.Scalar, height: Vector.Scalar)
  • withSize(width:height:) Extension method

    Returns a Rectangle that matches this rectangle’s size with a new location.

    Declaration

    Swift

    func withSize(width: Vector.Scalar, height: Vector.Scalar) -> Self
  • withLocation(x:y:) Extension method

    Returns a rectangle that matches this rectangle’s size with a new location.

    Declaration

    Swift

    func withLocation(x: Vector.Scalar, y: Vector.Scalar) -> Self
  • movingTop(to:) Extension method

    Returns a new Rectangle with the same left, right, and height as the current instance, where the top lays on value.

    Declaration

    Swift

    func movingTop(to value: Vector.Scalar) -> Self
  • movingLeft(to:) Extension method

    Returns a new Rectangle with the same top, bottom, and width as the current instance, where the left lays on value.

    Declaration

    Swift

    func movingLeft(to value: Vector.Scalar) -> Self

Available where Self: AdditiveRectangleType, Vector: Vector2Type

  • offsetBy(x:y:) Extension method

    Returns a copy of this Rectangle with the minimum and maximum coordinates offset by a given amount.

    Declaration

    Swift

    func offsetBy(x: Vector.Scalar, y: Vector.Scalar) -> Self