Skip to content

Rectangle

Module Geometry.Rects

In ixfx, a rectangle has this shape:

type Rect = {
height: number
width: number
}

Rectangles can be positioned, meaning they also have an x & y, denoting the top-left corner:

type RectPositioned = Rect & {
x: number
y: number
}

Once you have data that conforms to Rect or RectPositioned, ixfx has a bunch of functions to help you work with them:

Distances, intersection

Creating

  • fromCenter - create a rectangle from a center
  • fromElement - create a rectangle based on size of a HTML element
  • fromNumbers - create a rectangle from a series of numbers (opposite of toNumbers)
  • fromTopLeft - create a rectangle from its top-left corner
  • random - create a random rectangle

Math

Etc

  • isEmpty - true if rectangle has 0 for height and width. Use Rects.Empty or Rects.EmptyPositioned to get an empty rectangle.
  • isPlaceholder - true if rectangle has NaN for height and width. Use Rects.Placeholder or Rects.PlaceholderPositioned to get a placeholder rectangle.