Rect

public struct Rect : Equatable

Represents a rectangle.

  • Initializes a new instance of the Rect structure with location (0,0) and zero width and height.

    Declaration

    Swift

    public init()

    Return Value

    the newly created Rect.

  • Initializes a new instance of the Rect structure with the specified location, width and height.

    Declaration

    Swift

    public init(
        location: Point,
        size: Size)

    Parameters

    location

    The location of the top left corner of the rectangle.

    size

    The size of the rectangle.

    Return Value

    The newly created Rect.

  • Initializes a new instance of the Rect structure from the specified CGRect.

    Declaration

    Swift

    public init(rect: CGRect)

    Parameters

    rect

    The CGRect that provides data for the new rectangle.

    Return Value

    The newly created Rect.

  • Initializes a new instance of the Rect structure with the specified location, width and height.

    Declaration

    Swift

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

    Parameters

    x

    The x-coordinate of the top left corner of the rectangle.

    y

    The y-coordinate of the top left corner of the rectangle.

    width

    The width of the rectangle.

    height

    The height of the rectangle.

    Return Value

    The newly created Rect.

  • Creates a Rect from two points.

    Declaration

    Swift

    public static func fromPoints(
        _ p1: Point, _ p2: Point) -> Rect

    Parameters

    p1

    The location of the top left corner of the rectangle.

    p2

    The location of the bottom right corner of the rectangle.

    Return Value

    The newly created Rect.

  • Converts this Rect to a CGRect.

    Declaration

    Swift

    public func toCGRect() -> CGRect

    Return Value

    A CGRect that corresponds to this Rect.

  • Gets the x-coordinate of the top left corner of this Rect.

    Declaration

    Swift

    public func left() -> Double

    Return Value

    The x-coordinate of the top left corner.

  • Gets the x-coordinate of the bottom right corner of this Rect.

    Declaration

    Swift

    public func right() -> Double

    Return Value

    The x-coordinate of the bottom right corner.

  • Gets the y-coordinate of the top left corner of this Rect.

    Declaration

    Swift

    public func top() -> Double

    Return Value

    The y-coordinate of the top left corner.

  • Gets the y-coordinate of the bottom right corner of this Rect.

    Declaration

    Swift

    public func bottom() -> Double

    Return Value

    The y-coordinate of the bottom right corner.

  • Gets the top left corner of this Rect.

    Declaration

    Swift

    public func getLocation() -> Point

    Return Value

    The coordinate of the top left corner.

  • Gets the center of this Rect.

    Declaration

    Swift

    public func getCenter() -> Point

    Return Value

    The point at the center of this Rect.

  • Gets the bottom right corner of this Rect.

    Declaration

    Swift

    public func getBottomRight() -> Point

    Return Value

    The coordinate of the bottom right corner of this Rect.

  • Inflates the width and height of this Rect with the specified values.

    Declaration

    Swift

    public mutating func inflate(_ dx: Double, dy: Double)

    Parameters

    dx

    The value with which the width is inflated.

    dy

    The value with which the height is inflated.

  • Inflates the width and height of the specified Rect with the specified values.

    Declaration

    Swift

    public static func inflate(_ rect: Rect, dx: Double, dy: Double) -> Rect

    Parameters

    rect

    The Rect whose width and height are inflated.

    dx

    The value with which the width is inflated.

    dy

    The value with which the height is inflated.

    Return Value

    The inflated Rect.

  • Creates a Rect from the specified string.

    Declaration

    Swift

    public static func fromString(_ s: String) -> Rect

    Parameters

    s

    A string that contains the x and y coordinates, width and height of the new Rect. The values are expected to be separated by commas.

    Return Value

    The newly created Rect.

  • Creates a new Rect with the specified top-left and bottom-right coordinates.

    Declaration

    Swift

    public static func fromLTRB(_ left: Double, top: Double, right: Double, bottom: Double) -> Rect

    Parameters

    left

    The x-coordinate of the top left corner of the new Rect.

    top

    The y-coordinate of the top left corner of the new Rect.

    right

    The x-coordinate of the bottom right corner of the new Rect.

    bottom

    The y-coordinate of the bottom right corner of the new Rect.

    Return Value

    The newly created Rect.

  • Returns the union of the specified Rect objects.

    Declaration

    Swift

    public static func union(_ a: Rect!, b: Rect) -> Rect

    Parameters

    a

    The first rect to unite.

    b

    The second rect to unite.

    Return Value

    A Rect that represents the union of the two rectangles.

  • Returns the union of this Rect with the specified Rect object.

    Declaration

    Swift

    public func union(_ rect: Rect!) -> Rect

    Parameters

    rect

    The Rect to unite.

    Return Value

    A Rect that represents the union of the this Rect and the specified Rect.

  • Checks if the specified point is contained within this Rect.

    Declaration

    Swift

    public func containsPoint(_ p: Point) -> Bool

    Parameters

    p

    The point to check.

    Return Value

    true if the point is inside this Rect; otherwise false.

  • Checks if the specified Rect intersects within this Rect.

    Declaration

    Swift

    public func intersectsWith(_ r: Rect) -> Bool

    Parameters

    r

    The Rect to check.

    Return Value

    true if the specified Rect intersects with this Rect; otherwise false.

  • Checks if the specified Rect is contained within this Rect.

    Declaration

    Swift

    public func contains(_ r: Rect) -> Bool

    Parameters

    r

    The Rect to check.

    Return Value

    true if the specified Rect is inside this Rect; otherwise false.

  • Offsets the location of this Rect with the specified x and y values.

    Declaration

    Swift

    public mutating func offset(_ dx: Double, dy: Double)

    Parameters

    dx

    The value with which the x-coordinate of the top left corner is corrected.

    dy

    The value with which the y-coordinate of the top left corner is corrected.

  • Prints the top-left and bottom-right coordinates of this Rect.

    Declaration

    Swift

    public func printMe()
  • Calculates the center point of this Rect.

    Declaration

    Swift

    public var center: Point { get }

    Return Value

    The center of this Rect.

  • Gets the top left point of this Rect.

    Declaration

    Swift

    public var topLeft: Point { get }

    Return Value

    The top left point of this Rect.

  • Gets the top right point of this Rect.

    Declaration

    Swift

    public var topRight: Point { get }

    Return Value

    The top right point of this Rect.

  • Gets the bottom left point of this Rect.

    Declaration

    Swift

    public var bottomLeft: Point { get }

    Return Value

    The bottom left point of this Rect.

  • Gets the bottom right point of this Rect.

    Declaration

    Swift

    public var bottomRight: Point { get }

    Return Value

    The bottom right point of this Rect.

  • Calculates the middle left point of this Rect.

    Declaration

    Swift

    public var middleLeft: Point { get }

    Return Value

    The point that lies in the middle of the left side of this Rect.

  • Calculates the middle right point of this Rect.

    Declaration

    Swift

    public var middleRight: Point { get }

    Return Value

    The point that lies in the middle of the right side of this Rect.

  • Calculates the bottom middle point of this Rect.

    Declaration

    Swift

    public var bottomMiddle: Point { get }

    Return Value

    The point that lies in the middle of the bottom side of this Rect.

  • Calculates the top middle point of this Rect.

    Declaration

    Swift

    public var topMiddle: Point { get }

    Return Value

    The point that lies in the middle of the top side of this Rect.

  • Gets the four corner points of this Rect.

    Declaration

    Swift

    public func getCornerPoints() -> [Point]

    Return Value

    An array with the corner points of this Rect.

  • Gets the size of this Rect.

    Declaration

    Swift

    public var size: Size { get set }

    Return Value

    The size of this Rect.

  • Scales the width and height of this Rect with the specified amount. Note that the coordinates of the four corners of
    the Rect change as well.

    Declaration

    Swift

    public func scaledRect(_ scale: Double) -> Rect

    Return Value

    The scaled Rect.

  • x

    A double field for the x-coordinate of the top-left corner of this Rect.

    Declaration

    Swift

    public var x: Double
  • y

    A double field for the y-coordinate of the top-left corner of this Rect.

    Declaration

    Swift

    public var y: Double
  • A double field for the width of this Rect.

    Declaration

    Swift

    public var width: Double
  • A double field for the height of this Rect.

    Declaration

    Swift

    public var height: Double