Skip to content

Commit e328494

Browse files
feat(geom): add scaleWithCenter()
1 parent afe8377 commit e328494

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packages/geom/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export * from "./point-inside.js";
7373
export * from "./resample.js";
7474
export * from "./rotate.js";
7575
export * from "./scale.js";
76+
export * from "./scale-with-center.js";
7677
export * from "./scatter.js";
7778
export * from "./simplify.js";
7879
export * from "./split-arclength.js";
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { IShape } from "@thi.ng/geom-api";
2+
import type { ReadonlyVec } from "@thi.ng/vectors";
3+
import { mulN } from "@thi.ng/vectors/muln";
4+
import { scale } from "./scale.js";
5+
import { translate } from "./translate.js";
6+
7+
/**
8+
* Applies a sequence of translate and scale operations to return an uniformly
9+
* scaled version of the given shape using `center` as the point of reference.
10+
*
11+
* @remarks
12+
* This op is likely slower than using {@link transform} with a equivalent
13+
* transformation matrix (e.g. using [`scaleWithCenter()` from
14+
* thi.ng/matrices](https://docs.thi.ng/umbrella/matrices/functions/scaleWithCenter23.html)),
15+
* but will not change the shape type (as might be the case with `transform()`).
16+
*
17+
* Also see: {@link scale}, {@link translate}, {@link applyTransforms}.
18+
*
19+
* @param shape
20+
* @param center
21+
* @param factor
22+
*/
23+
export const scaleWithCenter = (
24+
shape: IShape,
25+
center: ReadonlyVec,
26+
factor: number
27+
) => translate(scale(translate(shape, mulN([], center, -1)), factor), center);

0 commit comments

Comments
 (0)