@nakafa/aksara-contracts 0.32.0 → 0.34.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 +7 -0
- package/dist/math/bounds.js +131 -0
- 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 +51 -0
- package/dist/math/extent.js +143 -0
- package/dist/math/intersection.d.ts +19 -0
- package/dist/math/intersection.js +41 -0
- package/dist/math/plane.d.ts +32 -68
- package/dist/math/plane.js +21 -15
- 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 +22 -0
- package/dist/math/rational.js +42 -0
- 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 +4 -84
- package/dist/math/space.js +7 -15
- package/dist/math/visual.d.ts +41 -227
- package/package.json +1 -1
package/dist/math/plane.d.ts
CHANGED
|
@@ -20,23 +20,6 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
20
20
|
}>;
|
|
21
21
|
readonly kind: Schema.Literal<"circle">;
|
|
22
22
|
readonly radius: Schema.Finite;
|
|
23
|
-
}>, Schema.Struct<{
|
|
24
|
-
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
25
|
-
readonly id: Schema.String;
|
|
26
|
-
readonly kind: Schema.Literal<"closed-spline">;
|
|
27
|
-
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
28
|
-
readonly x: Schema.Finite;
|
|
29
|
-
readonly y: Schema.Finite;
|
|
30
|
-
}>, Schema.Struct<{
|
|
31
|
-
readonly x: Schema.Finite;
|
|
32
|
-
readonly y: Schema.Finite;
|
|
33
|
-
}>, Schema.Struct<{
|
|
34
|
-
readonly x: Schema.Finite;
|
|
35
|
-
readonly y: Schema.Finite;
|
|
36
|
-
}>]>, readonly [Schema.Struct<{
|
|
37
|
-
readonly x: Schema.Finite;
|
|
38
|
-
readonly y: Schema.Finite;
|
|
39
|
-
}>]>;
|
|
40
23
|
}>, Schema.Struct<{
|
|
41
24
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
42
25
|
readonly id: Schema.String;
|
|
@@ -87,6 +70,20 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
87
70
|
readonly x: Schema.Finite;
|
|
88
71
|
readonly y: Schema.Finite;
|
|
89
72
|
}>]>;
|
|
73
|
+
}>, Schema.Struct<{
|
|
74
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
75
|
+
readonly id: Schema.String;
|
|
76
|
+
readonly coefficients: Schema.Struct<{
|
|
77
|
+
readonly a: Schema.Finite;
|
|
78
|
+
readonly b: Schema.Finite;
|
|
79
|
+
readonly c: Schema.Finite;
|
|
80
|
+
}>;
|
|
81
|
+
readonly domain: Schema.Struct<{
|
|
82
|
+
readonly max: Schema.Finite;
|
|
83
|
+
readonly min: Schema.Finite;
|
|
84
|
+
}>;
|
|
85
|
+
readonly inputAxis: Schema.Literals<readonly ["x", "y"]>;
|
|
86
|
+
readonly kind: Schema.Literal<"quadratic">;
|
|
90
87
|
}>, Schema.Struct<{
|
|
91
88
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
92
89
|
readonly id: Schema.String;
|
|
@@ -111,24 +108,8 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
111
108
|
readonly x: Schema.Finite;
|
|
112
109
|
readonly y: Schema.Finite;
|
|
113
110
|
}>;
|
|
114
|
-
}>, Schema.Struct<{
|
|
115
|
-
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
116
|
-
readonly id: Schema.String;
|
|
117
|
-
readonly kind: Schema.Literal<"spline">;
|
|
118
|
-
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
119
|
-
readonly x: Schema.Finite;
|
|
120
|
-
readonly y: Schema.Finite;
|
|
121
|
-
}>, Schema.Struct<{
|
|
122
|
-
readonly x: Schema.Finite;
|
|
123
|
-
readonly y: Schema.Finite;
|
|
124
|
-
}>, Schema.Struct<{
|
|
125
|
-
readonly x: Schema.Finite;
|
|
126
|
-
readonly y: Schema.Finite;
|
|
127
|
-
}>]>, readonly [Schema.Struct<{
|
|
128
|
-
readonly x: Schema.Finite;
|
|
129
|
-
readonly y: Schema.Finite;
|
|
130
|
-
}>]>;
|
|
131
111
|
}>]>;
|
|
112
|
+
export type PlaneMathObject = typeof PlaneMathObjectSchema.Type;
|
|
132
113
|
/** Exact Cartesian frame presented behind a plane construction. */
|
|
133
114
|
export declare const PlaneMathFrameSchema: Schema.Struct<{
|
|
134
115
|
readonly axes: Schema.Literals<readonly ["hidden", "visible"]>;
|
|
@@ -143,11 +124,13 @@ export declare const PlaneMathFrameSchema: Schema.Struct<{
|
|
|
143
124
|
readonly min: Schema.Finite;
|
|
144
125
|
}>;
|
|
145
126
|
}>;
|
|
127
|
+
export type PlaneMathFrame = typeof PlaneMathFrameSchema.Type;
|
|
146
128
|
/** Plane visuals use semantic fit instead of renderer camera parameters. */
|
|
147
129
|
export declare const PlaneMathViewSchema: Schema.Struct<{
|
|
148
130
|
readonly kind: Schema.Literal<"fit">;
|
|
149
131
|
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
150
132
|
}>;
|
|
133
|
+
export type PlaneMathView = typeof PlaneMathViewSchema.Type;
|
|
151
134
|
/** One coordinate anchor resolved against a separate rich-label map. */
|
|
152
135
|
export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
153
136
|
readonly at: Schema.Struct<{
|
|
@@ -157,6 +140,7 @@ export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
|
157
140
|
readonly key: Schema.String;
|
|
158
141
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
159
142
|
}>;
|
|
143
|
+
export type PlaneLabelAnchor = typeof PlaneLabelAnchorSchema.Type;
|
|
160
144
|
/** Complete stable plane visual before rich labels are attached. */
|
|
161
145
|
export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
162
146
|
readonly frame: Schema.Struct<{
|
|
@@ -200,23 +184,6 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
200
184
|
}>;
|
|
201
185
|
readonly kind: Schema.Literal<"circle">;
|
|
202
186
|
readonly radius: Schema.Finite;
|
|
203
|
-
}>, Schema.Struct<{
|
|
204
|
-
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
205
|
-
readonly id: Schema.String;
|
|
206
|
-
readonly kind: Schema.Literal<"closed-spline">;
|
|
207
|
-
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
208
|
-
readonly x: Schema.Finite;
|
|
209
|
-
readonly y: Schema.Finite;
|
|
210
|
-
}>, Schema.Struct<{
|
|
211
|
-
readonly x: Schema.Finite;
|
|
212
|
-
readonly y: Schema.Finite;
|
|
213
|
-
}>, Schema.Struct<{
|
|
214
|
-
readonly x: Schema.Finite;
|
|
215
|
-
readonly y: Schema.Finite;
|
|
216
|
-
}>]>, readonly [Schema.Struct<{
|
|
217
|
-
readonly x: Schema.Finite;
|
|
218
|
-
readonly y: Schema.Finite;
|
|
219
|
-
}>]>;
|
|
220
187
|
}>, Schema.Struct<{
|
|
221
188
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
222
189
|
readonly id: Schema.String;
|
|
@@ -267,6 +234,20 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
267
234
|
readonly x: Schema.Finite;
|
|
268
235
|
readonly y: Schema.Finite;
|
|
269
236
|
}>]>;
|
|
237
|
+
}>, Schema.Struct<{
|
|
238
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
239
|
+
readonly id: Schema.String;
|
|
240
|
+
readonly coefficients: Schema.Struct<{
|
|
241
|
+
readonly a: Schema.Finite;
|
|
242
|
+
readonly b: Schema.Finite;
|
|
243
|
+
readonly c: Schema.Finite;
|
|
244
|
+
}>;
|
|
245
|
+
readonly domain: Schema.Struct<{
|
|
246
|
+
readonly max: Schema.Finite;
|
|
247
|
+
readonly min: Schema.Finite;
|
|
248
|
+
}>;
|
|
249
|
+
readonly inputAxis: Schema.Literals<readonly ["x", "y"]>;
|
|
250
|
+
readonly kind: Schema.Literal<"quadratic">;
|
|
270
251
|
}>, Schema.Struct<{
|
|
271
252
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
272
253
|
readonly id: Schema.String;
|
|
@@ -291,23 +272,6 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
291
272
|
readonly x: Schema.Finite;
|
|
292
273
|
readonly y: Schema.Finite;
|
|
293
274
|
}>;
|
|
294
|
-
}>, Schema.Struct<{
|
|
295
|
-
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
296
|
-
readonly id: Schema.String;
|
|
297
|
-
readonly kind: Schema.Literal<"spline">;
|
|
298
|
-
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
299
|
-
readonly x: Schema.Finite;
|
|
300
|
-
readonly y: Schema.Finite;
|
|
301
|
-
}>, Schema.Struct<{
|
|
302
|
-
readonly x: Schema.Finite;
|
|
303
|
-
readonly y: Schema.Finite;
|
|
304
|
-
}>, Schema.Struct<{
|
|
305
|
-
readonly x: Schema.Finite;
|
|
306
|
-
readonly y: Schema.Finite;
|
|
307
|
-
}>]>, readonly [Schema.Struct<{
|
|
308
|
-
readonly x: Schema.Finite;
|
|
309
|
-
readonly y: Schema.Finite;
|
|
310
|
-
}>]>;
|
|
311
275
|
}>]>>;
|
|
312
276
|
readonly space: Schema.Literal<"plane">;
|
|
313
277
|
readonly view: Schema.Struct<{
|
package/dist/math/plane.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathFeatureVisibilitySchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
|
|
3
|
+
import { planeBoundsIssues } from "#contracts/math/bounds";
|
|
4
|
+
import { planeResolutionIssues } from "#contracts/math/resolution";
|
|
3
5
|
const ObjectFields = {
|
|
4
6
|
appearance: MathAppearanceSchema,
|
|
5
7
|
id: MathVisualKeySchema,
|
|
@@ -83,18 +85,6 @@ const PlanePolygonObjectSchema = Schema.Struct({
|
|
|
83
85
|
kind: Schema.Literal("polygon"),
|
|
84
86
|
vertices: PlaneShapeSchema,
|
|
85
87
|
}).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, samePlanePoint) && hasPlaneArea(vertices), { message: "Expected unique vertices forming a non-degenerate polygon." })));
|
|
86
|
-
const PlaneSplineObjectSchema = Schema.Struct({
|
|
87
|
-
...ObjectFields,
|
|
88
|
-
kind: Schema.Literal("spline"),
|
|
89
|
-
samples: PlaneShapeSchema,
|
|
90
|
-
}).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, samePlanePoint), { message: "Expected at least three unique spline samples." })));
|
|
91
|
-
const PlaneClosedSplineObjectSchema = Schema.Struct({
|
|
92
|
-
...ObjectFields,
|
|
93
|
-
kind: Schema.Literal("closed-spline"),
|
|
94
|
-
samples: PlaneShapeSchema,
|
|
95
|
-
}).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, samePlanePoint), {
|
|
96
|
-
message: "Expected unique closed-spline samples without a repeated closing sample.",
|
|
97
|
-
})));
|
|
98
88
|
const PlaneCircleObjectSchema = Schema.Struct({
|
|
99
89
|
...ObjectFields,
|
|
100
90
|
center: PlanePointSchema,
|
|
@@ -109,18 +99,30 @@ const PlaneArcObjectSchema = Schema.Struct({
|
|
|
109
99
|
startDegrees: ArcStartDegreesSchema,
|
|
110
100
|
sweepDegrees: ArcSweepDegreesSchema,
|
|
111
101
|
});
|
|
102
|
+
const PlaneQuadraticObjectSchema = Schema.Struct({
|
|
103
|
+
...ObjectFields,
|
|
104
|
+
coefficients: Schema.Struct({
|
|
105
|
+
a: Schema.Finite.pipe(Schema.check(Schema.makeFilter((value) => value !== 0, {
|
|
106
|
+
message: "Expected a non-zero quadratic coefficient.",
|
|
107
|
+
}))),
|
|
108
|
+
b: Schema.Finite,
|
|
109
|
+
c: Schema.Finite,
|
|
110
|
+
}),
|
|
111
|
+
domain: MathAxisRangeSchema,
|
|
112
|
+
inputAxis: Schema.Literals(["x", "y"]),
|
|
113
|
+
kind: Schema.Literal("quadratic"),
|
|
114
|
+
});
|
|
112
115
|
/** Mathematical objects supported by a Cartesian plane scene. */
|
|
113
116
|
export const PlaneMathObjectSchema = Schema.Union([
|
|
114
117
|
PlaneArcObjectSchema,
|
|
115
118
|
PlaneCircleObjectSchema,
|
|
116
|
-
PlaneClosedSplineObjectSchema,
|
|
117
119
|
PlaneLineObjectSchema,
|
|
118
120
|
PlanePointObjectSchema,
|
|
119
121
|
PlanePolygonObjectSchema,
|
|
120
122
|
PlanePolylineObjectSchema,
|
|
123
|
+
PlaneQuadraticObjectSchema,
|
|
121
124
|
PlaneRayObjectSchema,
|
|
122
125
|
PlaneSegmentObjectSchema,
|
|
123
|
-
PlaneSplineObjectSchema,
|
|
124
126
|
]);
|
|
125
127
|
/** Exact Cartesian frame presented behind a plane construction. */
|
|
126
128
|
export const PlaneMathFrameSchema = Schema.Struct({
|
|
@@ -148,4 +150,8 @@ export const PlaneMathVisualSchema = Schema.Struct({
|
|
|
148
150
|
objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
|
|
149
151
|
space: Schema.Literal("plane"),
|
|
150
152
|
view: PlaneMathViewSchema,
|
|
151
|
-
}).pipe(Schema.check(Schema.makeFilter(({ labels = [], objects }) =>
|
|
153
|
+
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, view }) => [
|
|
154
|
+
...mathVisualIdentityIssues(objects, labels),
|
|
155
|
+
...planeBoundsIssues(frame, objects, labels),
|
|
156
|
+
...planeResolutionIssues(frame, objects, labels, view),
|
|
157
|
+
])));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
import type { PlanePoint, SpacePoint } from "#contracts/math/base";
|
|
3
|
+
import type { AxisRange } from "#contracts/math/extent";
|
|
4
|
+
import { type AxisTraversal } from "#contracts/math/intersection";
|
|
5
|
+
export type RenderThreshold = BigDecimal.BigDecimal;
|
|
6
|
+
/** Returns the exact width of one finite authored axis. */
|
|
7
|
+
export declare function axisSpan(range: AxisRange): BigDecimal.BigDecimal;
|
|
8
|
+
/** Checks one exact axis width against the shared render threshold. */
|
|
9
|
+
export declare function spanUnresolved(range: AxisRange, threshold: RenderThreshold): boolean;
|
|
10
|
+
/** Checks one non-zero measurement against the shared render threshold. */
|
|
11
|
+
export declare function measureUnresolved(value: number, threshold: RenderThreshold): boolean;
|
|
12
|
+
/** Resolves 2^-23 of the complete translation-invariant render envelope. */
|
|
13
|
+
export declare function renderThreshold(ranges: readonly [AxisRange, AxisRange, ...AxisRange[]], padding: number, envelopePairs?: readonly (readonly [number, number])[]): BigDecimal.BigDecimal;
|
|
14
|
+
/** Includes both view coordinates, their separation, and one frame axis. */
|
|
15
|
+
export declare function axisEnvelopePairs(range: AxisRange, left: number, right: number): readonly (readonly [number, number])[];
|
|
16
|
+
/** Checks that the frame-visible portion of one infinite path remains visible. */
|
|
17
|
+
export declare function visiblePathResolvable(kind: "line" | "ray", axes: readonly AxisTraversal[], threshold: RenderThreshold): boolean;
|
|
18
|
+
/** Checks whether any non-zero polygon altitude collapses in the renderer. */
|
|
19
|
+
export declare function polygonAltitudeUnresolved(vertices: readonly [
|
|
20
|
+
PlanePoint | SpacePoint,
|
|
21
|
+
PlanePoint | SpacePoint,
|
|
22
|
+
PlanePoint | SpacePoint,
|
|
23
|
+
...(PlanePoint | SpacePoint)[]
|
|
24
|
+
], threshold: RenderThreshold): boolean;
|
|
25
|
+
/** Checks exact quadratic curvature without relying on renderer sampling. */
|
|
26
|
+
export declare function quadraticCurvatureUnresolved(coefficient: number, domainSpan: BigDecimal.BigDecimal, threshold: RenderThreshold): boolean;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
/** Exact quotient whose denominator is normalized to a positive value. */
|
|
3
|
+
export interface ExactRatio {
|
|
4
|
+
readonly denominator: BigDecimal.BigDecimal;
|
|
5
|
+
readonly numerator: BigDecimal.BigDecimal;
|
|
6
|
+
}
|
|
7
|
+
/** Creates one exact decimal from a schema-validated finite number. */
|
|
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;
|
|
11
|
+
/** Creates one exact ratio from a known non-zero denominator. */
|
|
12
|
+
export declare function makeRatio(numerator: BigDecimal.BigDecimal, denominator: BigDecimal.BigDecimal): ExactRatio;
|
|
13
|
+
/** Creates one exact ratio from a finite number. */
|
|
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;
|
|
17
|
+
/** Creates the exact path parameter `(boundary - start) / (through - start)`. */
|
|
18
|
+
export declare function differenceRatio(boundary: number, start: number, through: number): ExactRatio;
|
|
19
|
+
/** Compares two exact ratios without division or floating-point overflow. */
|
|
20
|
+
export declare function compareRatios(left: ExactRatio, right: ExactRatio): import("effect/Ordering").Ordering;
|
|
21
|
+
/** Checks one exact ratio against inclusive finite numeric boundaries. */
|
|
22
|
+
export declare function ratioInRange(ratio: ExactRatio, minimum: number, maximum: number): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
const unit = BigDecimal.fromBigInt(1n);
|
|
3
|
+
/** Creates one exact decimal from a schema-validated finite number. */
|
|
4
|
+
export function decimal(value) {
|
|
5
|
+
return BigDecimal.fromNumberUnsafe(value);
|
|
6
|
+
}
|
|
7
|
+
/** Lifts one exact decimal into the shared rational coordinate form. */
|
|
8
|
+
export function decimalRatio(value) {
|
|
9
|
+
return { denominator: unit, numerator: value };
|
|
10
|
+
}
|
|
11
|
+
/** Creates one exact ratio from a known non-zero denominator. */
|
|
12
|
+
export function makeRatio(numerator, denominator) {
|
|
13
|
+
return BigDecimal.isNegative(denominator)
|
|
14
|
+
? {
|
|
15
|
+
denominator: BigDecimal.negate(denominator),
|
|
16
|
+
numerator: BigDecimal.negate(numerator),
|
|
17
|
+
}
|
|
18
|
+
: { denominator, numerator };
|
|
19
|
+
}
|
|
20
|
+
/** Creates one exact ratio from a finite number. */
|
|
21
|
+
export function numberRatio(value) {
|
|
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);
|
|
28
|
+
}
|
|
29
|
+
/** Creates the exact path parameter `(boundary - start) / (through - start)`. */
|
|
30
|
+
export function differenceRatio(boundary, start, through) {
|
|
31
|
+
const origin = decimal(start);
|
|
32
|
+
return makeRatio(BigDecimal.subtract(decimal(boundary), origin), BigDecimal.subtract(decimal(through), origin));
|
|
33
|
+
}
|
|
34
|
+
/** Compares two exact ratios without division or floating-point overflow. */
|
|
35
|
+
export function compareRatios(left, right) {
|
|
36
|
+
return BigDecimal.Order(BigDecimal.multiply(left.numerator, right.denominator), BigDecimal.multiply(right.numerator, left.denominator));
|
|
37
|
+
}
|
|
38
|
+
/** Checks one exact ratio against inclusive finite numeric boundaries. */
|
|
39
|
+
export function ratioInRange(ratio, minimum, maximum) {
|
|
40
|
+
return (compareRatios(numberRatio(minimum), ratio) <= 0 &&
|
|
41
|
+
compareRatios(ratio, numberRatio(maximum)) <= 0);
|
|
42
|
+
}
|
|
@@ -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[];
|