Skip to content

union

The smallest rectangle that contains all the given rectangles, e.g. the bounds of a group of layers.

Available since v3.1.5

import { union } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { union } from 'helpers4/geometry';
union(rects: readonly Rect[]): Rect | undefined
ParameterTypeDescription
rectsreadonly Rect[]The rectangles

Rect | undefined — Their bounding rectangle, or undefined for none

The smallest rectangle containing every layer.

union([{ x: 0, y: 0, width: 10, height: 10 }, { x: 20, y: 5, width: 10, height: 10 }])
// => { x: 0, y: 0, width: 30, height: 15 }

No rectangle, no bounds.

union([]) // => undefined

An axis-aligned rectangle: its top-left corner and its size. Width and height are expected to be non-negative.

interface Rect {
  height: number;
  width: number;
  x: number;
  y: number;
}

View source on GitHub