geom-center-and-normalize 2.1.1 → 2.2.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/CHANGELOG.md +18 -0
- package/README.md +2 -2
- package/index.js +6 -6
- package/package.json +5 -2
- package/types/index.d.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
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.2.1](https://github.com/vorg/geom-center-and-normalize/compare/v2.2.0...v2.2.1) (2025-09-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* 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)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [2.2.0](https://github.com/vorg/geom-center-and-normalize/compare/v2.1.1...v2.2.0) (2024-04-16)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* rename scale to normalizedSize ([8007608](https://github.com/vorg/geom-center-and-normalize/commit/800760830ee69d2a882d74447ce97e56ead7e857))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
5
23
|
## [2.1.1](https://github.com/vorg/geom-center-and-normalize/compare/v2.1.0...v2.1.1) (2024-03-14)
|
|
6
24
|
|
|
7
25
|
|
package/README.md
CHANGED
|
@@ -37,11 +37,11 @@ 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: `{ center: boolean, normalize: boolean,
|
|
40
|
+
- options: `{ center: boolean, normalize: boolean, normalizedSize: number }` – enable/disable centering/normalizing and control normalized scaling. `center` and `normalize` defaults to `true`. Scale defaults to `1`.
|
|
41
41
|
|
|
42
42
|
**Returns**
|
|
43
43
|
|
|
44
|
-
- positions: `TypedArray | Array | Array<[x, y, z]>` – The positions parameter array updated, centered at `[0, 0, 0]` and normalized to a bounding box of `
|
|
44
|
+
- positions: `TypedArray | Array | Array<[x, y, z]>` – The positions parameter array updated, centered at `[0, 0, 0]` and normalized to a bounding box of `normalizedSize` (`[-halfScale, -halfScale, -halfScale] x [halfScale, halfScale, halfScale]`).
|
|
45
45
|
|
|
46
46
|
## License
|
|
47
47
|
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const TEMP_VEC3 = vec3.create();
|
|
|
5
5
|
|
|
6
6
|
function centerAndNormalize(
|
|
7
7
|
positions,
|
|
8
|
-
{ center = true, normalize = true,
|
|
8
|
+
{ center = true, normalize = true, normalizedSize = 1 } = {},
|
|
9
9
|
) {
|
|
10
10
|
const isFlatArray = !positions[0]?.length;
|
|
11
11
|
const positionsCount = positions.length / (isFlatArray ? 3 : 1);
|
|
@@ -15,23 +15,23 @@ function centerAndNormalize(
|
|
|
15
15
|
|
|
16
16
|
if (normalize) {
|
|
17
17
|
const size = aabb.size(bbox);
|
|
18
|
-
|
|
18
|
+
normalizedSize = normalizedSize / (Math.max(...size) || 1);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
for (let i = 0; i < positionsCount; i++) {
|
|
22
22
|
if (isFlatArray) {
|
|
23
23
|
avec3.sub(positions, i, bboxCenter, 0);
|
|
24
24
|
if (normalize) {
|
|
25
|
-
avec3.scale(positions, i,
|
|
26
|
-
if (!center) avec3.add(positions, i, bboxCenter, 0);
|
|
25
|
+
avec3.scale(positions, i, normalizedSize);
|
|
27
26
|
}
|
|
27
|
+
if (!center) avec3.add(positions, i, bboxCenter, 0);
|
|
28
28
|
} else {
|
|
29
29
|
vec3.set(TEMP_VEC3, positions[i]);
|
|
30
30
|
vec3.sub(TEMP_VEC3, bboxCenter);
|
|
31
31
|
if (normalize) {
|
|
32
|
-
vec3.scale(TEMP_VEC3,
|
|
33
|
-
if (!center) vec3.add(TEMP_VEC3, bboxCenter);
|
|
32
|
+
vec3.scale(TEMP_VEC3, normalizedSize);
|
|
34
33
|
}
|
|
34
|
+
if (!center) vec3.add(TEMP_VEC3, bboxCenter);
|
|
35
35
|
vec3.set(positions[i], TEMP_VEC3);
|
|
36
36
|
}
|
|
37
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geom-center-and-normalize",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
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": [
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default centerAndNormalize;
|
|
2
|
-
declare function centerAndNormalize(positions: any, { center, normalize,
|
|
2
|
+
declare function centerAndNormalize(positions: any, { center, normalize, normalizedSize }?: {
|
|
3
3
|
center?: boolean;
|
|
4
4
|
normalize?: boolean;
|
|
5
|
-
|
|
5
|
+
normalizedSize?: number;
|
|
6
6
|
}): any;
|