Skip to content

intersects

Whether two rectangles have an area in common, exactly when intersection returns a rectangle: rectangles that only touch do not, and neither does an empty (zero width or height) rectangle.

Available since v3.1.5

import { intersects } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { intersects } from 'helpers4/geometry';
intersects(a: Rect, b: Rect): boolean
ParameterTypeDescription
aRectA rectangle
bRectAnother rectangle

boolean — true if they have an area in common

True when the rectangles have an area in common.

intersects(layer, viewport)

Adjacent rectangles do not intersect.

intersects({ x: 0, y: 0, width: 10, height: 10 }, { x: 10, y: 0, width: 10, height: 10 }) // => false

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