@nakafa/aksara-contracts 0.33.0 → 0.35.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/dist/math/arc-precision.d.ts +7 -0
- package/dist/math/arc-precision.js +82 -0
- package/dist/math/bounds.d.ts +3 -3
- package/dist/math/bounds.js +13 -2
- package/dist/math/collision.d.ts +7 -0
- package/dist/math/collision.js +41 -0
- package/dist/math/coordinate.d.ts +32 -0
- package/dist/math/coordinate.js +61 -0
- package/dist/math/extent.d.ts +30 -0
- package/dist/math/extent.js +63 -54
- package/dist/math/intersection.d.ts +9 -4
- package/dist/math/intersection.js +9 -5
- package/dist/math/plane.d.ts +1 -0
- package/dist/math/plane.js +3 -1
- package/dist/math/precision.d.ts +26 -0
- package/dist/math/precision.js +114 -0
- package/dist/math/proximity.d.ts +12 -0
- package/dist/math/proximity.js +138 -0
- package/dist/math/rational.d.ts +4 -0
- package/dist/math/rational.js +10 -1
- package/dist/math/resolution.d.ts +9 -0
- package/dist/math/resolution.js +110 -0
- package/dist/math/scene.d.ts +10 -0
- package/dist/math/scene.js +115 -0
- package/dist/math/space.d.ts +1 -0
- package/dist/math/space.js +4 -2
- package/dist/math/visual.d.ts +156 -156
- package/dist/text/syntax.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { BigDecimal, Array as EffectArray } from "effect";
|
|
2
|
+
import { infinitePathInterval, } from "#contracts/math/intersection";
|
|
3
|
+
import { decimal, makeRatio } from "#contracts/math/rational";
|
|
4
|
+
const FLOAT32_RESOLUTION = BigDecimal.fromStringUnsafe("0.00000011920928955078125");
|
|
5
|
+
const TWO = BigDecimal.fromBigInt(2n);
|
|
6
|
+
const FOUR = BigDecimal.fromBigInt(4n);
|
|
7
|
+
/** Returns the exact width of one finite authored axis. */
|
|
8
|
+
export function axisSpan(range) {
|
|
9
|
+
return BigDecimal.subtract(decimal(range.max), decimal(range.min));
|
|
10
|
+
}
|
|
11
|
+
/** Checks one exact axis width against the shared render threshold. */
|
|
12
|
+
export function spanUnresolved(range, threshold) {
|
|
13
|
+
return BigDecimal.isLessThan(axisSpan(range), threshold);
|
|
14
|
+
}
|
|
15
|
+
/** Checks one non-zero measurement against the shared render threshold. */
|
|
16
|
+
export function measureUnresolved(value, threshold) {
|
|
17
|
+
return decimalMeasureUnresolved(decimal(value), threshold);
|
|
18
|
+
}
|
|
19
|
+
/** Checks one exact non-zero measurement against the render threshold. */
|
|
20
|
+
function decimalMeasureUnresolved(value, threshold) {
|
|
21
|
+
const measure = BigDecimal.abs(value);
|
|
22
|
+
return (!BigDecimal.isZero(measure) && BigDecimal.isLessThan(measure, threshold));
|
|
23
|
+
}
|
|
24
|
+
/** Resolves 2^-23 of the complete translation-invariant render envelope. */
|
|
25
|
+
export function renderThreshold(ranges, padding, envelopePairs = []) {
|
|
26
|
+
const [firstRange, ...remainingRanges] = ranges;
|
|
27
|
+
let extent = axisSpan(firstRange);
|
|
28
|
+
for (const range of remainingRanges) {
|
|
29
|
+
extent = BigDecimal.max(extent, axisSpan(range));
|
|
30
|
+
}
|
|
31
|
+
for (const [left, right] of envelopePairs) {
|
|
32
|
+
const externalDelta = BigDecimal.abs(BigDecimal.subtract(decimal(left), decimal(right)));
|
|
33
|
+
extent = BigDecimal.max(extent, externalDelta);
|
|
34
|
+
}
|
|
35
|
+
const padded = BigDecimal.sum(extent, BigDecimal.multiply(decimal(padding), TWO));
|
|
36
|
+
return BigDecimal.multiply(padded, FLOAT32_RESOLUTION);
|
|
37
|
+
}
|
|
38
|
+
/** Includes both view coordinates, their separation, and one frame axis. */
|
|
39
|
+
export function axisEnvelopePairs(range, left, right) {
|
|
40
|
+
return [
|
|
41
|
+
[left, right],
|
|
42
|
+
[left, range.min],
|
|
43
|
+
[left, range.max],
|
|
44
|
+
[right, range.min],
|
|
45
|
+
[right, range.max],
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
/** Subtracts two exact path parameters without dividing either ratio. */
|
|
49
|
+
function ratioDifference(left, right) {
|
|
50
|
+
return makeRatio(BigDecimal.subtract(BigDecimal.multiply(left.numerator, right.denominator), BigDecimal.multiply(right.numerator, left.denominator)), BigDecimal.multiply(left.denominator, right.denominator));
|
|
51
|
+
}
|
|
52
|
+
/** Checks that the frame-visible portion of one infinite path remains visible. */
|
|
53
|
+
export function visiblePathResolvable(kind, axes, threshold) {
|
|
54
|
+
const interval = infinitePathInterval(kind, axes);
|
|
55
|
+
if (!(interval?.entry && interval.exit)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const parameterSpan = ratioDifference(interval.exit, interval.entry);
|
|
59
|
+
let hasVisibleExtent = false;
|
|
60
|
+
for (const axis of axes) {
|
|
61
|
+
const direction = BigDecimal.abs(BigDecimal.subtract(decimal(axis.through), decimal(axis.start)));
|
|
62
|
+
const visibleNumerator = BigDecimal.multiply(BigDecimal.abs(parameterSpan.numerator), direction);
|
|
63
|
+
if (BigDecimal.isZero(visibleNumerator)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
hasVisibleExtent = true;
|
|
67
|
+
if (BigDecimal.isLessThan(visibleNumerator, BigDecimal.multiply(threshold, parameterSpan.denominator))) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return hasVisibleExtent;
|
|
72
|
+
}
|
|
73
|
+
/** Checks whether any non-zero polygon altitude collapses in the renderer. */
|
|
74
|
+
export function polygonAltitudeUnresolved(vertices, threshold) {
|
|
75
|
+
const exact = vertices.map((point) => ({
|
|
76
|
+
x: decimal(point.x),
|
|
77
|
+
y: decimal(point.y),
|
|
78
|
+
z: decimal("z" in point ? point.z : 0),
|
|
79
|
+
}));
|
|
80
|
+
const thresholdSquared = BigDecimal.multiply(threshold, threshold);
|
|
81
|
+
for (const [index, point] of exact.entries()) {
|
|
82
|
+
const previous = EffectArray.getUnsafe(exact, (index + exact.length - 1) % exact.length);
|
|
83
|
+
const next = EffectArray.getUnsafe(exact, (index + 1) % exact.length);
|
|
84
|
+
const baseline = {
|
|
85
|
+
x: BigDecimal.subtract(next.x, previous.x),
|
|
86
|
+
y: BigDecimal.subtract(next.y, previous.y),
|
|
87
|
+
z: BigDecimal.subtract(next.z, previous.z),
|
|
88
|
+
};
|
|
89
|
+
const offset = {
|
|
90
|
+
x: BigDecimal.subtract(point.x, previous.x),
|
|
91
|
+
y: BigDecimal.subtract(point.y, previous.y),
|
|
92
|
+
z: BigDecimal.subtract(point.z, previous.z),
|
|
93
|
+
};
|
|
94
|
+
const cross = {
|
|
95
|
+
x: BigDecimal.subtract(BigDecimal.multiply(baseline.y, offset.z), BigDecimal.multiply(baseline.z, offset.y)),
|
|
96
|
+
y: BigDecimal.subtract(BigDecimal.multiply(baseline.z, offset.x), BigDecimal.multiply(baseline.x, offset.z)),
|
|
97
|
+
z: BigDecimal.subtract(BigDecimal.multiply(baseline.x, offset.y), BigDecimal.multiply(baseline.y, offset.x)),
|
|
98
|
+
};
|
|
99
|
+
const crossSquared = BigDecimal.sumAll(Object.values(cross).map((value) => BigDecimal.multiply(value, value)));
|
|
100
|
+
if (BigDecimal.isZero(crossSquared)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const baselineSquared = BigDecimal.sumAll(Object.values(baseline).map((value) => BigDecimal.multiply(value, value)));
|
|
104
|
+
if (BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared))) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/** Checks exact quadratic curvature without relying on renderer sampling. */
|
|
111
|
+
export function quadraticCurvatureUnresolved(coefficient, domainSpan, threshold) {
|
|
112
|
+
const curvature = BigDecimal.multiply(BigDecimal.abs(decimal(coefficient)), BigDecimal.multiply(domainSpan, domainSpan));
|
|
113
|
+
return BigDecimal.isLessThan(curvature, BigDecimal.multiply(threshold, FOUR));
|
|
114
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
import { type ExactRatio } from "#contracts/math/rational";
|
|
3
|
+
/** One exact rational coordinate participating in a proximity comparison. */
|
|
4
|
+
export interface ExactProximityEntry {
|
|
5
|
+
readonly error?: BigDecimal.BigDecimal;
|
|
6
|
+
readonly value: ExactRatio;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Finds later-authored coordinates whose disjoint error intervals prove a
|
|
10
|
+
* distinct gap below one threshold in O(n log n).
|
|
11
|
+
*/
|
|
12
|
+
export declare function unresolvedProximityIndexes(entries: readonly ExactProximityEntry[], threshold: BigDecimal.BigDecimal): Set<number>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { BigDecimal, Array as EffectArray } from "effect";
|
|
2
|
+
import { compareRatios, makeRatio, } from "#contracts/math/rational";
|
|
3
|
+
const ZERO = BigDecimal.fromBigInt(0n);
|
|
4
|
+
/** Translates one rational coordinate by an exact decimal measurement. */
|
|
5
|
+
function translate(value, offset, direction) {
|
|
6
|
+
const scaledOffset = BigDecimal.multiply(offset, value.denominator);
|
|
7
|
+
return makeRatio(direction === -1
|
|
8
|
+
? BigDecimal.subtract(value.numerator, scaledOffset)
|
|
9
|
+
: BigDecimal.sum(value.numerator, scaledOffset), value.denominator);
|
|
10
|
+
}
|
|
11
|
+
/** Returns the first sorted ratio at or after one exact boundary. */
|
|
12
|
+
function firstRank(values, target, afterEqual) {
|
|
13
|
+
let start = 0;
|
|
14
|
+
let end = values.length;
|
|
15
|
+
while (start < end) {
|
|
16
|
+
const middle = Math.floor((start + end) / 2);
|
|
17
|
+
const order = compareRatios(EffectArray.getUnsafe(values, middle), target);
|
|
18
|
+
if (order < 0 || (afterEqual && order === 0)) {
|
|
19
|
+
start = middle + 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
end = middle;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return start;
|
|
26
|
+
}
|
|
27
|
+
/** Assigns a stable exact rank to every source-ordered ratio. */
|
|
28
|
+
function rankRatios(values) {
|
|
29
|
+
const ordered = values
|
|
30
|
+
.map((value, sourceIndex) => ({ sourceIndex, value }))
|
|
31
|
+
.sort((left, right) => compareRatios(left.value, right.value));
|
|
32
|
+
const distinct = [];
|
|
33
|
+
const ranks = new Array(values.length);
|
|
34
|
+
for (const entry of ordered) {
|
|
35
|
+
const previous = distinct.at(-1);
|
|
36
|
+
if (previous && compareRatios(previous, entry.value) === 0) {
|
|
37
|
+
ranks[entry.sourceIndex] = distinct.length - 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
ranks[entry.sourceIndex] = distinct.length;
|
|
41
|
+
distinct.push(entry.value);
|
|
42
|
+
}
|
|
43
|
+
return { ranks, values: distinct };
|
|
44
|
+
}
|
|
45
|
+
/** Builds an empty segment tree over exact ratio ranks. */
|
|
46
|
+
function makeTree(size) {
|
|
47
|
+
let base = 1;
|
|
48
|
+
while (base < size) {
|
|
49
|
+
base *= 2;
|
|
50
|
+
}
|
|
51
|
+
return { base, values: new Array(base * 2) };
|
|
52
|
+
}
|
|
53
|
+
/** Selects the greater defined exact ratio. */
|
|
54
|
+
function greaterRatio(left, right) {
|
|
55
|
+
if (left === undefined) {
|
|
56
|
+
return right;
|
|
57
|
+
}
|
|
58
|
+
if (right === undefined) {
|
|
59
|
+
return left;
|
|
60
|
+
}
|
|
61
|
+
return compareRatios(left, right) < 0 ? right : left;
|
|
62
|
+
}
|
|
63
|
+
/** Selects the lesser defined exact ratio. */
|
|
64
|
+
function lesserRatio(left, right) {
|
|
65
|
+
if (left === undefined) {
|
|
66
|
+
return right;
|
|
67
|
+
}
|
|
68
|
+
if (right === undefined) {
|
|
69
|
+
return left;
|
|
70
|
+
}
|
|
71
|
+
return compareRatios(left, right) > 0 ? right : left;
|
|
72
|
+
}
|
|
73
|
+
/** Inserts one exact ratio at its compressed rank. */
|
|
74
|
+
function updateTree(tree, rank, value, select) {
|
|
75
|
+
const { values } = tree;
|
|
76
|
+
let cursor = tree.base + rank;
|
|
77
|
+
values[cursor] = select(values[cursor], value);
|
|
78
|
+
while (cursor > 1) {
|
|
79
|
+
cursor = Math.floor(cursor / 2);
|
|
80
|
+
values[cursor] = select(EffectArray.getUnsafe(values, cursor * 2), EffectArray.getUnsafe(values, cursor * 2 + 1));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Selects one exact ratio across a half-open compressed-rank interval. */
|
|
84
|
+
function queryTree(tree, start, end, select) {
|
|
85
|
+
let left = start + tree.base;
|
|
86
|
+
let right = end + tree.base;
|
|
87
|
+
let selected;
|
|
88
|
+
while (left < right) {
|
|
89
|
+
if (left % 2 === 1) {
|
|
90
|
+
selected = select(selected, EffectArray.getUnsafe(tree.values, left));
|
|
91
|
+
left += 1;
|
|
92
|
+
}
|
|
93
|
+
if (right % 2 === 1) {
|
|
94
|
+
right -= 1;
|
|
95
|
+
selected = select(selected, EffectArray.getUnsafe(tree.values, right));
|
|
96
|
+
}
|
|
97
|
+
left = Math.floor(left / 2);
|
|
98
|
+
right = Math.floor(right / 2);
|
|
99
|
+
}
|
|
100
|
+
return selected;
|
|
101
|
+
}
|
|
102
|
+
/** Expands one exact estimate into its explicit symmetric error interval. */
|
|
103
|
+
function exactInterval(entry) {
|
|
104
|
+
const error = entry.error ?? ZERO;
|
|
105
|
+
return {
|
|
106
|
+
lower: translate(entry.value, error, -1),
|
|
107
|
+
upper: translate(entry.value, error, 1),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Finds later-authored coordinates whose disjoint error intervals prove a
|
|
112
|
+
* distinct gap below one threshold in O(n log n).
|
|
113
|
+
*/
|
|
114
|
+
export function unresolvedProximityIndexes(entries, threshold) {
|
|
115
|
+
const intervals = entries.map(exactInterval);
|
|
116
|
+
const lower = rankRatios(intervals.map((entry) => entry.lower));
|
|
117
|
+
const upper = rankRatios(intervals.map((entry) => entry.upper));
|
|
118
|
+
const leftTree = makeTree(upper.values.length);
|
|
119
|
+
const rightTree = makeTree(lower.values.length);
|
|
120
|
+
const unresolved = new Set();
|
|
121
|
+
for (const [sourceIndex, interval] of intervals.entries()) {
|
|
122
|
+
const leftEnd = firstRank(upper.values, interval.lower, false);
|
|
123
|
+
const closestLeft = queryTree(leftTree, 0, leftEnd, greaterRatio);
|
|
124
|
+
const rightStart = firstRank(lower.values, interval.upper, true);
|
|
125
|
+
const closestRight = queryTree(rightTree, rightStart, lower.values.length, lesserRatio);
|
|
126
|
+
const leftThreshold = translate(interval.upper, threshold, -1);
|
|
127
|
+
const rightThreshold = translate(interval.lower, threshold, 1);
|
|
128
|
+
if ((closestLeft !== undefined &&
|
|
129
|
+
compareRatios(leftThreshold, closestLeft) < 0) ||
|
|
130
|
+
(closestRight !== undefined &&
|
|
131
|
+
compareRatios(closestRight, rightThreshold) < 0)) {
|
|
132
|
+
unresolved.add(sourceIndex);
|
|
133
|
+
}
|
|
134
|
+
updateTree(leftTree, EffectArray.getUnsafe(upper.ranks, sourceIndex), interval.lower, greaterRatio);
|
|
135
|
+
updateTree(rightTree, EffectArray.getUnsafe(lower.ranks, sourceIndex), interval.upper, lesserRatio);
|
|
136
|
+
}
|
|
137
|
+
return unresolved;
|
|
138
|
+
}
|
package/dist/math/rational.d.ts
CHANGED
|
@@ -6,10 +6,14 @@ export interface ExactRatio {
|
|
|
6
6
|
}
|
|
7
7
|
/** Creates one exact decimal from a schema-validated finite number. */
|
|
8
8
|
export declare function decimal(value: number): BigDecimal.BigDecimal;
|
|
9
|
+
/** Lifts one exact decimal into the shared rational coordinate form. */
|
|
10
|
+
export declare function decimalRatio(value: BigDecimal.BigDecimal): ExactRatio;
|
|
9
11
|
/** Creates one exact ratio from a known non-zero denominator. */
|
|
10
12
|
export declare function makeRatio(numerator: BigDecimal.BigDecimal, denominator: BigDecimal.BigDecimal): ExactRatio;
|
|
11
13
|
/** Creates one exact ratio from a finite number. */
|
|
12
14
|
export declare function numberRatio(value: number): ExactRatio;
|
|
15
|
+
/** Evaluates one affine coordinate without dividing its exact parameter. */
|
|
16
|
+
export declare function affineRatio(start: number, through: number, parameter: ExactRatio): ExactRatio;
|
|
13
17
|
/** Creates the exact path parameter `(boundary - start) / (through - start)`. */
|
|
14
18
|
export declare function differenceRatio(boundary: number, start: number, through: number): ExactRatio;
|
|
15
19
|
/** Compares two exact ratios without division or floating-point overflow. */
|
package/dist/math/rational.js
CHANGED
|
@@ -4,6 +4,10 @@ const unit = BigDecimal.fromBigInt(1n);
|
|
|
4
4
|
export function decimal(value) {
|
|
5
5
|
return BigDecimal.fromNumberUnsafe(value);
|
|
6
6
|
}
|
|
7
|
+
/** Lifts one exact decimal into the shared rational coordinate form. */
|
|
8
|
+
export function decimalRatio(value) {
|
|
9
|
+
return { denominator: unit, numerator: value };
|
|
10
|
+
}
|
|
7
11
|
/** Creates one exact ratio from a known non-zero denominator. */
|
|
8
12
|
export function makeRatio(numerator, denominator) {
|
|
9
13
|
return BigDecimal.isNegative(denominator)
|
|
@@ -15,7 +19,12 @@ export function makeRatio(numerator, denominator) {
|
|
|
15
19
|
}
|
|
16
20
|
/** Creates one exact ratio from a finite number. */
|
|
17
21
|
export function numberRatio(value) {
|
|
18
|
-
return
|
|
22
|
+
return decimalRatio(decimal(value));
|
|
23
|
+
}
|
|
24
|
+
/** Evaluates one affine coordinate without dividing its exact parameter. */
|
|
25
|
+
export function affineRatio(start, through, parameter) {
|
|
26
|
+
const origin = decimal(start);
|
|
27
|
+
return makeRatio(BigDecimal.sum(BigDecimal.multiply(origin, parameter.denominator), BigDecimal.multiply(BigDecimal.subtract(decimal(through), origin), parameter.numerator)), parameter.denominator);
|
|
19
28
|
}
|
|
20
29
|
/** Creates the exact path parameter `(boundary - start) / (through - start)`. */
|
|
21
30
|
export function differenceRatio(boundary, start, through) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Schema } from "effect";
|
|
2
|
+
import type { PlaneLabelAnchor, PlaneMathFrame, PlaneMathObject, PlaneMathView } from "#contracts/math/plane";
|
|
3
|
+
import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject, SpaceMathView } from "#contracts/math/space";
|
|
4
|
+
/** One stable authoring failure for geometry below renderer resolution. */
|
|
5
|
+
export declare const MATH_VISUAL_RESOLUTION_MESSAGE = "Expected every non-zero mathematical visual delta to be at least 2^-23 of its combined render envelope.";
|
|
6
|
+
/** Reports every plane delta that a normalized renderer cannot preserve. */
|
|
7
|
+
export declare function planeResolutionIssues(frame: PlaneMathFrame, objects: readonly PlaneMathObject[], labels: readonly PlaneLabelAnchor[], view: PlaneMathView): readonly Schema.FilterIssue[];
|
|
8
|
+
/** Reports every space delta that a normalized renderer cannot preserve. */
|
|
9
|
+
export declare function spaceResolutionIssues(frame: SpaceMathFrame, objects: readonly SpaceMathObject[], labels: readonly SpaceLabelAnchor[], view: SpaceMathView): readonly Schema.FilterIssue[];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { arcCurvatureUnresolved, arcEndpointAxesUnresolved, arcEndpointsUnresolved, } from "#contracts/math/arc-precision";
|
|
2
|
+
import { concentricRadiusCollisionPaths, coordinateCollisionPaths, } from "#contracts/math/collision";
|
|
3
|
+
import { pathAxes } from "#contracts/math/coordinate";
|
|
4
|
+
import { axisEnvelopePairs, axisSpan, measureUnresolved, polygonAltitudeUnresolved, quadraticCurvatureUnresolved, renderThreshold, spanUnresolved, visiblePathResolvable, } from "#contracts/math/precision";
|
|
5
|
+
import { planeSceneCoordinates, spaceSceneCoordinates, } from "#contracts/math/scene";
|
|
6
|
+
/** One stable authoring failure for geometry below renderer resolution. */
|
|
7
|
+
export const MATH_VISUAL_RESOLUTION_MESSAGE = "Expected every non-zero mathematical visual delta to be at least 2^-23 of its combined render envelope.";
|
|
8
|
+
/** Places the shared resolution failure at one authored schema path. */
|
|
9
|
+
function issue(path) {
|
|
10
|
+
return { issue: MATH_VISUAL_RESOLUTION_MESSAGE, path };
|
|
11
|
+
}
|
|
12
|
+
/** Removes repeated issue paths while preserving first-cause order. */
|
|
13
|
+
function uniqueIssues(issues) {
|
|
14
|
+
return [
|
|
15
|
+
...new Map(issues.map((candidate) => [JSON.stringify(candidate.path), candidate])).values(),
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
/** Reports one non-zero authored measure below the scene threshold. */
|
|
19
|
+
function measureIssue(value, threshold, path) {
|
|
20
|
+
return measureUnresolved(value, threshold) ? [issue(path)] : [];
|
|
21
|
+
}
|
|
22
|
+
/** Checks polygon altitude and infinite-path visible extent. */
|
|
23
|
+
function objectResolutionIssues(frame, object, index, threshold) {
|
|
24
|
+
const root = ["objects", index];
|
|
25
|
+
if (object.kind === "polygon") {
|
|
26
|
+
return polygonAltitudeUnresolved(object.vertices, threshold)
|
|
27
|
+
? [issue(root)]
|
|
28
|
+
: [];
|
|
29
|
+
}
|
|
30
|
+
if (object.kind !== "line" && object.kind !== "ray") {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const [from, through] = object.kind === "line" ? object.through : [object.from, object.through];
|
|
34
|
+
return visiblePathResolvable(object.kind, pathAxes(frame, from, through), threshold)
|
|
35
|
+
? []
|
|
36
|
+
: [issue(root)];
|
|
37
|
+
}
|
|
38
|
+
/** Applies plane-specific measure and exact curve-resolution checks. */
|
|
39
|
+
function planeObjectIssues(frame, object, index, threshold) {
|
|
40
|
+
const root = ["objects", index];
|
|
41
|
+
if (object.kind === "circle") {
|
|
42
|
+
return measureIssue(object.radius, threshold, [...root, "radius"]);
|
|
43
|
+
}
|
|
44
|
+
if (object.kind === "arc") {
|
|
45
|
+
const radiusIssues = measureIssue(object.radius, threshold, [
|
|
46
|
+
...root,
|
|
47
|
+
"radius",
|
|
48
|
+
]);
|
|
49
|
+
const shapeUnresolved = arcEndpointsUnresolved(object.radius, object.sweepDegrees, threshold) ||
|
|
50
|
+
arcCurvatureUnresolved(object.radius, object.sweepDegrees, threshold);
|
|
51
|
+
if (shapeUnresolved) {
|
|
52
|
+
return [...radiusIssues, issue([...root, "sweepDegrees"])];
|
|
53
|
+
}
|
|
54
|
+
return arcEndpointAxesUnresolved(object.radius, object.startDegrees, object.sweepDegrees, threshold)
|
|
55
|
+
? [...radiusIssues, issue(root)]
|
|
56
|
+
: radiusIssues;
|
|
57
|
+
}
|
|
58
|
+
if (object.kind === "quadratic") {
|
|
59
|
+
const domainSpan = axisSpan(object.domain);
|
|
60
|
+
const domainIssues = spanUnresolved(object.domain, threshold)
|
|
61
|
+
? [issue([...root, "domain"])]
|
|
62
|
+
: [];
|
|
63
|
+
return quadraticCurvatureUnresolved(object.coefficients.a, domainSpan, threshold)
|
|
64
|
+
? [...domainIssues, issue([...root, "coefficients", "a"])]
|
|
65
|
+
: domainIssues;
|
|
66
|
+
}
|
|
67
|
+
return objectResolutionIssues(frame, object, index, threshold);
|
|
68
|
+
}
|
|
69
|
+
/** Reports every frame axis whose non-zero span collapses in the envelope. */
|
|
70
|
+
function frameIssues(entries, threshold) {
|
|
71
|
+
return entries.flatMap(({ axis, range }) => spanUnresolved(range, threshold) ? [issue(["frame", axis])] : []);
|
|
72
|
+
}
|
|
73
|
+
/** Reports every plane delta that a normalized renderer cannot preserve. */
|
|
74
|
+
export function planeResolutionIssues(frame, objects, labels, view) {
|
|
75
|
+
const threshold = renderThreshold([frame.x, frame.y], view.padding ?? 0);
|
|
76
|
+
return uniqueIssues([
|
|
77
|
+
...frameIssues([
|
|
78
|
+
{ axis: "x", range: frame.x },
|
|
79
|
+
{ axis: "y", range: frame.y },
|
|
80
|
+
], threshold),
|
|
81
|
+
...measureIssue(view.padding ?? 0, threshold, ["view", "padding"]),
|
|
82
|
+
...coordinateCollisionPaths(planeSceneCoordinates(frame, objects, labels, threshold), threshold).map(issue),
|
|
83
|
+
...concentricRadiusCollisionPaths(objects, threshold).map(issue),
|
|
84
|
+
...objects.flatMap((object, index) => planeObjectIssues(frame, object, index, threshold)),
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
/** Reports every space delta that a normalized renderer cannot preserve. */
|
|
88
|
+
export function spaceResolutionIssues(frame, objects, labels, view) {
|
|
89
|
+
const envelopePairs = view.kind === "camera"
|
|
90
|
+
? [
|
|
91
|
+
...axisEnvelopePairs(frame.x, view.position.x, view.target.x),
|
|
92
|
+
...axisEnvelopePairs(frame.y, view.position.y, view.target.y),
|
|
93
|
+
...axisEnvelopePairs(frame.z, view.position.z, view.target.z),
|
|
94
|
+
]
|
|
95
|
+
: [];
|
|
96
|
+
const threshold = renderThreshold([frame.x, frame.y, frame.z], view.kind === "fit" ? (view.padding ?? 0) : 0, envelopePairs);
|
|
97
|
+
return uniqueIssues([
|
|
98
|
+
...frameIssues([
|
|
99
|
+
{ axis: "x", range: frame.x },
|
|
100
|
+
{ axis: "y", range: frame.y },
|
|
101
|
+
{ axis: "z", range: frame.z },
|
|
102
|
+
], threshold),
|
|
103
|
+
...measureIssue(view.kind === "fit" ? (view.padding ?? 0) : 0, threshold, [
|
|
104
|
+
"view",
|
|
105
|
+
"padding",
|
|
106
|
+
]),
|
|
107
|
+
...coordinateCollisionPaths(spaceSceneCoordinates(frame, objects, labels, view, threshold), threshold).map(issue),
|
|
108
|
+
...objects.flatMap((object, index) => objectResolutionIssues(frame, object, index, threshold)),
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type SceneCoordinate, type ScenePath } from "#contracts/math/coordinate";
|
|
2
|
+
import type { PlaneLabelAnchor, PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
|
|
3
|
+
import { type RenderThreshold } from "#contracts/math/precision";
|
|
4
|
+
import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject, SpaceMathView } from "#contracts/math/space";
|
|
5
|
+
/** Owns one stable path for radial geometry-resolution failures. */
|
|
6
|
+
export declare function radialGeometryPath(kind: "arc" | "circle", index: number): ScenePath;
|
|
7
|
+
/** Projects one plane scene into a single ordered exact coordinate stream. */
|
|
8
|
+
export declare function planeSceneCoordinates(frame: PlaneMathFrame, objects: readonly PlaneMathObject[], labels: readonly PlaneLabelAnchor[], threshold: RenderThreshold): SceneCoordinate[];
|
|
9
|
+
/** Projects one space scene into a single ordered exact coordinate stream. */
|
|
10
|
+
export declare function spaceSceneCoordinates(frame: SpaceMathFrame, objects: readonly SpaceMathObject[], labels: readonly SpaceLabelAnchor[], view: SpaceMathView, threshold: RenderThreshold): SceneCoordinate[];
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
import { arcCurvatureUnresolved, arcEndpointsUnresolved, } from "#contracts/math/arc-precision";
|
|
3
|
+
import { clippedPathCoordinates, sceneCoordinate as coordinate, frameCoordinates, pointCoordinates, } from "#contracts/math/coordinate";
|
|
4
|
+
import { cuboidExtents, quadraticExtrema, radialOffsets, } from "#contracts/math/extent";
|
|
5
|
+
import { axisSpan, measureUnresolved, quadraticCurvatureUnresolved, spanUnresolved, } from "#contracts/math/precision";
|
|
6
|
+
import { decimal, decimalRatio } from "#contracts/math/rational";
|
|
7
|
+
/** Projects exact cardinal extrema from one circle or directed arc. */
|
|
8
|
+
function radialCoordinates(object, path, threshold) {
|
|
9
|
+
if (measureUnresolved(object.radius, threshold)) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
if (object.kind === "arc" &&
|
|
13
|
+
(arcEndpointsUnresolved(object.radius, object.sweepDegrees, threshold) ||
|
|
14
|
+
arcCurvatureUnresolved(object.radius, object.sweepDegrees, threshold))) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return radialOffsets(object).flatMap((offset) => [
|
|
18
|
+
coordinate("x", path, decimalRatio(BigDecimal.sum(decimal(object.center.x), offset.x)), true, offset.error),
|
|
19
|
+
coordinate("y", path, decimalRatio(BigDecimal.sum(decimal(object.center.y), offset.y)), true, offset.error),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
/** Owns one stable path for radial geometry-resolution failures. */
|
|
23
|
+
export function radialGeometryPath(kind, index) {
|
|
24
|
+
return kind === "arc" ? ["objects", index] : ["objects", index, "radius"];
|
|
25
|
+
}
|
|
26
|
+
/** Projects the exact endpoints and in-domain vertex of one quadratic. */
|
|
27
|
+
function quadraticCoordinates(object, path, threshold) {
|
|
28
|
+
const domainSpan = axisSpan(object.domain);
|
|
29
|
+
if (spanUnresolved(object.domain, threshold) ||
|
|
30
|
+
quadraticCurvatureUnresolved(object.coefficients.a, domainSpan, threshold)) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const { inputAxis } = object;
|
|
34
|
+
const outputAxis = inputAxis === "x" ? "y" : "x";
|
|
35
|
+
return quadraticExtrema(object).flatMap(({ input, output }) => [
|
|
36
|
+
coordinate(inputAxis, path, input),
|
|
37
|
+
coordinate(outputAxis, path, output),
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
/** Projects the center and exact face coordinates of one cuboid. */
|
|
41
|
+
function cuboidCoordinates(object, path) {
|
|
42
|
+
return [
|
|
43
|
+
...pointCoordinates(object.center, [...path, "center"]),
|
|
44
|
+
...cuboidExtents(object).flatMap(({ axis, center, dimension, extent }) => [
|
|
45
|
+
coordinate(axis, [...path, "size", dimension], decimalRatio(BigDecimal.subtract(decimal(center), extent))),
|
|
46
|
+
coordinate(axis, [...path, "size", dimension], decimalRatio(BigDecimal.sum(decimal(center), extent))),
|
|
47
|
+
]),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
/** Projects every finite or frame-clipped coordinate of one scene object. */
|
|
51
|
+
function objectCoordinates(frame, object, index, threshold) {
|
|
52
|
+
const root = ["objects", index];
|
|
53
|
+
if (object.kind === "point") {
|
|
54
|
+
return pointCoordinates(object.at, [...root, "at"]);
|
|
55
|
+
}
|
|
56
|
+
if (object.kind === "line") {
|
|
57
|
+
const [from, through] = object.through;
|
|
58
|
+
return clippedPathCoordinates(frame, "line", from, through, root, threshold);
|
|
59
|
+
}
|
|
60
|
+
if (object.kind === "ray") {
|
|
61
|
+
return clippedPathCoordinates(frame, "ray", object.from, object.through, root, threshold);
|
|
62
|
+
}
|
|
63
|
+
if (object.kind === "segment") {
|
|
64
|
+
return [
|
|
65
|
+
...pointCoordinates(object.from, [...root, "from"]),
|
|
66
|
+
...pointCoordinates(object.to, [...root, "to"]),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
if (object.kind === "polyline" || object.kind === "polygon") {
|
|
70
|
+
return object.vertices.flatMap((point, pointIndex) => pointCoordinates(point, [...root, "vertices", pointIndex]));
|
|
71
|
+
}
|
|
72
|
+
if (object.kind === "circle" || object.kind === "arc") {
|
|
73
|
+
return [
|
|
74
|
+
...pointCoordinates(object.center, [...root, "center"]),
|
|
75
|
+
...radialCoordinates(object, radialGeometryPath(object.kind, index), threshold),
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
if (object.kind === "quadratic") {
|
|
79
|
+
return quadraticCoordinates(object, root, threshold);
|
|
80
|
+
}
|
|
81
|
+
return cuboidCoordinates(object, root);
|
|
82
|
+
}
|
|
83
|
+
/** Projects all label anchors after the objects they annotate. */
|
|
84
|
+
function labelCoordinates(labels) {
|
|
85
|
+
return labels.flatMap((label, index) => pointCoordinates(label.at, ["labels", index, "at"]));
|
|
86
|
+
}
|
|
87
|
+
/** Projects semantic camera or isometric coordinates before space objects. */
|
|
88
|
+
function viewCoordinates(view) {
|
|
89
|
+
if (view.kind === "camera") {
|
|
90
|
+
return [
|
|
91
|
+
...pointCoordinates(view.position, ["view", "position"]),
|
|
92
|
+
...pointCoordinates(view.target, ["view", "target"]),
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
return view.kind === "isometric" && view.target
|
|
96
|
+
? pointCoordinates(view.target, ["view", "target"])
|
|
97
|
+
: [];
|
|
98
|
+
}
|
|
99
|
+
/** Projects one plane scene into a single ordered exact coordinate stream. */
|
|
100
|
+
export function planeSceneCoordinates(frame, objects, labels, threshold) {
|
|
101
|
+
return [
|
|
102
|
+
...frameCoordinates(frame),
|
|
103
|
+
...objects.flatMap((object, index) => objectCoordinates(frame, object, index, threshold)),
|
|
104
|
+
...labelCoordinates(labels),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
/** Projects one space scene into a single ordered exact coordinate stream. */
|
|
108
|
+
export function spaceSceneCoordinates(frame, objects, labels, view, threshold) {
|
|
109
|
+
return [
|
|
110
|
+
...frameCoordinates(frame),
|
|
111
|
+
...viewCoordinates(view),
|
|
112
|
+
...objects.flatMap((object, index) => objectCoordinates(frame, object, index, threshold)),
|
|
113
|
+
...labelCoordinates(labels),
|
|
114
|
+
];
|
|
115
|
+
}
|
package/dist/math/space.d.ts
CHANGED
|
@@ -147,6 +147,7 @@ export declare const SpaceMathViewSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
147
147
|
readonly z: Schema.Finite;
|
|
148
148
|
}>>;
|
|
149
149
|
}>]>;
|
|
150
|
+
export type SpaceMathView = typeof SpaceMathViewSchema.Type;
|
|
150
151
|
/** One coordinate anchor resolved against a separate rich-label map. */
|
|
151
152
|
export declare const SpaceLabelAnchorSchema: Schema.Struct<{
|
|
152
153
|
readonly at: Schema.Struct<{
|
package/dist/math/space.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathFeatureVisibilitySchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PositiveMeasureSchema, SpacePointSchema, sameSpacePoint, } from "#contracts/math/base";
|
|
3
3
|
import { spaceBoundsIssues } from "#contracts/math/bounds";
|
|
4
|
+
import { spaceResolutionIssues } from "#contracts/math/resolution";
|
|
4
5
|
import { hasCoplanarArea } from "#contracts/math/vector";
|
|
5
6
|
const ObjectFields = {
|
|
6
7
|
appearance: MathAppearanceSchema,
|
|
@@ -113,7 +114,8 @@ export const SpaceMathVisualSchema = Schema.Struct({
|
|
|
113
114
|
objects: Schema.NonEmptyArray(SpaceMathObjectSchema),
|
|
114
115
|
space: Schema.Literal("space"),
|
|
115
116
|
view: SpaceMathViewSchema,
|
|
116
|
-
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects }) => [
|
|
117
|
+
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, view }) => [
|
|
117
118
|
...mathVisualIdentityIssues(objects, labels),
|
|
118
|
-
...spaceBoundsIssues(frame, objects, labels),
|
|
119
|
+
...spaceBoundsIssues(frame, objects, labels, view),
|
|
120
|
+
...spaceResolutionIssues(frame, objects, labels, view),
|
|
119
121
|
])));
|