@nakafa/aksara-contracts 0.48.0 → 0.48.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/dist/graph/identity.js +2 -2
- package/dist/math/arc.js +3 -3
- package/dist/math/base.js +9 -9
- package/dist/math/bounds.d.ts +1 -1
- package/dist/math/bounds.js +13 -12
- package/dist/math/collision.js +21 -23
- package/dist/math/coordinate.js +3 -3
- package/dist/math/extent.js +10 -14
- package/dist/math/plane.js +5 -5
- package/dist/math/precision.js +3 -3
- package/dist/math/proximity.js +15 -12
- package/dist/math/resolution.js +6 -6
- package/dist/math/scene.js +8 -8
- package/dist/math/vector.js +6 -5
- package/dist/math/visual.js +2 -2
- package/dist/preview/target.js +5 -5
- package/dist/program/curriculum.js +3 -3
- package/dist/program/snapshot/digest.js +12 -12
- package/dist/program/spec.js +4 -4
- package/dist/projection/article.js +3 -3
- package/dist/projection/material.js +2 -2
- package/dist/projection/question.js +2 -2
- package/dist/question/answer.js +3 -3
- package/dist/question/identity.js +2 -2
- package/dist/question/item.js +10 -10
- package/dist/question/response.js +12 -12
- package/dist/question/rubric.js +9 -9
- package/dist/quran/attribution.d.ts +12 -4
- package/dist/quran/attribution.js +2 -1
- package/dist/quran/notes.js +24 -17
- package/dist/quran/provenance.js +14 -13
- package/dist/quran/snapshot/digest.js +18 -13
- package/dist/quran/snapshot/row/hash.js +6 -6
- package/dist/quran/snapshot/row.js +3 -3
- package/dist/quran/source.js +10 -10
- package/dist/release/current/evidence.js +2 -2
- package/dist/release/head.js +2 -2
- package/dist/release/policy.js +5 -5
- package/dist/release/rollback/spec.js +4 -5
- package/dist/release/route/page.js +2 -2
- package/dist/release/snapshot/scope.js +3 -3
- package/dist/release/snapshot/spec.js +5 -5
- package/dist/renderer/component.js +2 -2
- package/dist/renderer/contract.js +9 -10
- package/dist/renderer/manifest.js +3 -4
- package/dist/runtime/protected/spec.js +3 -3
- package/dist/runtime/verify.js +2 -2
- package/dist/signature/trusted.js +3 -3
- package/dist/transport/batch.js +3 -3
- package/dist/transport/group.js +2 -2
- package/dist/transport/snapshot.js +2 -2
- package/dist/tryout/closure/accounting.js +2 -2
- package/dist/tryout/hash/catalog.js +5 -5
- package/dist/tryout/identity.js +7 -6
- package/dist/tryout/language.d.ts +1 -1
- package/dist/tryout/language.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -3
- package/dist/tryout/scoring.js +4 -4
- package/dist/tryout/snapshot/hash.js +2 -2
- package/package.json +1 -1
package/dist/graph/identity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { LearningGraphIdentitySchema, } from "#contracts/graph/spec";
|
|
3
3
|
import { AppLocaleSchema } from "#contracts/locale";
|
|
4
4
|
import { isLowerKebab } from "#contracts/text/syntax";
|
|
@@ -12,7 +12,7 @@ export const LearningGraphSegmentsSchema = Schema.Struct({
|
|
|
12
12
|
});
|
|
13
13
|
/** Builds one graph ID from already validated source-owned segments. */
|
|
14
14
|
function graphId(prefix, segments) {
|
|
15
|
-
return `${prefix}:${
|
|
15
|
+
return `${prefix}:${Arr.join(segments, ":")}`;
|
|
16
16
|
}
|
|
17
17
|
/** Source segments could not produce valid stable graph identities. */
|
|
18
18
|
export class LearningGraphIdentityError extends Schema.TaggedError()("LearningGraphIdentityError", { cause: Schema.Unknown }) {
|
package/dist/math/arc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigDecimal, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, BigDecimal, Schema } from "effect";
|
|
2
2
|
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
3
3
|
import { decimal } from "#contracts/math/rational";
|
|
4
4
|
const PI = BigDecimal.fromStringUnsafe("3.1415926535897932384626433832795028841971693993751");
|
|
@@ -79,8 +79,8 @@ export function arcCurvatureUnresolved(radius, sweepDegrees, threshold) {
|
|
|
79
79
|
export function arcEndpointAxesUnresolved(radius, startDegrees, sweepDegrees, threshold) {
|
|
80
80
|
const exactStart = decimal(startDegrees);
|
|
81
81
|
const exactEnd = BigDecimal.sum(exactStart, decimal(sweepDegrees));
|
|
82
|
-
return [
|
|
82
|
+
return Arr.some([
|
|
83
83
|
endpointAxisMeasure(radius, exactStart, startDegrees),
|
|
84
84
|
endpointAxisMeasure(radius, exactEnd, startDegrees + sweepDegrees),
|
|
85
|
-
]
|
|
85
|
+
], (measure) => boundedMeasureUnresolved(measure, threshold));
|
|
86
86
|
}
|
package/dist/math/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HashSet, MutableHashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, HashSet, MutableHashSet, MutableList, Option, Schema, } from "effect";
|
|
2
2
|
const KEY_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
3
3
|
/** Relative floating-point tolerance used by normalized geometry predicates. */
|
|
4
4
|
export const GEOMETRY_TOLERANCE = Number.EPSILON * 128;
|
|
@@ -67,31 +67,31 @@ export function sameSpacePoint(left, right) {
|
|
|
67
67
|
/** Returns every repeated-key index after its first authored occurrence. */
|
|
68
68
|
function duplicateKeyIndexes(values, keyOf) {
|
|
69
69
|
const seen = MutableHashSet.empty();
|
|
70
|
-
const duplicates =
|
|
70
|
+
const duplicates = MutableList.make();
|
|
71
71
|
for (const [index, value] of values.entries()) {
|
|
72
72
|
const key = keyOf(value);
|
|
73
73
|
if (MutableHashSet.has(seen, key)) {
|
|
74
|
-
|
|
74
|
+
MutableList.append(duplicates, index);
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
MutableHashSet.add(seen, key);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
return duplicates;
|
|
80
|
+
return MutableList.toArray(duplicates);
|
|
81
81
|
}
|
|
82
82
|
/** Reports every repeated scene identity at its exact authored key path. */
|
|
83
83
|
export function mathVisualIdentityIssues(objects, labels) {
|
|
84
|
-
const objectIds = HashSet.fromIterable(
|
|
84
|
+
const objectIds = HashSet.fromIterable(Arr.map(objects, ({ id }) => id));
|
|
85
85
|
return [
|
|
86
|
-
...duplicateKeyIndexes(objects, ({ id }) => id)
|
|
86
|
+
...Arr.map(duplicateKeyIndexes(objects, ({ id }) => id), (index) => ({
|
|
87
87
|
issue: "Expected a unique mathematical object id.",
|
|
88
88
|
path: ["objects", index, "id"],
|
|
89
89
|
})),
|
|
90
|
-
...duplicateKeyIndexes(labels, ({ key }) => key)
|
|
90
|
+
...Arr.map(duplicateKeyIndexes(labels, ({ key }) => key), (index) => ({
|
|
91
91
|
issue: "Expected a unique mathematical label key.",
|
|
92
92
|
path: ["labels", index, "key"],
|
|
93
93
|
})),
|
|
94
|
-
...
|
|
94
|
+
...Arr.flatMap(labels, (label, index) => HashSet.has(objectIds, label.objectId)
|
|
95
95
|
? []
|
|
96
96
|
: [
|
|
97
97
|
{
|
|
@@ -103,5 +103,5 @@ export function mathVisualIdentityIssues(objects, labels) {
|
|
|
103
103
|
}
|
|
104
104
|
/** Checks that an authored coordinate sequence contains no repeated position. */
|
|
105
105
|
export function hasUniquePositions(values, same) {
|
|
106
|
-
return
|
|
106
|
+
return Arr.every(values, (value, index) => Option.contains(Arr.findFirstIndex(values, (candidate) => same(value, candidate)), index));
|
|
107
107
|
}
|
package/dist/math/bounds.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Schema } from "effect";
|
|
2
2
|
import type { PlaneLabelAnchor, PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
|
|
3
3
|
import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject, SpaceMathView } from "#contracts/math/space";
|
|
4
4
|
/** Reports every finite plane object or label that escapes its authored frame. */
|
package/dist/math/bounds.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { Array as Arr } from "effect";
|
|
1
2
|
import { arcContained, axisContains, circleContained, cuboidContained, quadraticContained, } from "#contracts/math/extent";
|
|
2
3
|
import { infinitePathIntersectsBox } from "#contracts/math/intersection";
|
|
3
4
|
/** Checks one plane point against both inclusive frame ranges. */
|
|
4
5
|
function planeContains(frame, point) {
|
|
5
|
-
return [
|
|
6
|
+
return Arr.every([
|
|
6
7
|
{ coordinate: point.x, range: frame.x },
|
|
7
8
|
{ coordinate: point.y, range: frame.y },
|
|
8
|
-
]
|
|
9
|
+
], ({ coordinate, range }) => axisContains(range, coordinate));
|
|
9
10
|
}
|
|
10
11
|
/** Checks one space point against all three inclusive frame ranges. */
|
|
11
12
|
function spaceContains(frame, point) {
|
|
12
|
-
return [
|
|
13
|
+
return Arr.every([
|
|
13
14
|
{ coordinate: point.x, range: frame.x },
|
|
14
15
|
{ coordinate: point.y, range: frame.y },
|
|
15
16
|
{ coordinate: point.z, range: frame.z },
|
|
16
|
-
]
|
|
17
|
+
], ({ coordinate, range }) => axisContains(range, coordinate));
|
|
17
18
|
}
|
|
18
19
|
/** Maps one plane path onto the Cartesian frame slabs it traverses. */
|
|
19
20
|
function planeAxes(frame, start, through) {
|
|
@@ -43,10 +44,10 @@ function planeObjectContained(frame, object) {
|
|
|
43
44
|
return planeContains(frame, object.at);
|
|
44
45
|
}
|
|
45
46
|
if (object.kind === "segment") {
|
|
46
|
-
return [object.from, object.to]
|
|
47
|
+
return Arr.every([object.from, object.to], (point) => planeContains(frame, point));
|
|
47
48
|
}
|
|
48
49
|
if (object.kind === "polyline" || object.kind === "polygon") {
|
|
49
|
-
return object.vertices
|
|
50
|
+
return Arr.every(object.vertices, (point) => planeContains(frame, point));
|
|
50
51
|
}
|
|
51
52
|
if (object.kind === "circle") {
|
|
52
53
|
return circleContained(frame, object);
|
|
@@ -69,17 +70,17 @@ function spaceObjectContained(frame, object) {
|
|
|
69
70
|
return spaceContains(frame, object.at);
|
|
70
71
|
}
|
|
71
72
|
if (object.kind === "segment") {
|
|
72
|
-
return [object.from, object.to]
|
|
73
|
+
return Arr.every([object.from, object.to], (point) => spaceContains(frame, point));
|
|
73
74
|
}
|
|
74
75
|
if (object.kind === "polyline" || object.kind === "polygon") {
|
|
75
|
-
return object.vertices
|
|
76
|
+
return Arr.every(object.vertices, (point) => spaceContains(frame, point));
|
|
76
77
|
}
|
|
77
78
|
return cuboidContained(frame, object);
|
|
78
79
|
}
|
|
79
80
|
/** Reports every finite plane object or label that escapes its authored frame. */
|
|
80
81
|
export function planeBoundsIssues(frame, objects, labels) {
|
|
81
82
|
return [
|
|
82
|
-
...
|
|
83
|
+
...Arr.flatMap(objects, (object, index) => planeObjectContained(frame, object)
|
|
83
84
|
? []
|
|
84
85
|
: [
|
|
85
86
|
{
|
|
@@ -87,7 +88,7 @@ export function planeBoundsIssues(frame, objects, labels) {
|
|
|
87
88
|
path: ["objects", index],
|
|
88
89
|
},
|
|
89
90
|
]),
|
|
90
|
-
...
|
|
91
|
+
...Arr.flatMap(labels, (label, index) => planeContains(frame, label.at)
|
|
91
92
|
? []
|
|
92
93
|
: [
|
|
93
94
|
{
|
|
@@ -110,7 +111,7 @@ export function spaceBoundsIssues(frame, objects, labels, view) {
|
|
|
110
111
|
]
|
|
111
112
|
: [];
|
|
112
113
|
return [
|
|
113
|
-
...
|
|
114
|
+
...Arr.flatMap(objects, (object, index) => spaceObjectContained(frame, object)
|
|
114
115
|
? []
|
|
115
116
|
: [
|
|
116
117
|
{
|
|
@@ -118,7 +119,7 @@ export function spaceBoundsIssues(frame, objects, labels, view) {
|
|
|
118
119
|
path: ["objects", index],
|
|
119
120
|
},
|
|
120
121
|
]),
|
|
121
|
-
...
|
|
122
|
+
...Arr.flatMap(labels, (label, index) => spaceContains(frame, label.at)
|
|
122
123
|
? []
|
|
123
124
|
: [
|
|
124
125
|
{
|
package/dist/math/collision.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array as Arr, MutableHashMap, MutableHashSet,
|
|
1
|
+
import { Array as Arr, MutableHashMap, MutableHashSet, Record as Rec, } from "effect";
|
|
2
2
|
import { unresolvedProximityIndexes } from "#contracts/math/proximity";
|
|
3
3
|
import { numberRatio } from "#contracts/math/rational";
|
|
4
4
|
import { radialGeometryPath } from "#contracts/math/scene";
|
|
@@ -14,34 +14,32 @@ function uniquePaths(paths) {
|
|
|
14
14
|
/** Finds reportable scene coordinates that collapse on the same axis. */
|
|
15
15
|
export function coordinateCollisionPaths(coordinates, threshold) {
|
|
16
16
|
const axes = ["x", "y", "z"];
|
|
17
|
-
return uniquePaths(
|
|
18
|
-
const entries =
|
|
17
|
+
return uniquePaths(Arr.flatMap(axes, (axis) => {
|
|
18
|
+
const entries = Arr.filter(coordinates, (entry) => entry.axis === axis);
|
|
19
19
|
const unresolved = unresolvedProximityIndexes(entries, threshold);
|
|
20
|
-
return
|
|
20
|
+
return Arr.flatMap(entries, (entry, index) => entry.reportable && MutableHashSet.has(unresolved, index)
|
|
21
21
|
? [entry.path]
|
|
22
22
|
: []);
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
25
25
|
/** Finds non-zero radius deltas between concentric circles or arcs. */
|
|
26
26
|
export function concentricRadiusCollisionPaths(objects, threshold) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const radii = Arr.flatMap(objects, (object, index) => object.kind === "arc" || object.kind === "circle"
|
|
28
|
+
? [
|
|
29
|
+
{
|
|
30
|
+
center: `${object.center.x}:${object.center.y}`,
|
|
31
|
+
index,
|
|
32
|
+
kind: object.kind,
|
|
33
|
+
value: numberRatio(object.radius),
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
: []);
|
|
37
|
+
// A center text always holds a colon, so the groups keep first-seen order.
|
|
38
|
+
const groups = Rec.values(Arr.groupBy(radii, (radius) => radius.center));
|
|
39
|
+
return Arr.flatMap(groups, (group) => {
|
|
39
40
|
const unresolved = unresolvedProximityIndexes(group, threshold);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return paths;
|
|
41
|
+
return Arr.flatMap(group, (entry, entryIndex) => MutableHashSet.has(unresolved, entryIndex)
|
|
42
|
+
? [radialGeometryPath(entry.kind, entry.index)]
|
|
43
|
+
: []);
|
|
44
|
+
});
|
|
47
45
|
}
|
package/dist/math/coordinate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { AxisTraversalSchema, infinitePathInterval, } from "#contracts/math/intersection";
|
|
3
3
|
import { visiblePathResolvable, } from "#contracts/math/precision";
|
|
4
4
|
import { affineRatio, ExactRatioSchema, numberRatio, } from "#contracts/math/rational";
|
|
@@ -38,7 +38,7 @@ export function frameCoordinates(frame) {
|
|
|
38
38
|
["y", frame.y],
|
|
39
39
|
...("z" in frame ? [["z", frame.z]] : []),
|
|
40
40
|
];
|
|
41
|
-
return
|
|
41
|
+
return Arr.flatMap(axes, ([axis, range]) => [
|
|
42
42
|
sceneCoordinate(axis, ["frame", axis], numberRatio(range.min), false),
|
|
43
43
|
sceneCoordinate(axis, ["frame", axis], numberRatio(range.max), false),
|
|
44
44
|
]);
|
|
@@ -71,5 +71,5 @@ export function clippedPathCoordinates(frame, kind, from, through, path, thresho
|
|
|
71
71
|
if (!visiblePathResolvable(kind, axes, threshold)) {
|
|
72
72
|
return [];
|
|
73
73
|
}
|
|
74
|
-
return [interval.entry, interval.exit]
|
|
74
|
+
return Arr.flatMap([interval.entry, interval.exit], (parameter) => Arr.map(axes, (axis) => sceneCoordinate(axis.axis, path, affineRatio(axis.start, axis.through, parameter))));
|
|
75
75
|
}
|
package/dist/math/extent.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigDecimal, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, BigDecimal, Schema } from "effect";
|
|
2
2
|
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
3
3
|
import { decimal, decimalRatio, ExactRatioSchema, makeRatio, numberRatio, ratioInRange, } from "#contracts/math/rational";
|
|
4
4
|
const ZERO = BigDecimal.fromBigInt(0n);
|
|
@@ -59,27 +59,23 @@ function arcOffset(radius, angle) {
|
|
|
59
59
|
/** Returns every endpoint or cardinal offset that bounds one radial object. */
|
|
60
60
|
export function radialOffsets(object) {
|
|
61
61
|
if (object.kind === "circle") {
|
|
62
|
-
return [0, 90, 180, 270]
|
|
62
|
+
return Arr.map([0, 90, 180, 270], (angle) => arcOffset(object.radius, angle));
|
|
63
63
|
}
|
|
64
64
|
const angles = [
|
|
65
65
|
object.startDegrees,
|
|
66
66
|
object.startDegrees + object.sweepDegrees,
|
|
67
|
+
...Arr.filter([0, 90, 180, 270], (angle) => arcContainsAngle(object.startDegrees, object.sweepDegrees, angle)),
|
|
67
68
|
];
|
|
68
|
-
|
|
69
|
-
if (arcContainsAngle(object.startDegrees, object.sweepDegrees, angle)) {
|
|
70
|
-
angles.push(angle);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return angles.map((angle) => arcOffset(object.radius, angle));
|
|
69
|
+
return Arr.map(angles, (angle) => arcOffset(object.radius, angle));
|
|
74
70
|
}
|
|
75
71
|
/** Checks the exact endpoints and cardinal extrema of one directed arc. */
|
|
76
72
|
export function arcContained(frame, object) {
|
|
77
|
-
return radialOffsets(object)
|
|
73
|
+
return Arr.every(radialOffsets(object), (offset) => axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
|
|
78
74
|
axisContainsTranslated(frame.y, object.center.y, offset.y, offset.error));
|
|
79
75
|
}
|
|
80
76
|
/** Checks one circle through exact radius-to-boundary comparisons. */
|
|
81
77
|
export function circleContained(frame, object) {
|
|
82
|
-
return radialOffsets(object)
|
|
78
|
+
return Arr.every(radialOffsets(object), (offset) => axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
|
|
83
79
|
axisContainsTranslated(frame.y, object.center.y, offset.y, offset.error));
|
|
84
80
|
}
|
|
85
81
|
/** Evaluates one quadratic exactly at a finite authored input. */
|
|
@@ -99,7 +95,7 @@ const QuadraticExtremumSchema = Schema.Struct({
|
|
|
99
95
|
});
|
|
100
96
|
/** Returns both domain endpoints and the in-domain vertex of one quadratic. */
|
|
101
97
|
export function quadraticExtrema(object) {
|
|
102
|
-
const endpoints = [object.domain.min, object.domain.max]
|
|
98
|
+
const endpoints = Arr.map([object.domain.min, object.domain.max], (input) => ({
|
|
103
99
|
input: numberRatio(input),
|
|
104
100
|
output: decimalRatio(quadraticValue(object, input)),
|
|
105
101
|
}));
|
|
@@ -117,10 +113,10 @@ export function quadraticExtrema(object) {
|
|
|
117
113
|
export function quadraticContained(frame, object) {
|
|
118
114
|
const inputRange = object.inputAxis === "x" ? frame.x : frame.y;
|
|
119
115
|
const outputRange = object.inputAxis === "x" ? frame.y : frame.x;
|
|
120
|
-
if (![object.domain.min, object.domain.max]
|
|
116
|
+
if (!Arr.every([object.domain.min, object.domain.max], (input) => axisContains(inputRange, input))) {
|
|
121
117
|
return false;
|
|
122
118
|
}
|
|
123
|
-
return quadraticExtrema(object)
|
|
119
|
+
return Arr.every(quadraticExtrema(object), ({ output }) => ratioInRange(output, outputRange.min, outputRange.max));
|
|
124
120
|
}
|
|
125
121
|
const CuboidExtentSchema = Schema.Struct({
|
|
126
122
|
axis: Schema.Literals(["x", "y", "z"]),
|
|
@@ -154,6 +150,6 @@ export function cuboidExtents(object) {
|
|
|
154
150
|
}
|
|
155
151
|
/** Checks one cuboid through exact half-extent-to-boundary comparisons. */
|
|
156
152
|
export function cuboidContained(frame, object) {
|
|
157
|
-
return cuboidExtents(object)
|
|
153
|
+
return Arr.every(cuboidExtents(object), ({ axis, center, extent }) => axisContainsTranslated(frame[axis], center, extent, ZERO) &&
|
|
158
154
|
axisContainsTranslated(frame[axis], center, BigDecimal.negate(extent), ZERO));
|
|
159
155
|
}
|
package/dist/math/plane.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
|
|
3
3
|
import { planeBoundsIssues } from "#contracts/math/bounds";
|
|
4
4
|
import { planeResolutionIssues } from "#contracts/math/resolution";
|
|
@@ -24,16 +24,16 @@ function hasPlaneArea(vertices) {
|
|
|
24
24
|
/** Translates before scaling so polygon area is independent of its location. */
|
|
25
25
|
function normalizedPlaneOffsets(vertices) {
|
|
26
26
|
const [origin] = vertices;
|
|
27
|
-
let offsets =
|
|
27
|
+
let offsets = Arr.map(vertices, ({ x, y }) => ({
|
|
28
28
|
x: x - origin.x,
|
|
29
29
|
y: y - origin.y,
|
|
30
30
|
}));
|
|
31
|
-
if (
|
|
31
|
+
if (Arr.some(offsets, ({ x, y }) => !(Number.isFinite(x) && Number.isFinite(y)))) {
|
|
32
32
|
let sourceScale = 1;
|
|
33
33
|
for (const { x, y } of vertices) {
|
|
34
34
|
sourceScale = Math.max(sourceScale, Math.abs(x), Math.abs(y));
|
|
35
35
|
}
|
|
36
|
-
offsets =
|
|
36
|
+
offsets = Arr.map(vertices, ({ x, y }) => ({
|
|
37
37
|
x: x / sourceScale - origin.x / sourceScale,
|
|
38
38
|
y: y / sourceScale - origin.y / sourceScale,
|
|
39
39
|
}));
|
|
@@ -43,7 +43,7 @@ function normalizedPlaneOffsets(vertices) {
|
|
|
43
43
|
extent = Math.max(extent, Math.abs(x), Math.abs(y));
|
|
44
44
|
}
|
|
45
45
|
const divisor = Math.max(extent, Number.MIN_VALUE);
|
|
46
|
-
return
|
|
46
|
+
return Arr.map(offsets, ({ x, y }) => ({ x: x / divisor, y: y / divisor }));
|
|
47
47
|
}
|
|
48
48
|
const PlanePointObjectSchema = Schema.Struct({
|
|
49
49
|
...ObjectFields,
|
package/dist/math/precision.js
CHANGED
|
@@ -72,7 +72,7 @@ export function visiblePathResolvable(kind, axes, threshold) {
|
|
|
72
72
|
}
|
|
73
73
|
/** Checks whether any non-zero polygon altitude collapses in the renderer. */
|
|
74
74
|
export function polygonAltitudeUnresolved(vertices, threshold) {
|
|
75
|
-
const exact =
|
|
75
|
+
const exact = EffectArray.map(vertices, (point) => ({
|
|
76
76
|
x: decimal(point.x),
|
|
77
77
|
y: decimal(point.y),
|
|
78
78
|
z: decimal("z" in point ? point.z : 0),
|
|
@@ -96,11 +96,11 @@ export function polygonAltitudeUnresolved(vertices, threshold) {
|
|
|
96
96
|
y: BigDecimal.subtract(BigDecimal.multiply(baseline.z, offset.x), BigDecimal.multiply(baseline.x, offset.z)),
|
|
97
97
|
z: BigDecimal.subtract(BigDecimal.multiply(baseline.x, offset.y), BigDecimal.multiply(baseline.y, offset.x)),
|
|
98
98
|
};
|
|
99
|
-
const crossSquared = BigDecimal.sumAll(Rec.values(cross)
|
|
99
|
+
const crossSquared = BigDecimal.sumAll(EffectArray.map(Rec.values(cross), (value) => BigDecimal.multiply(value, value)));
|
|
100
100
|
if (BigDecimal.isZero(crossSquared)) {
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
const baselineSquared = BigDecimal.sumAll(Rec.values(baseline)
|
|
103
|
+
const baselineSquared = BigDecimal.sumAll(EffectArray.map(Rec.values(baseline), (value) => BigDecimal.multiply(value, value)));
|
|
104
104
|
if (BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared))) {
|
|
105
105
|
return true;
|
|
106
106
|
}
|
package/dist/math/proximity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigDecimal, Array as EffectArray, MutableHashSet, Schema, } from "effect";
|
|
1
|
+
import { BigDecimal, Array as EffectArray, MutableHashSet, MutableList, Order, Schema, } from "effect";
|
|
2
2
|
import { compareRatios, ExactRatioSchema, makeRatio, } from "#contracts/math/rational";
|
|
3
3
|
/** One exact rational coordinate participating in a proximity comparison. */
|
|
4
4
|
const ExactProximityEntrySchema = Schema.Struct({
|
|
@@ -43,21 +43,24 @@ function firstRank(values, target, afterEqual) {
|
|
|
43
43
|
}
|
|
44
44
|
/** Assigns a stable exact rank to every source-ordered ratio. */
|
|
45
45
|
function rankRatios(values) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const indexed = EffectArray.map(values, (value, sourceIndex) => ({
|
|
47
|
+
sourceIndex,
|
|
48
|
+
value,
|
|
49
|
+
}));
|
|
50
|
+
const ordered = EffectArray.sortWith(indexed, (entry) => entry.value, Order.make(compareRatios));
|
|
51
|
+
const distinct = MutableList.make();
|
|
50
52
|
const ranks = new Array(values.length);
|
|
53
|
+
let previous;
|
|
51
54
|
for (const entry of ordered) {
|
|
52
|
-
|
|
53
|
-
if (previous && compareRatios(previous, entry.value) === 0) {
|
|
55
|
+
if (previous !== undefined && compareRatios(previous, entry.value) === 0) {
|
|
54
56
|
ranks[entry.sourceIndex] = distinct.length - 1;
|
|
55
57
|
continue;
|
|
56
58
|
}
|
|
57
59
|
ranks[entry.sourceIndex] = distinct.length;
|
|
58
|
-
|
|
60
|
+
MutableList.append(distinct, entry.value);
|
|
61
|
+
previous = entry.value;
|
|
59
62
|
}
|
|
60
|
-
return { ranks, values: distinct };
|
|
63
|
+
return { ranks, values: MutableList.toArray(distinct) };
|
|
61
64
|
}
|
|
62
65
|
/** Builds an empty segment tree over exact ratio ranks. */
|
|
63
66
|
function makeTree(size) {
|
|
@@ -129,9 +132,9 @@ function exactInterval(entry) {
|
|
|
129
132
|
* distinct gap below one threshold in O(n log n).
|
|
130
133
|
*/
|
|
131
134
|
export function unresolvedProximityIndexes(entries, threshold) {
|
|
132
|
-
const intervals =
|
|
133
|
-
const lower = rankRatios(
|
|
134
|
-
const upper = rankRatios(
|
|
135
|
+
const intervals = EffectArray.map(entries, exactInterval);
|
|
136
|
+
const lower = rankRatios(EffectArray.map(intervals, (entry) => entry.lower));
|
|
137
|
+
const upper = rankRatios(EffectArray.map(intervals, (entry) => entry.upper));
|
|
135
138
|
const leftTree = makeTree(upper.values.length);
|
|
136
139
|
const rightTree = makeTree(lower.values.length);
|
|
137
140
|
const unresolved = MutableHashSet.empty();
|
package/dist/math/resolution.js
CHANGED
|
@@ -76,7 +76,7 @@ function planeObjectIssues(frame, object, index, threshold) {
|
|
|
76
76
|
}
|
|
77
77
|
/** Reports every frame axis whose non-zero span collapses in the envelope. */
|
|
78
78
|
function frameIssues(entries, threshold) {
|
|
79
|
-
return
|
|
79
|
+
return Arr.flatMap(entries, ({ axis, range }) => spanUnresolved(range, threshold) ? [issue(["frame", axis])] : []);
|
|
80
80
|
}
|
|
81
81
|
/** Reports every plane delta that a normalized renderer cannot preserve. */
|
|
82
82
|
export function planeResolutionIssues(frame, objects, labels, view) {
|
|
@@ -87,9 +87,9 @@ export function planeResolutionIssues(frame, objects, labels, view) {
|
|
|
87
87
|
{ axis: "y", range: frame.y },
|
|
88
88
|
], threshold),
|
|
89
89
|
...measureIssue(view.padding ?? 0, threshold, ["view", "padding"]),
|
|
90
|
-
...coordinateCollisionPaths(planeSceneCoordinates(frame, objects, labels, threshold), threshold)
|
|
91
|
-
...concentricRadiusCollisionPaths(objects, threshold)
|
|
92
|
-
...
|
|
90
|
+
...Arr.map(coordinateCollisionPaths(planeSceneCoordinates(frame, objects, labels, threshold), threshold), issue),
|
|
91
|
+
...Arr.map(concentricRadiusCollisionPaths(objects, threshold), issue),
|
|
92
|
+
...Arr.flatMap(objects, (object, index) => planeObjectIssues(frame, object, index, threshold)),
|
|
93
93
|
]);
|
|
94
94
|
}
|
|
95
95
|
/** Reports every space delta that a normalized renderer cannot preserve. */
|
|
@@ -112,7 +112,7 @@ export function spaceResolutionIssues(frame, objects, labels, view) {
|
|
|
112
112
|
"view",
|
|
113
113
|
"padding",
|
|
114
114
|
]),
|
|
115
|
-
...coordinateCollisionPaths(spaceSceneCoordinates(frame, objects, labels, view, threshold), threshold)
|
|
116
|
-
...
|
|
115
|
+
...Arr.map(coordinateCollisionPaths(spaceSceneCoordinates(frame, objects, labels, view, threshold), threshold), issue),
|
|
116
|
+
...Arr.flatMap(objects, (object, index) => objectResolutionIssues(frame, object, index, threshold)),
|
|
117
117
|
]);
|
|
118
118
|
}
|
package/dist/math/scene.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigDecimal } from "effect";
|
|
1
|
+
import { Array as Arr, BigDecimal } from "effect";
|
|
2
2
|
import { arcCurvatureUnresolved, arcEndpointsUnresolved, } from "#contracts/math/arc";
|
|
3
3
|
import { clippedPathCoordinates, sceneCoordinate as coordinate, frameCoordinates, pointCoordinates, } from "#contracts/math/coordinate";
|
|
4
4
|
import { cuboidExtents, quadraticExtrema, radialOffsets, } from "#contracts/math/extent";
|
|
@@ -14,7 +14,7 @@ function radialCoordinates(object, path, threshold) {
|
|
|
14
14
|
arcCurvatureUnresolved(object.radius, object.sweepDegrees, threshold))) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
|
-
return radialOffsets(object)
|
|
17
|
+
return Arr.flatMap(radialOffsets(object), (offset) => [
|
|
18
18
|
coordinate("x", path, decimalRatio(BigDecimal.sum(decimal(object.center.x), offset.x)), true, offset.error),
|
|
19
19
|
coordinate("y", path, decimalRatio(BigDecimal.sum(decimal(object.center.y), offset.y)), true, offset.error),
|
|
20
20
|
]);
|
|
@@ -32,7 +32,7 @@ function quadraticCoordinates(object, path, threshold) {
|
|
|
32
32
|
}
|
|
33
33
|
const { inputAxis } = object;
|
|
34
34
|
const outputAxis = inputAxis === "x" ? "y" : "x";
|
|
35
|
-
return quadraticExtrema(object)
|
|
35
|
+
return Arr.flatMap(quadraticExtrema(object), ({ input, output }) => [
|
|
36
36
|
coordinate(inputAxis, path, input),
|
|
37
37
|
coordinate(outputAxis, path, output),
|
|
38
38
|
]);
|
|
@@ -41,7 +41,7 @@ function quadraticCoordinates(object, path, threshold) {
|
|
|
41
41
|
function cuboidCoordinates(object, path) {
|
|
42
42
|
return [
|
|
43
43
|
...pointCoordinates(object.center, [...path, "center"]),
|
|
44
|
-
...cuboidExtents(object)
|
|
44
|
+
...Arr.flatMap(cuboidExtents(object), ({ axis, center, dimension, extent }) => [
|
|
45
45
|
coordinate(axis, [...path, "size", dimension], decimalRatio(BigDecimal.subtract(decimal(center), extent))),
|
|
46
46
|
coordinate(axis, [...path, "size", dimension], decimalRatio(BigDecimal.sum(decimal(center), extent))),
|
|
47
47
|
]),
|
|
@@ -67,7 +67,7 @@ function objectCoordinates(frame, object, index, threshold) {
|
|
|
67
67
|
];
|
|
68
68
|
}
|
|
69
69
|
if (object.kind === "polyline" || object.kind === "polygon") {
|
|
70
|
-
return object.vertices
|
|
70
|
+
return Arr.flatMap(object.vertices, (point, pointIndex) => pointCoordinates(point, [...root, "vertices", pointIndex]));
|
|
71
71
|
}
|
|
72
72
|
if (object.kind === "circle" || object.kind === "arc") {
|
|
73
73
|
return [
|
|
@@ -82,7 +82,7 @@ function objectCoordinates(frame, object, index, threshold) {
|
|
|
82
82
|
}
|
|
83
83
|
/** Projects all label anchors after the objects they annotate. */
|
|
84
84
|
function labelCoordinates(labels) {
|
|
85
|
-
return
|
|
85
|
+
return Arr.flatMap(labels, (label, index) => pointCoordinates(label.at, ["labels", index, "at"]));
|
|
86
86
|
}
|
|
87
87
|
/** Projects semantic camera or isometric coordinates before space objects. */
|
|
88
88
|
function viewCoordinates(view) {
|
|
@@ -100,7 +100,7 @@ function viewCoordinates(view) {
|
|
|
100
100
|
export function planeSceneCoordinates(frame, objects, labels, threshold) {
|
|
101
101
|
return [
|
|
102
102
|
...frameCoordinates(frame),
|
|
103
|
-
...
|
|
103
|
+
...Arr.flatMap(objects, (object, index) => objectCoordinates(frame, object, index, threshold)),
|
|
104
104
|
...labelCoordinates(labels),
|
|
105
105
|
];
|
|
106
106
|
}
|
|
@@ -109,7 +109,7 @@ export function spaceSceneCoordinates(frame, objects, labels, view, threshold) {
|
|
|
109
109
|
return [
|
|
110
110
|
...frameCoordinates(frame),
|
|
111
111
|
...viewCoordinates(view),
|
|
112
|
-
...
|
|
112
|
+
...Arr.flatMap(objects, (object, index) => objectCoordinates(frame, object, index, threshold)),
|
|
113
113
|
...labelCoordinates(labels),
|
|
114
114
|
];
|
|
115
115
|
}
|
package/dist/math/vector.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Array as Arr } from "effect";
|
|
1
2
|
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
2
3
|
/** Checks a space polygon is planar and has non-zero area. */
|
|
3
4
|
export function hasCoplanarArea(vertices) {
|
|
@@ -19,23 +20,23 @@ export function hasCoplanarArea(vertices) {
|
|
|
19
20
|
return false;
|
|
20
21
|
}
|
|
21
22
|
const unitNormal = divide(strongestNormal, strongestLength);
|
|
22
|
-
return
|
|
23
|
+
return Arr.every(offsets, (offset) => Math.abs(dot(unitNormal, offset)) <=
|
|
23
24
|
GEOMETRY_TOLERANCE * Math.max(1, length(offset)));
|
|
24
25
|
}
|
|
25
26
|
/** Translates before scaling so coplanarity is independent of scene location. */
|
|
26
27
|
function normalizedSpaceOffsets(vertices) {
|
|
27
28
|
const [origin] = vertices;
|
|
28
|
-
let offsets =
|
|
29
|
+
let offsets = Arr.map(vertices, ({ x, y, z }) => ({
|
|
29
30
|
x: x - origin.x,
|
|
30
31
|
y: y - origin.y,
|
|
31
32
|
z: z - origin.z,
|
|
32
33
|
}));
|
|
33
|
-
if (
|
|
34
|
+
if (Arr.some(offsets, ({ x, y, z }) => !(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z)))) {
|
|
34
35
|
let sourceScale = 1;
|
|
35
36
|
for (const { x, y, z } of vertices) {
|
|
36
37
|
sourceScale = Math.max(sourceScale, Math.abs(x), Math.abs(y), Math.abs(z));
|
|
37
38
|
}
|
|
38
|
-
offsets =
|
|
39
|
+
offsets = Arr.map(vertices, ({ x, y, z }) => ({
|
|
39
40
|
x: x / sourceScale - origin.x / sourceScale,
|
|
40
41
|
y: y / sourceScale - origin.y / sourceScale,
|
|
41
42
|
z: z / sourceScale - origin.z / sourceScale,
|
|
@@ -46,7 +47,7 @@ function normalizedSpaceOffsets(vertices) {
|
|
|
46
47
|
extent = Math.max(extent, Math.abs(x), Math.abs(y), Math.abs(z));
|
|
47
48
|
}
|
|
48
49
|
const divisor = Math.max(extent, Number.MIN_VALUE);
|
|
49
|
-
return
|
|
50
|
+
return Arr.map(offsets, (offset) => divide(offset, divisor));
|
|
50
51
|
}
|
|
51
52
|
/** Returns the cross product of two space vectors. */
|
|
52
53
|
function cross(left, right) {
|
package/dist/math/visual.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { decodeContract } from "#contracts/decode";
|
|
3
3
|
import { PlaneMathVisualSchema } from "#contracts/math/plane";
|
|
4
4
|
import { SpaceMathVisualSchema } from "#contracts/math/space";
|
|
@@ -11,5 +11,5 @@ export const MathVisualSchema = Schema.Union([
|
|
|
11
11
|
export const decodeMathVisual = Effect.fn("AksaraContracts.decodeMathVisual")((input) => decodeContract(MathVisualSchema, "MathVisual", input));
|
|
12
12
|
/** Returns every rich-label key in authored anchor order. */
|
|
13
13
|
export function mathVisualLabelKeys(visual) {
|
|
14
|
-
return (visual.labels ?? []
|
|
14
|
+
return Arr.map(visual.labels ?? [], ({ key }) => key);
|
|
15
15
|
}
|
package/dist/preview/target.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, Struct } from "effect";
|
|
1
|
+
import { Array as Arr, Schema, Struct } from "effect";
|
|
2
2
|
import { PublicPathSchema } from "#contracts/ids";
|
|
3
3
|
import { AppLocaleSchema } from "#contracts/locale";
|
|
4
4
|
import { TryoutExamSchema, TryoutSectionSchema, TryoutSetSchema, TryoutTrackSchema, } from "#contracts/tryout/catalog";
|
|
@@ -23,10 +23,10 @@ const TryoutPreviewTargetInputSchema = Schema.Struct({
|
|
|
23
23
|
/** Checks that every target row belongs to one locale-specific hierarchy. */
|
|
24
24
|
function hasCoherentTryoutHierarchy(input) {
|
|
25
25
|
const rows = [input.track, input.set, input.section, input.placement];
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return (Arr.every(rows, ({ countryKey }) => countryKey === input.exam.countryKey) &&
|
|
27
|
+
Arr.every(rows, ({ examKey }) => examKey === input.exam.examKey) &&
|
|
28
|
+
Arr.every(rows, ({ appLocale }) => appLocale === input.exam.appLocale) &&
|
|
29
|
+
Arr.every(rows, ({ sourceRevision }) => sourceRevision === input.exam.sourceRevision) &&
|
|
30
30
|
input.set.trackKey === input.track.trackKey &&
|
|
31
31
|
input.section.trackKey === input.track.trackKey &&
|
|
32
32
|
input.placement.trackKey === input.track.trackKey &&
|