* Expands this bounds to include the axis-aligned bounding box of * the given rect's four corners, optionally transformed through `m` * first. With a non-identity `m` (rotation, scale, etc.) the result * is the AABB of the transformed quad, not a transformed AABB. * @param x0 - The left x co
( x0: number, y0: number, x1: number, y1: number, m?: Matrix2d | Matrix3d, )
| 313 | * @param [m] - An optional transform applied to each corner before inclusion. |
| 314 | */ |
| 315 | addFrame( |
| 316 | x0: number, |
| 317 | y0: number, |
| 318 | x1: number, |
| 319 | y1: number, |
| 320 | m?: Matrix2d | Matrix3d, |
| 321 | ) { |
| 322 | if (m === undefined || m.isIdentity()) { |
| 323 | // no transform (or a no-op transform): fold the 4 corners' |
| 324 | // min/max directly into the AABB without any Point or |
| 325 | // `m.apply` work. Mirrors `addPoint` for each corner — |
| 326 | // using Math.min/max so the caller may pass swapped corners |
| 327 | // (x1 < x0 etc.) without breaking. |
| 328 | const minX = Math.min(x0, x1); |
| 329 | const maxX = Math.max(x0, x1); |
| 330 | const minY = Math.min(y0, y1); |
| 331 | const maxY = Math.max(y0, y1); |
| 332 | if (minX < this.min.x) { |
| 333 | this.min.x = minX; |
| 334 | } |
| 335 | if (maxX > this.max.x) { |
| 336 | this.max.x = maxX; |
| 337 | } |
| 338 | if (minY < this.min.y) { |
| 339 | this.min.y = minY; |
| 340 | } |
| 341 | if (maxY > this.max.y) { |
| 342 | this.max.y = maxY; |
| 343 | } |
| 344 | return; |
| 345 | } |
| 346 | // transformed: walk the 4 corners through `m` via `addPoint`. |
| 347 | // Reuse the module-level scratch — `m.apply` mutates in place |
| 348 | // and `addPoint` reads x/y immediately after, so the same Point |
| 349 | // can shuttle through all four corners. |
| 350 | const v = _addFrameScratch; |
| 351 | this.addPoint(v.set(x0, y0), m); |
| 352 | this.addPoint(v.set(x1, y0), m); |
| 353 | this.addPoint(v.set(x0, y1), m); |
| 354 | this.addPoint(v.set(x1, y1), m); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Returns true if the bounds contain the given point or vector. |
no test coverage detected