MCPcopy
hub / github.com/facebook/react / unionOfRects

Function unionOfRects

packages/react-devtools-timeline/src/view-base/geometry.js:128–147  ·  view source on GitHub ↗
(...rects: Rect[])

Source from the content-addressed store, hash-verified

126 * @returns Union of `rects`. If `rects` is empty, returns `zeroRect`.
127 */
128export function unionOfRects(...rects: Rect[]): Rect {
129 if (rects.length === 0) {
130 return zeroRect;
131 }
132
133 const [firstRect, ...remainingRects] = rects;
134 const boxUnion = remainingRects
135 .map(rectToBox)
136 .reduce((intermediateUnion, nextBox): Box => {
137 const [unionTop, unionRight, unionBottom, unionLeft] = intermediateUnion;
138 const [nextTop, nextRight, nextBottom, nextLeft] = nextBox;
139 return [
140 Math.min(unionTop, nextTop),
141 Math.max(unionRight, nextRight),
142 Math.max(unionBottom, nextBottom),
143 Math.min(unionLeft, nextLeft),
144 ];
145 }, rectToBox(firstRect));
146 return boxToRect(boxUnion);
147}

Callers 2

desiredSizeMethod · 0.90
geometry-test.jsFile · 0.90

Calls 3

rectToBoxFunction · 0.85
boxToRectFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected