@nakafa/aksara-contracts 0.27.0 → 0.31.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/README.md +18 -10
- package/dist/math/base.d.ts +49 -0
- package/dist/math/base.js +103 -0
- package/dist/math/plane.d.ts +317 -0
- package/dist/math/plane.js +151 -0
- package/dist/math/space.d.ts +397 -0
- package/dist/math/space.js +129 -0
- package/dist/math/vector.d.ts +3 -0
- package/dist/math/vector.js +74 -0
- package/dist/math/visual.d.ts +984 -0
- package/dist/math/visual.js +15 -0
- package/dist/preview/artifact.d.ts +4 -32
- package/dist/preview/artifact.js +2 -2
- package/dist/preview/spec.d.ts +8 -64
- package/dist/projection/digest.d.ts +4 -74
- package/dist/projection/page.d.ts +1 -50
- package/dist/projection/page.js +9 -38
- package/dist/projection/question.d.ts +16 -184
- package/dist/projection/spec.d.ts +7 -253
- package/dist/projection/spec.js +2 -9
- package/dist/projection/verify.d.ts +4 -74
- package/dist/question/item.d.ts +24 -304
- package/dist/question/item.js +4 -4
- package/dist/question/response.d.ts +9 -97
- package/dist/question/response.js +8 -31
- package/dist/release/policy.d.ts +3 -0
- package/dist/release/policy.js +2 -0
- package/dist/release/rollback/spec.d.ts +36 -288
- package/dist/release/snapshot/data.d.ts +4 -32
- package/dist/release/snapshot/verify.d.ts +4 -60
- package/dist/renderer/compatibility.d.ts +49 -2
- package/dist/renderer/compatibility.js +49 -1
- package/dist/runtime/spec.d.ts +4 -46
- package/dist/runtime/verify.d.ts +0 -28
- package/dist/transport/batch.d.ts +8 -481
- package/dist/transport/batch.js +2 -14
- package/dist/transport/group.d.ts +50 -836
- package/dist/transport/group.js +1 -2
- package/dist/transport/request.d.ts +440 -2356
- package/dist/transport/response.d.ts +44 -436
- package/dist/transport/snapshot.d.ts +8 -64
- package/dist/tryout/content-hash.d.ts +4 -32
- package/dist/tryout/placement.d.ts +12 -96
- package/package.json +9 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
2
|
+
/** Checks a space polygon is planar and has non-zero area. */
|
|
3
|
+
export function hasCoplanarArea(vertices) {
|
|
4
|
+
const offsets = normalizedSpaceOffsets(vertices);
|
|
5
|
+
let strongestNormal;
|
|
6
|
+
let strongestLength = 0;
|
|
7
|
+
const vectors = offsets.slice(1);
|
|
8
|
+
for (const [leftIndex, left] of vectors.entries()) {
|
|
9
|
+
for (const right of vectors.slice(leftIndex + 1)) {
|
|
10
|
+
const candidate = cross(left, right);
|
|
11
|
+
const candidateLength = length(candidate);
|
|
12
|
+
if (candidateLength > strongestLength) {
|
|
13
|
+
strongestLength = candidateLength;
|
|
14
|
+
strongestNormal = candidate;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!(strongestNormal && strongestLength > GEOMETRY_TOLERANCE)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const unitNormal = divide(strongestNormal, strongestLength);
|
|
22
|
+
return offsets.every((offset) => Math.abs(dot(unitNormal, offset)) <=
|
|
23
|
+
GEOMETRY_TOLERANCE * Math.max(1, length(offset)));
|
|
24
|
+
}
|
|
25
|
+
/** Translates before scaling so coplanarity is independent of scene location. */
|
|
26
|
+
function normalizedSpaceOffsets(vertices) {
|
|
27
|
+
const [origin] = vertices;
|
|
28
|
+
let offsets = vertices.map(({ x, y, z }) => ({
|
|
29
|
+
x: x - origin.x,
|
|
30
|
+
y: y - origin.y,
|
|
31
|
+
z: z - origin.z,
|
|
32
|
+
}));
|
|
33
|
+
if (offsets.some(({ x, y, z }) => !(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z)))) {
|
|
34
|
+
let sourceScale = 1;
|
|
35
|
+
for (const { x, y, z } of vertices) {
|
|
36
|
+
sourceScale = Math.max(sourceScale, Math.abs(x), Math.abs(y), Math.abs(z));
|
|
37
|
+
}
|
|
38
|
+
offsets = vertices.map(({ x, y, z }) => ({
|
|
39
|
+
x: x / sourceScale - origin.x / sourceScale,
|
|
40
|
+
y: y / sourceScale - origin.y / sourceScale,
|
|
41
|
+
z: z / sourceScale - origin.z / sourceScale,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
let extent = 0;
|
|
45
|
+
for (const { x, y, z } of offsets) {
|
|
46
|
+
extent = Math.max(extent, Math.abs(x), Math.abs(y), Math.abs(z));
|
|
47
|
+
}
|
|
48
|
+
const divisor = Math.max(extent, Number.MIN_VALUE);
|
|
49
|
+
return offsets.map((offset) => divide(offset, divisor));
|
|
50
|
+
}
|
|
51
|
+
/** Returns the cross product of two space vectors. */
|
|
52
|
+
function cross(left, right) {
|
|
53
|
+
return {
|
|
54
|
+
x: left.y * right.z - left.z * right.y,
|
|
55
|
+
y: left.z * right.x - left.x * right.z,
|
|
56
|
+
z: left.x * right.y - left.y * right.x,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Returns the dot product of two space vectors. */
|
|
60
|
+
function dot(left, right) {
|
|
61
|
+
return left.x * right.x + left.y * right.y + left.z * right.z;
|
|
62
|
+
}
|
|
63
|
+
/** Returns a stable Euclidean vector length. */
|
|
64
|
+
function length(value) {
|
|
65
|
+
return Math.hypot(value.x, value.y, value.z);
|
|
66
|
+
}
|
|
67
|
+
/** Divides one space vector by a positive finite scale. */
|
|
68
|
+
function divide(value, divisor) {
|
|
69
|
+
return {
|
|
70
|
+
x: value.x / divisor,
|
|
71
|
+
y: value.y / divisor,
|
|
72
|
+
z: value.z / divisor,
|
|
73
|
+
};
|
|
74
|
+
}
|