@skenora/geometry 0.1.2
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/README.md +19 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/shapes.d.ts +12 -0
- package/dist/shapes.d.ts.map +1 -0
- package/dist/shapes.js +55 -0
- package/dist/shapes.js.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @skenora/geometry
|
|
2
|
+
|
|
3
|
+
Small renderer-independent geometry helpers used by Skenora shape authoring.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add @skenora/geometry
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Exports include rectangle and circle point generation, polyline closing, and
|
|
10
|
+
2D shape-bound calculation:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { calculateShapeBounds, rectanglePoints } from "@skenora/geometry";
|
|
14
|
+
|
|
15
|
+
const points = rectanglePoints(4, 2);
|
|
16
|
+
const bounds = calculateShapeBounds(points);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The package has no DOM or Babylon.js dependency.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/dist/shapes.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Vector3Value } from "@skenora/contracts";
|
|
2
|
+
export interface ShapeBounds {
|
|
3
|
+
min: Vector3Value;
|
|
4
|
+
max: Vector3Value;
|
|
5
|
+
center: Vector3Value;
|
|
6
|
+
size: Vector3Value;
|
|
7
|
+
}
|
|
8
|
+
export declare function rectanglePoints(width: number, height: number): readonly Vector3Value[];
|
|
9
|
+
export declare function circlePoints(radius: number, segments?: number): readonly Vector3Value[];
|
|
10
|
+
export declare function closePolyline(points: readonly Vector3Value[]): readonly Vector3Value[];
|
|
11
|
+
export declare function calculateShapeBounds(points: readonly Vector3Value[]): ShapeBounds | null;
|
|
12
|
+
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["../src/shapes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,YAAY,CAAC;IAClB,GAAG,EAAE,YAAY,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,SAAS,YAAY,EAAE,CASzB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,SAAK,GACZ,SAAS,YAAY,EAAE,CAUzB;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,YAAY,EAAE,GAC9B,SAAS,YAAY,EAAE,CAOzB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,YAAY,EAAE,GAC9B,WAAW,GAAG,IAAI,CAsBpB"}
|
package/dist/shapes.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export function rectanglePoints(width, height) {
|
|
2
|
+
const halfWidth = Math.abs(width) / 2;
|
|
3
|
+
const halfHeight = Math.abs(height) / 2;
|
|
4
|
+
return [
|
|
5
|
+
{ x: -halfWidth, y: 0, z: -halfHeight },
|
|
6
|
+
{ x: halfWidth, y: 0, z: -halfHeight },
|
|
7
|
+
{ x: halfWidth, y: 0, z: halfHeight },
|
|
8
|
+
{ x: -halfWidth, y: 0, z: halfHeight },
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
export function circlePoints(radius, segments = 48) {
|
|
12
|
+
const count = Math.max(3, Math.round(segments));
|
|
13
|
+
return Array.from({ length: count }, (_, index) => {
|
|
14
|
+
const angle = (index / count) * Math.PI * 2;
|
|
15
|
+
return {
|
|
16
|
+
x: Math.cos(angle) * Math.abs(radius),
|
|
17
|
+
y: 0,
|
|
18
|
+
z: Math.sin(angle) * Math.abs(radius),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function closePolyline(points) {
|
|
23
|
+
const first = points[0];
|
|
24
|
+
const last = points.at(-1);
|
|
25
|
+
if (!first || !last)
|
|
26
|
+
return points;
|
|
27
|
+
if (first.x === last.x && first.y === last.y && first.z === last.z)
|
|
28
|
+
return points;
|
|
29
|
+
return [...points, first];
|
|
30
|
+
}
|
|
31
|
+
export function calculateShapeBounds(points) {
|
|
32
|
+
if (points.length === 0)
|
|
33
|
+
return null;
|
|
34
|
+
const min = { x: Infinity, y: Infinity, z: Infinity };
|
|
35
|
+
const max = { x: -Infinity, y: -Infinity, z: -Infinity };
|
|
36
|
+
for (const point of points) {
|
|
37
|
+
min.x = Math.min(min.x, point.x);
|
|
38
|
+
min.y = Math.min(min.y, point.y);
|
|
39
|
+
min.z = Math.min(min.z, point.z);
|
|
40
|
+
max.x = Math.max(max.x, point.x);
|
|
41
|
+
max.y = Math.max(max.y, point.y);
|
|
42
|
+
max.z = Math.max(max.z, point.z);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
min,
|
|
46
|
+
max,
|
|
47
|
+
center: {
|
|
48
|
+
x: (min.x + max.x) / 2,
|
|
49
|
+
y: (min.y + max.y) / 2,
|
|
50
|
+
z: (min.z + max.z) / 2,
|
|
51
|
+
},
|
|
52
|
+
size: { x: max.x - min.x, y: max.y - min.y, z: max.z - min.z },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=shapes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../src/shapes.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,eAAe,CAC7B,KAAa,EACb,MAAc;IAEd,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO;QACL,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE;QACvC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE;QACtC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE;QACrC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE;KACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,QAAQ,GAAG,EAAE;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QAChD,MAAM,KAAK,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAC5C,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK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CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO;QACL,GAAG;QACH,GAAG;QACH,MAAM,EAAE;YACN,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACtB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACtB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;SACvB;QACD,IAAI,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE;KAC/D,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@skenora/geometry",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Renderer-independent shape geometry helpers for Skenora.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@skenora/contracts": "0.1.2"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json && node ../../scripts/prepare-package-output.mjs dist",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts"
|
|
30
|
+
}
|