-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afe8377
commit e328494
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { IShape } from "@thi.ng/geom-api"; | ||
import type { ReadonlyVec } from "@thi.ng/vectors"; | ||
import { mulN } from "@thi.ng/vectors/muln"; | ||
import { scale } from "./scale.js"; | ||
import { translate } from "./translate.js"; | ||
|
||
/** | ||
* Applies a sequence of translate and scale operations to return an uniformly | ||
* scaled version of the given shape using `center` as the point of reference. | ||
* | ||
* @remarks | ||
* This op is likely slower than using {@link transform} with a equivalent | ||
* transformation matrix (e.g. using [`scaleWithCenter()` from | ||
* thi.ng/matrices](https://docs.thi.ng/umbrella/matrices/functions/scaleWithCenter23.html)), | ||
* but will not change the shape type (as might be the case with `transform()`). | ||
* | ||
* Also see: {@link scale}, {@link translate}, {@link applyTransforms}. | ||
* | ||
* @param shape | ||
* @param center | ||
* @param factor | ||
*/ | ||
export const scaleWithCenter = ( | ||
shape: IShape, | ||
center: ReadonlyVec, | ||
factor: number | ||
) => translate(scale(translate(shape, mulN([], center, -1)), factor), center); |