* 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> )
| 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 | /** |
no test coverage detected