
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
bounding-rect
Advanced tools
A high-performance 2D rectangle manipulation library, providing efficient rectangle creation, transformation, and intersection detection capabilities
A high-performance 2D rectangle manipulation library, providing efficient rectangle creation, transformation, and intersection detection capabilities, optimized for graphics applications and collision detection.
npm install bounding-rect
import {
createRect,
set,
fromPoints,
intersects,
createVec2
} from 'bounding-rect';
// Create a rectangle
const rect = createRect();
set(rect, 10, 20, 100, 200);
// Create bounding rectangle from points
const points = new Float32Array([0,0, 50,30, 20,60]);
const boundingRect = createRect();
fromPoints(boundingRect, points);
// Intersection detection
const rectA = createRect();
set(rectA, 0, 0, 100, 100);
const rectB = createRect();
set(rectB, 50, 50, 100, 100);
const mtv = createVec2();
const hasIntersection = intersects(rectA, rectB, mtv);
console.log('Intersecting:', hasIntersection);
console.log('Minimum translation vector:', mtv);
createRect(): Float32ArrayCreates a rectangle instance with structure [x, y, width, height], initialized to all zeros.
createVec2(): Float32ArrayCreates a 2D vector instance with structure [x, y, _, _], with the last two elements reserved for 16-byte alignment.
createIntersectOpt(): Float32ArrayCreates an intersection detection options instance with structure [direction, bidirectional, touchThreshold, clamp] with default configurations.
set(out: Float32Array, x: number, y: number, width: number, height: number): voidSets the position and dimensions of a rectangle, automatically correcting negative width and height values.
fromCenter(out: Float32Array, cx: number, cy: number, width: number, height: number): voidCreates a rectangle from a center point.
fromPoints(out: Float32Array, points: Float32Array): voidCreates a bounding rectangle from a set of points, calculating the smallest rectangle that can contain all points.
fromLine(out: Float32Array, x0: number, y0: number, x1: number, y1: number): voidCreates a bounding rectangle from a line segment.
fromCubic(out: Float32Array, x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): voidCreates a bounding rectangle from a cubic Bézier curve, considering the curve's extrema points.
copy(out: Float32Array, a: Float32Array): voidCopies rectangle data from one rectangle to another.
union(out: Float32Array, a: Float32Array, b: Float32Array): voidMerges two rectangles, calculating the smallest rectangle that can contain both.
expand(out: Float32Array, rect: Float32Array, amount: number): voidUniformly expands a rectangle in all directions by a specified distance.
contract(out: Float32Array, rect: Float32Array, amount: number): voidUniformly contracts a rectangle from all sides by a specified distance.
getCenter(out: Float32Array, rect: Float32Array): voidGets the center point coordinates of a rectangle.
contains(rect: Float32Array, x: number, y: number): 0 | 1Checks if a point is inside a rectangle, returns 1 if inside, 0 if outside.
transformNoRotate(out: Float32Array, rect: Float32Array, m: Float32Array): voidApplies a non-rotational transformation to a rectangle (fast path), suitable for transformations containing only translation and scaling.
transform(out: Float32Array, rect: Float32Array, m: Float32Array): voidApplies a general transformation to a rectangle, suitable for complex transformations including rotation and shearing.
intersects(a: Float32Array, b: Float32Array, mtv: Float32Array): 0 | 1Basic intersection detection, checks if two rectangles intersect and calculates the minimum translation vector (MTV).
intersectsSmall(a: Float32Array, b: Float32Array, mtv: Float32Array): 0 | 1Specialized intersection detection for small rectangles, optimized for rectangles with smaller dimensions.
intersectsWithDir(a: Float32Array, b: Float32Array, mtv: Float32Array, dir: number): 0 | 1Direction-constrained intersection detection, only detects intersections in a specific direction.
intersectsWithOpt(a: Float32Array, b: Float32Array, mtv: Float32Array, opt: Float32Array): 0 | 1Intersection detection with options, supporting configuration of contact threshold, detection direction, etc.
intersectsBatch(rect: Float32Array, others: Float32Array[], count: number, outResults: Uint8Array): voidBatch detection of intersections between a rectangle and an array of rectangles, efficiently handling multiple detections.
areaBatchSIMD(rects: Float32Array[], count: number, outAreas: Float32Array): voidBatch calculates the area of rectangles, efficiently computing areas for multiple rectangles.
isEmpty(rect: Float32Array): 0 | 1Checks if a rectangle is empty, returns 1 if empty, 0 if non-empty.
isFinite(rect: Float32Array): 0 | 1Checks if a rectangle is valid (all values are finite numbers), returns 1 if valid, 0 if invalid.
area(rect: Float32Array): numberCalculates the area of a rectangle.
distance(a: Float32Array, b: Float32Array): numberCalculates the distance between two rectangles.
This library depends on the mat3 library for matrix operations, which will be installed automatically.
MIT
FAQs
A high-performance 2D rectangle manipulation library, providing efficient rectangle creation, transformation, and intersection detection capabilities
We found that bounding-rect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.