@nakafa/aksara-contracts 0.48.0 → 0.48.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/canonical.d.ts +5 -0
  2. package/dist/canonical.js +10 -0
  3. package/dist/graph/identity.js +2 -2
  4. package/dist/locale.js +2 -9
  5. package/dist/math/arc.js +3 -3
  6. package/dist/math/base.js +11 -11
  7. package/dist/math/bounds.d.ts +1 -1
  8. package/dist/math/bounds.js +13 -12
  9. package/dist/math/collision.js +21 -23
  10. package/dist/math/coordinate.js +3 -3
  11. package/dist/math/extent.js +10 -14
  12. package/dist/math/plane.js +6 -6
  13. package/dist/math/precision.js +7 -10
  14. package/dist/math/proximity.js +17 -14
  15. package/dist/math/resolution.js +6 -6
  16. package/dist/math/scene.js +8 -8
  17. package/dist/math/vector.js +16 -18
  18. package/dist/math/visual.js +2 -2
  19. package/dist/preview/target.js +5 -5
  20. package/dist/program/curriculum.js +3 -3
  21. package/dist/program/snapshot/digest.js +13 -13
  22. package/dist/program/spec.js +5 -9
  23. package/dist/projection/article.js +3 -3
  24. package/dist/projection/material.js +2 -2
  25. package/dist/projection/question.js +2 -2
  26. package/dist/question/answer.js +3 -3
  27. package/dist/question/identity.js +9 -7
  28. package/dist/question/item.js +10 -10
  29. package/dist/question/response.js +12 -12
  30. package/dist/question/rubric.js +9 -9
  31. package/dist/quran/attribution.d.ts +12 -4
  32. package/dist/quran/attribution.js +2 -1
  33. package/dist/quran/notes.js +24 -17
  34. package/dist/quran/provenance.js +14 -13
  35. package/dist/quran/snapshot/digest.js +27 -18
  36. package/dist/quran/snapshot/row/hash.js +6 -6
  37. package/dist/quran/snapshot/row.js +4 -8
  38. package/dist/quran/snapshot/spec.js +2 -2
  39. package/dist/quran/source.js +12 -16
  40. package/dist/release/current/evidence.js +2 -2
  41. package/dist/release/head.js +2 -2
  42. package/dist/release/items.js +2 -2
  43. package/dist/release/policy.js +8 -8
  44. package/dist/release/rollback/spec.js +8 -9
  45. package/dist/release/route/page.js +6 -6
  46. package/dist/release/snapshot/scope.js +3 -14
  47. package/dist/release/snapshot/spec.js +6 -5
  48. package/dist/release/spec.js +2 -2
  49. package/dist/renderer/compatibility.js +3 -3
  50. package/dist/renderer/component.js +2 -2
  51. package/dist/renderer/contract.js +9 -10
  52. package/dist/renderer/manifest.js +3 -4
  53. package/dist/runtime/protected/spec.js +3 -3
  54. package/dist/runtime/verify.js +2 -2
  55. package/dist/signature/trusted.js +3 -3
  56. package/dist/signature/verify.js +9 -14
  57. package/dist/transport/batch.js +3 -3
  58. package/dist/transport/group.js +2 -2
  59. package/dist/transport/snapshot.js +2 -2
  60. package/dist/tryout/closure/accounting.js +3 -3
  61. package/dist/tryout/hash/catalog.js +5 -5
  62. package/dist/tryout/identity.js +7 -6
  63. package/dist/tryout/language.d.ts +1 -1
  64. package/dist/tryout/language.js +1 -1
  65. package/dist/tryout/scoring.d.ts +3 -3
  66. package/dist/tryout/scoring.js +4 -4
  67. package/dist/tryout/snapshot/hash.js +2 -2
  68. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Checks that a list names members of one canonical list, each at most once,
3
+ * in the canonical order. A value outside the canonical list fails the check.
4
+ */
5
+ export declare function hasCanonicalOrder(canonical: readonly string[], values: readonly string[]): boolean;
@@ -0,0 +1,10 @@
1
+ import { Array as Arr } from "effect";
2
+ /**
3
+ * Checks that a list names members of one canonical list, each at most once,
4
+ * in the canonical order. A value outside the canonical list fails the check.
5
+ */
6
+ export function hasCanonicalOrder(canonical, values) {
7
+ const expected = Arr.filter(canonical, (member) => Arr.some(values, (value) => value === member));
8
+ return (expected.length === values.length &&
9
+ Arr.every(values, (value, index) => value === expected[index]));
10
+ }
@@ -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}:${segments.join(":")}`;
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/locale.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Schema } from "effect";
2
+ import { hasCanonicalOrder } from "#contracts/canonical";
2
3
  /** Stable locale codes supported by the current Aksara contract. */
3
4
  export const AppLocaleCodeSchema = Schema.Literals(["en", "id", "de"]);
4
5
  export const [ENGLISH_APP_LOCALE_CODE, INDONESIAN_APP_LOCALE_CODE, GERMAN_APP_LOCALE_CODE,] = AppLocaleCodeSchema.literals;
@@ -35,15 +36,7 @@ export function artifactLocaleCode(artifactLocale) {
35
36
  }
36
37
  /** Checks a nonempty locale subset for uniqueness and canonical order. */
37
38
  function hasCanonicalActiveAppLocales(locales) {
38
- let previousIndex = -1;
39
- for (const locale of locales) {
40
- const index = APP_LOCALE_CODES.indexOf(locale);
41
- if (index <= previousIndex) {
42
- return false;
43
- }
44
- previousIndex = index;
45
- }
46
- return true;
39
+ return hasCanonicalOrder(APP_LOCALE_CODES, locales);
47
40
  }
48
41
  /** Nonempty unique active locale subset in canonical contract order. */
49
42
  export const ActiveAppLocaleListSchema = Schema.NonEmptyArray(AppLocaleSchema).pipe(Schema.check(Schema.makeFilter(hasCanonicalActiveAppLocales, {
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
- ].some((measure) => boundedMeasureUnresolved(measure, threshold));
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 = [];
71
- for (const [index, value] of values.entries()) {
70
+ const duplicates = MutableList.make();
71
+ Arr.forEach(values, (value, index) => {
72
72
  const key = keyOf(value);
73
73
  if (MutableHashSet.has(seen, key)) {
74
- duplicates.push(index);
74
+ MutableList.append(duplicates, index);
75
75
  }
76
76
  else {
77
77
  MutableHashSet.add(seen, key);
78
78
  }
79
- }
80
- return duplicates;
79
+ });
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(objects.map(({ id }) => id));
84
+ const objectIds = HashSet.fromIterable(Arr.map(objects, ({ id }) => id));
85
85
  return [
86
- ...duplicateKeyIndexes(objects, ({ id }) => id).map((index) => ({
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).map((index) => ({
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
- ...labels.flatMap((label, index) => HashSet.has(objectIds, label.objectId)
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 values.every((value, index) => values.findIndex((candidate) => same(value, candidate)) === index);
106
+ return Arr.every(values, (value, index) => Option.contains(Arr.findFirstIndex(values, (candidate) => same(value, candidate)), index));
107
107
  }
@@ -1,4 +1,4 @@
1
- import type { Schema } from "effect";
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. */
@@ -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
- ].every(({ coordinate, range }) => axisContains(range, coordinate));
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
- ].every(({ coordinate, range }) => axisContains(range, coordinate));
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].every((point) => planeContains(frame, point));
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.every((point) => planeContains(frame, point));
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].every((point) => spaceContains(frame, point));
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.every((point) => spaceContains(frame, point));
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
- ...objects.flatMap((object, index) => planeObjectContained(frame, object)
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
- ...labels.flatMap((label, index) => planeContains(frame, label.at)
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
- ...objects.flatMap((object, index) => spaceObjectContained(frame, object)
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
- ...labels.flatMap((label, index) => spaceContains(frame, label.at)
122
+ ...Arr.flatMap(labels, (label, index) => spaceContains(frame, label.at)
122
123
  ? []
123
124
  : [
124
125
  {
@@ -1,4 +1,4 @@
1
- import { Array as Arr, MutableHashMap, MutableHashSet, Option, } from "effect";
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(axes.flatMap((axis) => {
18
- const entries = coordinates.filter((entry) => entry.axis === axis);
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 entries.flatMap((entry, index) => entry.reportable && MutableHashSet.has(unresolved, index)
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 groups = MutableHashMap.empty();
28
- for (const [index, object] of objects.entries()) {
29
- if (object.kind !== "arc" && object.kind !== "circle") {
30
- continue;
31
- }
32
- const key = `${object.center.x}:${object.center.y}`;
33
- const group = Option.getOrUndefined(MutableHashMap.get(groups, key)) ?? [];
34
- group.push({ index, kind: object.kind, value: numberRatio(object.radius) });
35
- MutableHashMap.set(groups, key, group);
36
- }
37
- const paths = [];
38
- for (const group of MutableHashMap.values(groups)) {
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
- for (const [entryIndex, entry] of group.entries()) {
41
- if (MutableHashSet.has(unresolved, entryIndex)) {
42
- paths.push(radialGeometryPath(entry.kind, entry.index));
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
  }
@@ -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 axes.flatMap(([axis, range]) => [
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].flatMap((parameter) => axes.map((axis) => sceneCoordinate(axis.axis, path, affineRatio(axis.start, axis.through, parameter))));
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
  }
@@ -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].map((angle) => arcOffset(object.radius, angle));
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
- for (const angle of [0, 90, 180, 270]) {
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).every((offset) => axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
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).every((offset) => axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
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].map((input) => ({
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].every((input) => axisContains(inputRange, input))) {
116
+ if (!Arr.every([object.domain.min, object.domain.max], (input) => axisContains(inputRange, input))) {
121
117
  return false;
122
118
  }
123
- return quadraticExtrema(object).every(({ output }) => ratioInRange(output, outputRange.min, outputRange.max));
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).every(({ axis, center, extent }) => axisContainsTranslated(frame[axis], center, extent, ZERO) &&
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
  }
@@ -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";
@@ -12,7 +12,7 @@ function hasPlaneArea(vertices) {
12
12
  let twiceArea = 0;
13
13
  let termMagnitude = 0;
14
14
  let previous = { x: 0, y: 0 };
15
- for (const current of offsets.slice(1)) {
15
+ for (const current of Arr.drop(offsets, 1)) {
16
16
  const positive = previous.x * current.y;
17
17
  const negative = previous.y * current.x;
18
18
  twiceArea += positive - negative;
@@ -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 = vertices.map(({ x, y }) => ({
27
+ let offsets = Arr.map(vertices, ({ x, y }) => ({
28
28
  x: x - origin.x,
29
29
  y: y - origin.y,
30
30
  }));
31
- if (offsets.some(({ x, y }) => !(Number.isFinite(x) && Number.isFinite(y)))) {
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 = vertices.map(({ x, y }) => ({
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 offsets.map(({ x, y }) => ({ x: x / divisor, y: y / divisor }));
46
+ return Arr.map(offsets, ({ x, y }) => ({ x: x / divisor, y: y / divisor }));
47
47
  }
48
48
  const PlanePointObjectSchema = Schema.Struct({
49
49
  ...ObjectFields,
@@ -72,13 +72,13 @@ 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 = vertices.map((point) => ({
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),
79
79
  }));
80
80
  const thresholdSquared = BigDecimal.multiply(threshold, threshold);
81
- for (const [index, point] of exact.entries()) {
81
+ return EffectArray.some(exact, (point, index) => {
82
82
  const previous = EffectArray.getUnsafe(exact, (index + exact.length - 1) % exact.length);
83
83
  const next = EffectArray.getUnsafe(exact, (index + 1) % exact.length);
84
84
  const baseline = {
@@ -96,16 +96,13 @@ 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).map((value) => BigDecimal.multiply(value, value)));
99
+ const crossSquared = BigDecimal.sumAll(EffectArray.map(Rec.values(cross), (value) => BigDecimal.multiply(value, value)));
100
100
  if (BigDecimal.isZero(crossSquared)) {
101
- continue;
102
- }
103
- const baselineSquared = BigDecimal.sumAll(Rec.values(baseline).map((value) => BigDecimal.multiply(value, value)));
104
- if (BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared))) {
105
- return true;
101
+ return false;
106
102
  }
107
- }
108
- return false;
103
+ const baselineSquared = BigDecimal.sumAll(EffectArray.map(Rec.values(baseline), (value) => BigDecimal.multiply(value, value)));
104
+ return BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared));
105
+ });
109
106
  }
110
107
  /** Checks exact quadratic curvature without relying on renderer sampling. */
111
108
  export function quadraticCurvatureUnresolved(coefficient, domainSpan, threshold) {
@@ -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 ordered = values
47
- .map((value, sourceIndex) => ({ sourceIndex, value }))
48
- .sort((left, right) => compareRatios(left.value, right.value));
49
- const distinct = [];
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
- const previous = distinct.at(-1);
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
- distinct.push(entry.value);
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,13 +132,13 @@ 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 = entries.map(exactInterval);
133
- const lower = rankRatios(intervals.map((entry) => entry.lower));
134
- const upper = rankRatios(intervals.map((entry) => entry.upper));
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();
138
- for (const [sourceIndex, interval] of intervals.entries()) {
141
+ EffectArray.forEach(intervals, (interval, sourceIndex) => {
139
142
  const leftEnd = firstRank(upper.values, interval.lower, false);
140
143
  const closestLeft = queryTree(leftTree, 0, leftEnd, greaterRatio);
141
144
  const rightStart = firstRank(lower.values, interval.upper, true);
@@ -150,6 +153,6 @@ export function unresolvedProximityIndexes(entries, threshold) {
150
153
  }
151
154
  updateTree(leftTree, EffectArray.getUnsafe(upper.ranks, sourceIndex), interval.lower, greaterRatio);
152
155
  updateTree(rightTree, EffectArray.getUnsafe(lower.ranks, sourceIndex), interval.upper, lesserRatio);
153
- }
156
+ });
154
157
  return unresolved;
155
158
  }
@@ -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 entries.flatMap(({ axis, range }) => spanUnresolved(range, threshold) ? [issue(["frame", axis])] : []);
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).map(issue),
91
- ...concentricRadiusCollisionPaths(objects, threshold).map(issue),
92
- ...objects.flatMap((object, index) => planeObjectIssues(frame, object, index, threshold)),
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).map(issue),
116
- ...objects.flatMap((object, index) => objectResolutionIssues(frame, object, index, threshold)),
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
  }
@@ -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).flatMap((offset) => [
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).flatMap(({ input, output }) => [
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).flatMap(({ axis, center, dimension, extent }) => [
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.flatMap((point, pointIndex) => pointCoordinates(point, [...root, "vertices", pointIndex]));
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 labels.flatMap((label, index) => pointCoordinates(label.at, ["labels", index, "at"]));
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
- ...objects.flatMap((object, index) => objectCoordinates(frame, object, index, threshold)),
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
- ...objects.flatMap((object, index) => objectCoordinates(frame, object, index, threshold)),
112
+ ...Arr.flatMap(objects, (object, index) => objectCoordinates(frame, object, index, threshold)),
113
113
  ...labelCoordinates(labels),
114
114
  ];
115
115
  }