Skip to content
FutureBlitz

    Install

    Import std.math.geometry

    Rect

    std.math.geometry

    struct

    Public Struct Rect Implements Equatable, Printable

    A rectangle in 2D, from its corner with the smallest X and Y, of a Width and Height that aren't negative.

    Examples

    
    Local a = Rect(0, 0, 10, 10)
    Local b = Rect(5, 5, 10, 10)
    Expect(a.Intersects(b))
    Expect(a.Intersection(b) == Rect(5, 5, 5, 5))
    Expect(a.Union(b) == Rect(0, 0, 15, 15))
    Expect(a.Contains(Vec2(2, 3)) && !a.Contains(Vec2(12, 3)))

    std/math/geometry.fb, line 30

    • Public Field X: Float field #

      Its left edge, the smallest X it has.

    • Public Field Y: Float field #

      Its top edge, the smallest Y it has.

    • Public Field Width: Float field #

      How wide it is, which isn't negative.

    • Public Field Height: Float field #

      How high it is, which isn't negative.

    • Public Static Method FromCorners(a: Vec2, b: Vec2): Rect static method #

      The rectangle from one corner to the other, whichever way around they are.

    • Public Static Method FromCenter(center: Vec2, size: Vec2): Rect static method #

      The rectangle of the size, with its center at the point.

    • Public Property Min: Vec2 property #

      The corner with the smallest X and Y.

    • Public Property Max: Vec2 property #

      The corner with the largest X and Y.

    • Public Property Center: Vec2 property #

      The point in its middle.

    • Public Property Size: Vec2 property #

      Its Width and Height, as a Vec2.

    • Public Property Area: Float property #

      Its Width times its Height.

    • Public Method Contains(point: Vec2): Bool method #

      Whether the point is in the rectangle or on its edge.

    • Public Method Contains(other: Rect): Bool method #

      Whether the other rectangle is all in this one.

    • Public Method Intersects(other: Rect): Bool method #

      Whether the two have a point in common, an edge's included.

    • Public Method Intersection(other: Rect): Rect? method #

      The rectangle where the two overlap, or Null where they don't meet.

    • Public Method Union(other: Rect): Rect method #

      The smallest rectangle that holds both.

    • Public Method Grow(amount: Float): Rect method #

      The rectangle with each edge moved out by amount, or in by a negative one. Shrunk past nothing, a side is 0 long, at the center.

    • Public Method ToString(): String method #

      Its parts, as "Rect(0, 0, 10, 5)".

    Report an issue with this page or with FutureBlitz on GitHub.