struct

Image::Rectangle

Inherits Struct < Value < Object

Rectangle represents an axis-aligned rectangular region.

Rectangles define regions in images using two points:

  • min: Top-left corner (inclusive)
  • max: Bottom-right corner (exclusive)

The half-open interval [min, max) means a pixel at (x, y) is inside the rectangle if min.x <= x < max.x and min.y <= y < max.y.

Rectangles are value types (structs) and support:

  • Translation: rect + point, rect - point
  • Inset/outset: rect.inset(n)
  • Set operations: intersect, union
  • Queries: empty?, overlaps?, in?

Empty rectangles (where min >= max) are valid and represent zero area. Many operations preserve or return empty rectangles as appropriate.

Memory layout: 16 bytes (2 Point values)

Example:

# Create 100x100 rectangle at origin
rect = Image.rect(0, 0, 100, 100)
rect.width  # 100
rect.height # 100

# Move rectangle
moved = rect + Image::Point.new(50, 50)

# Shrink by 10 pixels on all sides
inset = rect.inset(10) # rect(10, 10, 90, 90)

# Find overlap between two rectangles
r1 = Image.rect(0, 0, 100, 100)
r2 = Image.rect(50, 50, 150, 150)
overlap = r1.intersect(r2) # rect(50, 50, 100, 100)

Constructors

Instance methods

+(other : Point) : Rectangle
Source
-(other : Point) : Rectangle
Source
canon

Ensure min < max (swap if needed)

Source
empty?
Source
height
Source
in?(other : Rectangle) : Bool

Check if this rectangle is contained in other

Source
inset(n : Int32) : Rectangle

Inset rectangle by n pixels on all sides Positive n shrinks, negative n expands

Source
intersect(other : Rectangle) : Rectangle

Intersection of two rectangles

Source
overlaps?(other : Rectangle) : Bool

Check if rectangles overlap

Source
size
Source
union(other : Rectangle) : Rectangle

Union (bounding box) of two rectangles

Source
width
Source