geom-center-and-normalize 2.2.0 → 2.3.0
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/CHANGELOG.md +19 -0
- package/README.md +6 -2
- package/index.js +19 -13
- package/package.json +20 -11
- package/types/index.d.ts +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
# [2.3.0](https://github.com/vorg/geom-center-and-normalize/compare/v2.2.1...v2.3.0) (2026-10-12)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* flip align sign so -1 aligns the bounding box min ([907727b](https://github.com/vorg/geom-center-and-normalize/commit/907727bf2c084058e251cb45d270aac497889a5c))
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add align option ([d0596b5](https://github.com/vorg/geom-center-and-normalize/commit/d0596b5a71b3a49c726ea382ffc8427eeb106149))
|
|
14
|
+
|
|
15
|
+
## [2.2.1](https://github.com/vorg/geom-center-and-normalize/compare/v2.2.0...v2.2.1) (2025-09-21)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* apply centering regardles of normalization ([b0d14a4](https://github.com/vorg/geom-center-and-normalize/commit/b0d14a464da927ec4a320b52ad03e55fb7d9d705)), closes [#11](https://github.com/vorg/geom-center-and-normalize/issues/11)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
5
24
|
# [2.2.0](https://github.com/vorg/geom-center-and-normalize/compare/v2.1.1...v2.2.0) (2024-04-16)
|
|
6
25
|
|
|
7
26
|
|
package/README.md
CHANGED
|
@@ -37,11 +37,15 @@ const normalizedPositions = centerAndNormalize(positions);
|
|
|
37
37
|
|
|
38
38
|
- positions: `TypedArray | Array | Array<[x, y, z]>` – simplicial complex geometry positions (eg. `new Float32Array([x, y, z, x, y, z, ...])/new Array(x, y, z, x, y, z, ...)` or `new Array([x, y, z], [x, y, z], ...)`)
|
|
39
39
|
|
|
40
|
-
- options: `
|
|
40
|
+
- options: `object`
|
|
41
|
+
- `center: boolean` – move the bounding box center to `[0, 0, 0]`. Defaults to `true`.
|
|
42
|
+
- `normalize: boolean` – scale positions uniformly so that the bounding box largest side is `normalizedSize`. Defaults to `true`.
|
|
43
|
+
- `normalizedSize: number` – size of the bounding box largest side when normalizing. Defaults to `1`.
|
|
44
|
+
- `align: [x, y, z]` – per axis position on the bounding box, from `-1` (min) through `0` (center) to `1` (max), placed at the anchor: `[0, 0, 0]` when centering, the original bounding box center otherwise. Eg. `[0, -1, 0]` aligns the bounding box min y to the anchor. Defaults to `[0, 0, 0]`.
|
|
41
45
|
|
|
42
46
|
**Returns**
|
|
43
47
|
|
|
44
|
-
- positions: `TypedArray | Array | Array<[x, y, z]>` – The positions parameter array updated, centered at `[0, 0, 0]`
|
|
48
|
+
- positions: `TypedArray | Array | Array<[x, y, z]>` – The positions parameter array updated in place, by default centered at `[0, 0, 0]` with its bounding box largest side normalized to `normalizedSize`.
|
|
45
49
|
|
|
46
50
|
## License
|
|
47
51
|
|
package/index.js
CHANGED
|
@@ -5,33 +5,39 @@ const TEMP_VEC3 = vec3.create();
|
|
|
5
5
|
|
|
6
6
|
function centerAndNormalize(
|
|
7
7
|
positions,
|
|
8
|
-
{
|
|
8
|
+
{
|
|
9
|
+
center = true,
|
|
10
|
+
normalize = true,
|
|
11
|
+
normalizedSize = 1,
|
|
12
|
+
align = [0, 0, 0],
|
|
13
|
+
} = {},
|
|
9
14
|
) {
|
|
15
|
+
if (!center && !normalize && !align.some(Boolean)) return positions;
|
|
16
|
+
|
|
10
17
|
const isFlatArray = !positions[0]?.length;
|
|
11
18
|
const positionsCount = positions.length / (isFlatArray ? 3 : 1);
|
|
12
19
|
|
|
13
20
|
const bbox = aabb.fromPoints(aabb.create(), positions);
|
|
14
21
|
const bboxCenter = aabb.center(bbox);
|
|
22
|
+
const size = aabb.size(bbox);
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
const scale = normalize ? normalizedSize / (Math.max(...size) || 1) : 1;
|
|
25
|
+
|
|
26
|
+
const translation = bboxCenter.map(
|
|
27
|
+
(c, i) => (center ? 0 : c) - (align[i] * size[i] * scale) / 2,
|
|
28
|
+
);
|
|
29
|
+
const translate = translation.some(Boolean);
|
|
20
30
|
|
|
21
31
|
for (let i = 0; i < positionsCount; i++) {
|
|
22
32
|
if (isFlatArray) {
|
|
23
33
|
avec3.sub(positions, i, bboxCenter, 0);
|
|
24
|
-
if (normalize)
|
|
25
|
-
|
|
26
|
-
if (!center) avec3.add(positions, i, bboxCenter, 0);
|
|
27
|
-
}
|
|
34
|
+
if (normalize) avec3.scale(positions, i, scale);
|
|
35
|
+
if (translate) avec3.add(positions, i, translation, 0);
|
|
28
36
|
} else {
|
|
29
37
|
vec3.set(TEMP_VEC3, positions[i]);
|
|
30
38
|
vec3.sub(TEMP_VEC3, bboxCenter);
|
|
31
|
-
if (normalize)
|
|
32
|
-
|
|
33
|
-
if (!center) vec3.add(TEMP_VEC3, bboxCenter);
|
|
34
|
-
}
|
|
39
|
+
if (normalize) vec3.scale(TEMP_VEC3, scale);
|
|
40
|
+
if (translate) vec3.add(TEMP_VEC3, translation);
|
|
35
41
|
vec3.set(positions[i], TEMP_VEC3);
|
|
36
42
|
}
|
|
37
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geom-center-and-normalize",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Center a simplicial complex geometry's positions in place and scale them to fill a defined bounding box.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"geom",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
],
|
|
16
16
|
"homepage": "https://github.com/vorg/geom-center-and-normalize",
|
|
17
17
|
"bugs": "https://github.com/vorg/geom-center-and-normalize/issues",
|
|
18
|
-
"repository":
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/vorg/geom-center-and-normalize.git"
|
|
21
|
+
},
|
|
19
22
|
"license": "MIT",
|
|
20
23
|
"author": "Marcin Ignac <marcin.ignac@gmail.com> (https://github.com/vorg)",
|
|
21
24
|
"contributors": [
|
|
@@ -23,20 +26,26 @@
|
|
|
23
26
|
],
|
|
24
27
|
"sideEffects": false,
|
|
25
28
|
"type": "module",
|
|
26
|
-
"exports":
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./types/index.d.ts",
|
|
32
|
+
"default": "./index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./index.js",
|
|
36
|
+
"types": "./types/index.d.ts",
|
|
29
37
|
"scripts": {
|
|
30
38
|
"release": "snowdev release",
|
|
31
|
-
"test": "node --test",
|
|
32
|
-
"test:watch": "node --
|
|
39
|
+
"test": "node --experimental-test-coverage test",
|
|
40
|
+
"test:watch": "node --watch --experimental-test-coverage test"
|
|
33
41
|
},
|
|
34
42
|
"dependencies": {
|
|
35
|
-
"pex-geom": "^3.
|
|
36
|
-
"pex-math": "^4.
|
|
43
|
+
"pex-geom": "^3.1.2",
|
|
44
|
+
"pex-math": "^4.4.0"
|
|
37
45
|
},
|
|
46
|
+
"packageManager": "npm@11.3.0",
|
|
38
47
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
-
"
|
|
48
|
+
"node": ">=24.0.0",
|
|
49
|
+
"snowdev": ">=3.0.0-alpha.3"
|
|
41
50
|
}
|
|
42
51
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export default centerAndNormalize;
|
|
2
|
-
declare function centerAndNormalize(positions: any, { center, normalize, normalizedSize }?: {
|
|
3
|
-
center?: boolean;
|
|
4
|
-
normalize?: boolean;
|
|
5
|
-
normalizedSize?: number;
|
|
2
|
+
declare function centerAndNormalize(positions: any, { center, normalize, normalizedSize, align, }?: {
|
|
3
|
+
center?: boolean | undefined;
|
|
4
|
+
normalize?: boolean | undefined;
|
|
5
|
+
normalizedSize?: number | undefined;
|
|
6
|
+
align?: number[] | undefined;
|
|
6
7
|
}): any;
|