MCPcopy
hub / github.com/williamngan/pts / boundingBox

Method boundingBox

src/Op.ts:518–534  ·  view source on GitHub ↗

* Given an array of rectangles, get a rectangle that bounds all of them. * @param rects an array of (Groups or Iterables ) that represents a set of rectangles * @returns the bounding rectangle as a Group

( rects:Iterable<PtLikeIterable> )

Source from the content-addressed store, hash-verified

516 * @returns the bounding rectangle as a Group
517 */
518 static boundingBox( rects:Iterable<PtLikeIterable> ):Group {
519 let _rects = Util.iterToArray( rects );
520 let merged = Util.flatten( _rects, false );
521 let min = Pt.make( 2, Number.MAX_VALUE );
522 let max = Pt.make( 2, Number.MIN_VALUE );
523
524 // calculate min max in a single pass
525 for (let i=0, len=merged.length; i<len; i++) {
526 let k = 0;
527 for (let m of merged[i]) {
528 min[k] = Math.min( min[k], m[k] );
529 max[k] = Math.max( max[k], m[k] );
530 if (++k >= 2) break;
531 }
532 }
533 return new Group( min, max );
534 }
535
536
537 /**

Callers 4

intersectRect2DMethod · 0.45
quadrantsMethod · 0.45
hasIntersectRect2DMethod · 0.45
toRectsMethod · 0.45

Calls 5

iterToArrayMethod · 0.80
flattenMethod · 0.80
makeMethod · 0.80
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected