@expofp/geometry 3.44.8 → 3.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/rect.d.ts +3 -2
- package/dist/lib/rect.js +12 -3
- package/package.json +1 -1
package/dist/lib/rect.d.ts
CHANGED
|
@@ -147,11 +147,12 @@ export declare class Rect {
|
|
|
147
147
|
export declare function rectCorners(r: RectLike): Point[];
|
|
148
148
|
/**
|
|
149
149
|
* Returns the axis-aligned bounding box (AABB) that contains all four corners of a
|
|
150
|
-
* {@link RectLike}.
|
|
150
|
+
* {@link RectLike}. Allocates nothing when `target` is passed.
|
|
151
151
|
* @param r - the rect-like to compute bounds for
|
|
152
|
+
* @param target - optional box to write into
|
|
152
153
|
* @returns a {@link Box} representing the AABB
|
|
153
154
|
*/
|
|
154
|
-
export declare function rectBounds(r: RectLike): Box;
|
|
155
|
+
export declare function rectBounds(r: RectLike, target?: Box): Box;
|
|
155
156
|
/**
|
|
156
157
|
* Converts a {@link RectLike} to a triangulated {@link Polygon} via fan-triangulation, embedding
|
|
157
158
|
* the elevation as `z` on each vertex. Rect corners form a convex quad, so
|
package/dist/lib/rect.js
CHANGED
|
@@ -184,12 +184,21 @@ export function rectCorners(r) {
|
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* Returns the axis-aligned bounding box (AABB) that contains all four corners of a
|
|
187
|
-
* {@link RectLike}.
|
|
187
|
+
* {@link RectLike}. Allocates nothing when `target` is passed.
|
|
188
188
|
* @param r - the rect-like to compute bounds for
|
|
189
|
+
* @param target - optional box to write into
|
|
189
190
|
* @returns a {@link Box} representing the AABB
|
|
190
191
|
*/
|
|
191
|
-
export function rectBounds(r) {
|
|
192
|
-
|
|
192
|
+
export function rectBounds(r, target) {
|
|
193
|
+
const a = rot(r);
|
|
194
|
+
const cos = Math.abs(Math.cos(a));
|
|
195
|
+
const sin = Math.abs(Math.sin(a));
|
|
196
|
+
const w = Math.abs(r.size.x);
|
|
197
|
+
const h = Math.abs(r.size.y);
|
|
198
|
+
const hx = (w * cos + h * sin) / 2;
|
|
199
|
+
const hy = (w * sin + h * cos) / 2;
|
|
200
|
+
const { x, y } = r.center;
|
|
201
|
+
return (target ?? new Box()).set(x - hx, y - hy, x + hx, y + hy);
|
|
193
202
|
}
|
|
194
203
|
/**
|
|
195
204
|
* Converts a {@link RectLike} to a triangulated {@link Polygon} via fan-triangulation, embedding
|