@nakafa/aksara-contracts 5.0.0 → 6.1.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.
Files changed (99) hide show
  1. package/dist/artifact/integrity.d.ts +2 -2
  2. package/dist/artifact/limits.d.ts +1 -1
  3. package/dist/artifact/source.d.ts +1 -1
  4. package/dist/artifact/spec.d.ts +1 -1
  5. package/dist/artifact/verify.d.ts +1 -1
  6. package/dist/assessment/catalog.d.ts +12 -12
  7. package/dist/assessment/figure.d.ts +468 -0
  8. package/dist/assessment/snapshot.d.ts +24 -24
  9. package/dist/content.d.ts +7 -7
  10. package/dist/graph/family.d.ts +2 -2
  11. package/dist/graph/identity.d.ts +1 -1
  12. package/dist/locale.d.ts +21 -10
  13. package/dist/locale.js +24 -9
  14. package/dist/math/bounds.d.ts +3 -2
  15. package/dist/math/bounds.js +37 -8
  16. package/dist/math/curve.d.ts +42 -0
  17. package/dist/math/curve.js +55 -0
  18. package/dist/math/formula/box.d.ts +61 -0
  19. package/dist/math/formula/box.js +68 -0
  20. package/dist/math/formula/compile.d.ts +11 -0
  21. package/dist/math/formula/compile.js +100 -0
  22. package/dist/math/formula/contour.d.ts +17 -0
  23. package/dist/math/formula/contour.js +162 -0
  24. package/dist/math/formula/field.d.ts +19 -0
  25. package/dist/math/formula/field.js +35 -0
  26. package/dist/math/formula/mesh.d.ts +25 -0
  27. package/dist/math/formula/mesh.js +28 -0
  28. package/dist/math/formula/names.d.ts +4 -0
  29. package/dist/math/formula/names.js +23 -0
  30. package/dist/math/formula/parse.d.ts +10 -0
  31. package/dist/math/formula/parse.js +240 -0
  32. package/dist/math/formula/plane.d.ts +62 -0
  33. package/dist/math/formula/plane.js +175 -0
  34. package/dist/math/formula/reader.d.ts +102 -0
  35. package/dist/math/formula/reader.js +58 -0
  36. package/dist/math/formula/sample.d.ts +14 -0
  37. package/dist/math/formula/sample.js +182 -0
  38. package/dist/math/formula/scope.d.ts +37 -0
  39. package/dist/math/formula/scope.js +137 -0
  40. package/dist/math/formula/space.d.ts +10 -0
  41. package/dist/math/formula/space.js +94 -0
  42. package/dist/math/formula/syntax.d.ts +77 -0
  43. package/dist/math/formula/syntax.js +111 -0
  44. package/dist/math/formula/token.d.ts +43 -0
  45. package/dist/math/formula/token.js +150 -0
  46. package/dist/math/plane.d.ts +85 -0
  47. package/dist/math/plane.js +8 -2
  48. package/dist/math/scene.js +11 -2
  49. package/dist/math/solid.d.ts +124 -0
  50. package/dist/math/solid.js +86 -0
  51. package/dist/math/space.d.ts +213 -0
  52. package/dist/math/space.js +8 -2
  53. package/dist/math/visual.d.ts +454 -0
  54. package/dist/preview/artifact.d.ts +6 -6
  55. package/dist/preview/document.d.ts +13 -13
  56. package/dist/preview/spec.d.ts +49 -49
  57. package/dist/preview/target.d.ts +2 -2
  58. package/dist/program/curriculum.d.ts +2 -2
  59. package/dist/program/snapshot/hash.d.ts +6 -6
  60. package/dist/program/snapshot/row.d.ts +4 -4
  61. package/dist/program/spec.d.ts +2 -2
  62. package/dist/projection/article.d.ts +6 -6
  63. package/dist/projection/digest.d.ts +6 -6
  64. package/dist/projection/hash.d.ts +6 -6
  65. package/dist/projection/material.d.ts +6 -6
  66. package/dist/projection/page.d.ts +6 -6
  67. package/dist/projection/spec.d.ts +7 -7
  68. package/dist/projection/verify.d.ts +6 -6
  69. package/dist/quran/attribution.d.ts +4 -4
  70. package/dist/quran/identity.d.ts +7 -7
  71. package/dist/quran/identity.js +3 -3
  72. package/dist/quran/provenance.d.ts +12 -12
  73. package/dist/quran/snapshot/row/hash.d.ts +39 -39
  74. package/dist/quran/snapshot/row.d.ts +12 -12
  75. package/dist/quran/source.d.ts +7 -7
  76. package/dist/quran/spec.d.ts +1 -1
  77. package/dist/quran/spec.js +3 -3
  78. package/dist/release/canonical.d.ts +2 -2
  79. package/dist/release/digest.d.ts +2 -2
  80. package/dist/release/head.d.ts +9 -9
  81. package/dist/release/items.d.ts +2 -2
  82. package/dist/release/result/digest.d.ts +5 -5
  83. package/dist/release/rollback/digest.d.ts +4 -4
  84. package/dist/release/rollback/spec.d.ts +66 -66
  85. package/dist/release/route/digest.d.ts +2 -2
  86. package/dist/release/route/page.d.ts +4 -4
  87. package/dist/release/route/spec.d.ts +6 -6
  88. package/dist/release/route/verify.d.ts +2 -2
  89. package/dist/release/snapshot/data.d.ts +12 -12
  90. package/dist/release/snapshot/verify.d.ts +22 -22
  91. package/dist/release/spec.d.ts +6 -6
  92. package/dist/runtime/spec.d.ts +23 -23
  93. package/dist/runtime/verify.d.ts +14 -14
  94. package/dist/transport/batch.d.ts +22 -22
  95. package/dist/transport/group.d.ts +69 -69
  96. package/dist/transport/request.d.ts +244 -244
  97. package/dist/transport/response.d.ts +92 -92
  98. package/dist/transport/snapshot.d.ts +24 -24
  99. package/package.json +57 -1
@@ -0,0 +1,43 @@
1
+ import { Result, Schema } from "effect";
2
+ import { FormulaError } from "#contracts/math/formula/syntax";
3
+ /** One token of a formula and the index of its first character. */
4
+ export declare const FormulaTokenSchema: Schema.Union<readonly [Schema.Struct<{
5
+ readonly kind: Schema.Literal<"number">;
6
+ readonly position: Schema.Int;
7
+ readonly value: Schema.Finite;
8
+ }>, Schema.Struct<{
9
+ readonly kind: Schema.Literal<"name">;
10
+ readonly name: Schema.String;
11
+ readonly position: Schema.Int;
12
+ }>, Schema.Struct<{
13
+ readonly kind: Schema.Literal<"symbol">;
14
+ readonly position: Schema.Int;
15
+ readonly symbol: Schema.Literals<readonly ["(", ")", "*", "+", ",", "-", "/", "^", "_", "|", "°", "√"]>;
16
+ }>, Schema.Struct<{
17
+ readonly comparison: Schema.Literals<readonly ["=", "<", "<=", ">", ">="]>;
18
+ readonly kind: Schema.Literal<"comparison">;
19
+ readonly position: Schema.Int;
20
+ }>]>;
21
+ export type FormulaToken = typeof FormulaTokenSchema.Type;
22
+ /**
23
+ * Reads a formula into tokens. Letters split into the longest known words, so
24
+ * `2xy` reads as two, x, y and `sinh` as one function; π and θ read as `pi`
25
+ * and `theta`, and ² and ³ as powers.
26
+ */
27
+ export declare function tokenizeFormula(text: string): Result.Result<never, FormulaError> | Result.Result<({
28
+ readonly kind: "number";
29
+ readonly position: number;
30
+ readonly value: number;
31
+ } | {
32
+ readonly kind: "name";
33
+ readonly name: string;
34
+ readonly position: number;
35
+ } | {
36
+ readonly kind: "symbol";
37
+ readonly position: number;
38
+ readonly symbol: "(" | ")" | "*" | "+" | "," | "-" | "/" | "^" | "_" | "|" | "°" | "√";
39
+ } | {
40
+ readonly comparison: "<" | "<=" | "=" | ">" | ">=";
41
+ readonly kind: "comparison";
42
+ readonly position: number;
43
+ })[], never>;
@@ -0,0 +1,150 @@
1
+ import { Array as Arr, MutableList, Option, Order, Record as Rec, Result, Schema, } from "effect";
2
+ import { FORMULA_CONSTANTS, FormulaComparisonSchema, FormulaError, FormulaFunctionSchema, } from "#contracts/math/formula/syntax";
3
+ /** Symbols a formula writes between its numbers and names. */
4
+ const FormulaSymbolSchema = Schema.Literals([
5
+ "(",
6
+ ")",
7
+ "*",
8
+ "+",
9
+ ",",
10
+ "-",
11
+ "/",
12
+ "^",
13
+ "_",
14
+ "|",
15
+ "°",
16
+ "√",
17
+ ]);
18
+ /** One token of a formula and the index of its first character. */
19
+ export const FormulaTokenSchema = Schema.Union([
20
+ Schema.Struct({
21
+ kind: Schema.Literal("number"),
22
+ position: Schema.Int,
23
+ value: Schema.Finite,
24
+ }),
25
+ Schema.Struct({
26
+ kind: Schema.Literal("name"),
27
+ name: Schema.String,
28
+ position: Schema.Int,
29
+ }),
30
+ Schema.Struct({
31
+ kind: Schema.Literal("symbol"),
32
+ position: Schema.Int,
33
+ symbol: FormulaSymbolSchema,
34
+ }),
35
+ Schema.Struct({
36
+ comparison: FormulaComparisonSchema,
37
+ kind: Schema.Literal("comparison"),
38
+ position: Schema.Int,
39
+ }),
40
+ ]);
41
+ /** Every word longer than one letter, longest first, so `sinh` wins over `sin`. */
42
+ const WORDS = Arr.sort(Arr.filter([
43
+ ...FormulaFunctionSchema.literals,
44
+ ...Rec.keys(FORMULA_CONSTANTS),
45
+ "theta",
46
+ ], (word) => word.length > 1), Order.flip(Order.mapInput(Order.Number, (word) => word.length)));
47
+ /** Typed and Unicode spellings of each symbol, two-character ones first. */
48
+ const SPELLINGS = [
49
+ ["<=", { comparison: "<=", kind: "comparison", position: 0 }],
50
+ [">=", { comparison: ">=", kind: "comparison", position: 0 }],
51
+ ["≤", { comparison: "<=", kind: "comparison", position: 0 }],
52
+ ["≥", { comparison: ">=", kind: "comparison", position: 0 }],
53
+ ["<", { comparison: "<", kind: "comparison", position: 0 }],
54
+ [">", { comparison: ">", kind: "comparison", position: 0 }],
55
+ ["=", { comparison: "=", kind: "comparison", position: 0 }],
56
+ ["×", symbol("*")],
57
+ ["·", symbol("*")],
58
+ ["÷", symbol("/")],
59
+ ["−", symbol("-")],
60
+ ...Arr.map(FormulaSymbolSchema.literals, (each) => [
61
+ each,
62
+ symbol(each),
63
+ ]),
64
+ ];
65
+ /** Superscript digits read as a power of that digit. */
66
+ const SUPERSCRIPTS = { "²": 2, "³": 3 };
67
+ const DIGITS = /^(?:\d+(?:\.\d+)?|\.\d+)/u;
68
+ const LETTERS = /^[a-z]+/u;
69
+ const SPACE = /\s/u;
70
+ /** Builds one symbol token before its position is known. */
71
+ function symbol(each) {
72
+ return { kind: "symbol", position: 0, symbol: each };
73
+ }
74
+ /** Splits a run of letters into the longest known words and single letters. */
75
+ function splitLetters(run, start) {
76
+ const names = MutableList.make();
77
+ let index = 0;
78
+ while (index < run.length) {
79
+ const rest = run.slice(index);
80
+ const word = Option.getOrElse(Arr.findFirst(WORDS, (each) => rest.startsWith(each)), () => rest.charAt(0));
81
+ MutableList.append(names, {
82
+ kind: "name",
83
+ name: word,
84
+ position: start + index,
85
+ });
86
+ index += word.length;
87
+ }
88
+ return MutableList.toArray(names);
89
+ }
90
+ /**
91
+ * Reads a formula into tokens. Letters split into the longest known words, so
92
+ * `2xy` reads as two, x, y and `sinh` as one function; π and θ read as `pi`
93
+ * and `theta`, and ² and ³ as powers.
94
+ */
95
+ export function tokenizeFormula(text) {
96
+ const tokens = MutableList.make();
97
+ let index = 0;
98
+ while (index < text.length) {
99
+ const rest = text.slice(index);
100
+ const character = rest.charAt(0);
101
+ if (SPACE.test(character)) {
102
+ index += 1;
103
+ continue;
104
+ }
105
+ const digits = DIGITS.exec(rest);
106
+ if (digits) {
107
+ MutableList.append(tokens, {
108
+ kind: "number",
109
+ position: index,
110
+ value: Number(digits[0]),
111
+ });
112
+ index += digits[0].length;
113
+ continue;
114
+ }
115
+ const letters = LETTERS.exec(rest);
116
+ if (letters) {
117
+ MutableList.appendAll(tokens, splitLetters(letters[0], index));
118
+ index += letters[0].length;
119
+ continue;
120
+ }
121
+ if (character === "π" || character === "θ") {
122
+ const name = character === "π" ? "pi" : "theta";
123
+ MutableList.append(tokens, { kind: "name", name, position: index });
124
+ index += 1;
125
+ continue;
126
+ }
127
+ if (character === "²" || character === "³") {
128
+ MutableList.append(tokens, { ...symbol("^"), position: index });
129
+ MutableList.append(tokens, {
130
+ kind: "number",
131
+ position: index,
132
+ value: SUPERSCRIPTS[character],
133
+ });
134
+ index += 1;
135
+ continue;
136
+ }
137
+ const spelling = Arr.findFirst(SPELLINGS, ([spelled]) => rest.startsWith(spelled));
138
+ if (Option.isNone(spelling)) {
139
+ return Result.fail(new FormulaError({
140
+ message: `Unexpected "${character}" at ${index}.`,
141
+ position: index,
142
+ problem: "symbol-unexpected",
143
+ }));
144
+ }
145
+ const [written, token] = spelling.value;
146
+ MutableList.append(tokens, { ...token, position: index });
147
+ index += written.length;
148
+ }
149
+ return Result.succeed(MutableList.toArray(tokens));
150
+ }
@@ -1,6 +1,45 @@
1
1
  import { Schema } from "effect";
2
2
  /** Mathematical objects supported by a Cartesian plane scene. */
3
3
  export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct<{
4
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
5
+ readonly id: Schema.String;
6
+ readonly domain: Schema.optionalKey<Schema.Struct<{
7
+ readonly max: Schema.Finite;
8
+ readonly min: Schema.Finite;
9
+ }>>;
10
+ readonly formula: Schema.String;
11
+ readonly inputAxis: Schema.optionalKey<Schema.Literals<readonly ["x", "y"]>>;
12
+ readonly kind: Schema.Literal<"function">;
13
+ }>, Schema.Struct<{
14
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
15
+ readonly id: Schema.String;
16
+ readonly equation: Schema.String;
17
+ readonly kind: Schema.Literal<"implicit">;
18
+ }>, Schema.Struct<{
19
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
20
+ readonly id: Schema.String;
21
+ readonly kind: Schema.Literal<"parametric">;
22
+ readonly parameter: Schema.Struct<{
23
+ readonly max: Schema.Finite;
24
+ readonly min: Schema.Finite;
25
+ }>;
26
+ readonly x: Schema.String;
27
+ readonly y: Schema.String;
28
+ }>, Schema.Struct<{
29
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
30
+ readonly id: Schema.String;
31
+ readonly angle: Schema.Struct<{
32
+ readonly max: Schema.Finite;
33
+ readonly min: Schema.Finite;
34
+ }>;
35
+ readonly kind: Schema.Literal<"polar">;
36
+ readonly radius: Schema.String;
37
+ }>, Schema.Struct<{
38
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
39
+ readonly id: Schema.String;
40
+ readonly inequalities: Schema.NonEmptyArray<Schema.String>;
41
+ readonly kind: Schema.Literal<"region">;
42
+ }>, Schema.Struct<{
4
43
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
5
44
  readonly id: Schema.String;
6
45
  readonly center: Schema.Struct<{
@@ -163,6 +202,45 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
163
202
  readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
164
203
  }>>>;
165
204
  readonly objects: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
205
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
206
+ readonly id: Schema.String;
207
+ readonly domain: Schema.optionalKey<Schema.Struct<{
208
+ readonly max: Schema.Finite;
209
+ readonly min: Schema.Finite;
210
+ }>>;
211
+ readonly formula: Schema.String;
212
+ readonly inputAxis: Schema.optionalKey<Schema.Literals<readonly ["x", "y"]>>;
213
+ readonly kind: Schema.Literal<"function">;
214
+ }>, Schema.Struct<{
215
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
216
+ readonly id: Schema.String;
217
+ readonly equation: Schema.String;
218
+ readonly kind: Schema.Literal<"implicit">;
219
+ }>, Schema.Struct<{
220
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
221
+ readonly id: Schema.String;
222
+ readonly kind: Schema.Literal<"parametric">;
223
+ readonly parameter: Schema.Struct<{
224
+ readonly max: Schema.Finite;
225
+ readonly min: Schema.Finite;
226
+ }>;
227
+ readonly x: Schema.String;
228
+ readonly y: Schema.String;
229
+ }>, Schema.Struct<{
230
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
231
+ readonly id: Schema.String;
232
+ readonly angle: Schema.Struct<{
233
+ readonly max: Schema.Finite;
234
+ readonly min: Schema.Finite;
235
+ }>;
236
+ readonly kind: Schema.Literal<"polar">;
237
+ readonly radius: Schema.String;
238
+ }>, Schema.Struct<{
239
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
240
+ readonly id: Schema.String;
241
+ readonly inequalities: Schema.NonEmptyArray<Schema.String>;
242
+ readonly kind: Schema.Literal<"region">;
243
+ }>, Schema.Struct<{
166
244
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
167
245
  readonly id: Schema.String;
168
246
  readonly center: Schema.Struct<{
@@ -271,6 +349,13 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
271
349
  readonly y: Schema.Finite;
272
350
  }>;
273
351
  }>]>>;
352
+ readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
353
+ readonly max: Schema.Finite;
354
+ readonly min: Schema.Finite;
355
+ readonly name: Schema.String;
356
+ readonly step: Schema.optionalKey<Schema.Finite>;
357
+ readonly value: Schema.Finite;
358
+ }>>>;
274
359
  readonly space: Schema.Literal<"plane">;
275
360
  readonly view: Schema.Struct<{
276
361
  readonly kind: Schema.Literal<"fit">;
@@ -1,6 +1,9 @@
1
1
  import { Array as Arr, Schema } from "effect";
2
2
  import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAxisRangeSchema, MathViewPaddingSchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
3
3
  import { planeBoundsIssues } from "#contracts/math/bounds";
4
+ import { PlaneCurveObjectSchemas } from "#contracts/math/curve";
5
+ import { FormulaParameterSchema } from "#contracts/math/formula/field";
6
+ import { formulaScopeIssues, parameterScope, planeFormulaFields, } from "#contracts/math/formula/scope";
4
7
  import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
5
8
  import { planeResolutionIssues } from "#contracts/math/resolution";
6
9
  /** Checks a plane polygon has non-zero signed area. */
@@ -111,6 +114,7 @@ const PlaneQuadraticObjectSchema = Schema.Struct({
111
114
  });
112
115
  /** Mathematical objects supported by a Cartesian plane scene. */
113
116
  export const PlaneMathObjectSchema = Schema.Union([
117
+ ...PlaneCurveObjectSchemas,
114
118
  PlaneArcObjectSchema,
115
119
  PlaneCircleObjectSchema,
116
120
  PlaneLineObjectSchema,
@@ -139,10 +143,12 @@ export const PlaneMathVisualSchema = Schema.Struct({
139
143
  frame: PlaneMathFrameSchema,
140
144
  labels: Schema.optionalKey(Schema.Array(PlaneLabelAnchorSchema)),
141
145
  objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
146
+ parameters: Schema.optionalKey(Schema.Array(FormulaParameterSchema)),
142
147
  space: Schema.Literal("plane"),
143
148
  view: PlaneMathViewSchema,
144
- }).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, view }) => [
149
+ }).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, parameters = [], view }) => [
145
150
  ...mathVisualIdentityIssues(objects, labels),
146
- ...planeBoundsIssues(frame, objects, labels),
151
+ ...formulaScopeIssues(objects, planeFormulaFields, parameters),
152
+ ...planeBoundsIssues(frame, objects, labels, parameterScope(parameters)),
147
153
  ...planeResolutionIssues(frame, objects, labels, view),
148
154
  ])));
@@ -47,7 +47,10 @@ function cuboidCoordinates(object, path) {
47
47
  ]),
48
48
  ];
49
49
  }
50
- /** Projects every finite or frame-clipped coordinate of one scene object. */
50
+ /**
51
+ * Projects every finite or frame-clipped coordinate of one scene object. A
52
+ * formula object authors no coordinate: its samples come from its formula.
53
+ */
51
54
  function objectCoordinates(frame, object, index, threshold) {
52
55
  const root = ["objects", index];
53
56
  if (object.kind === "point") {
@@ -78,7 +81,13 @@ function objectCoordinates(frame, object, index, threshold) {
78
81
  if (object.kind === "quadratic") {
79
82
  return quadraticCoordinates(object, root, threshold);
80
83
  }
81
- return cuboidCoordinates(object, root);
84
+ if (object.kind === "prism" || object.kind === "pyramid") {
85
+ return Arr.flatMap(object.base, (point, pointIndex) => pointCoordinates(point, [...root, "base", pointIndex]));
86
+ }
87
+ if (object.kind === "cuboid") {
88
+ return cuboidCoordinates(object, root);
89
+ }
90
+ return [];
82
91
  }
83
92
  /** Projects all label anchors after the objects they annotate. */
84
93
  function labelCoordinates(labels) {
@@ -0,0 +1,124 @@
1
+ import { Schema } from "effect";
2
+ /** A base face: three or more coplanar corners of one simple polygon. */
3
+ export declare const SpaceFaceSchema: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
4
+ readonly x: Schema.Finite;
5
+ readonly y: Schema.Finite;
6
+ readonly z: Schema.Finite;
7
+ }>, Schema.Struct<{
8
+ readonly x: Schema.Finite;
9
+ readonly y: Schema.Finite;
10
+ readonly z: Schema.Finite;
11
+ }>, Schema.Struct<{
12
+ readonly x: Schema.Finite;
13
+ readonly y: Schema.Finite;
14
+ readonly z: Schema.Finite;
15
+ }>]>, readonly [Schema.Struct<{
16
+ readonly x: Schema.Finite;
17
+ readonly y: Schema.Finite;
18
+ readonly z: Schema.Finite;
19
+ }>]>;
20
+ /** The space objects a formula or a face defines. */
21
+ export declare const SpaceSolidObjectSchemas: readonly [Schema.Struct<{
22
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
23
+ readonly id: Schema.String;
24
+ readonly domain: Schema.optionalKey<Schema.Struct<{
25
+ readonly x: Schema.Struct<{
26
+ readonly max: Schema.Finite;
27
+ readonly min: Schema.Finite;
28
+ }>;
29
+ readonly y: Schema.Struct<{
30
+ readonly max: Schema.Finite;
31
+ readonly min: Schema.Finite;
32
+ }>;
33
+ }>>;
34
+ readonly formula: Schema.String;
35
+ readonly kind: Schema.Literal<"function">;
36
+ }>, Schema.Struct<{
37
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
38
+ readonly id: Schema.String;
39
+ readonly kind: Schema.Literal<"parametric">;
40
+ readonly parameter: Schema.Struct<{
41
+ readonly max: Schema.Finite;
42
+ readonly min: Schema.Finite;
43
+ }>;
44
+ readonly x: Schema.String;
45
+ readonly y: Schema.String;
46
+ readonly z: Schema.String;
47
+ }>, Schema.Struct<{
48
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
49
+ readonly id: Schema.String;
50
+ readonly base: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
51
+ readonly x: Schema.Finite;
52
+ readonly y: Schema.Finite;
53
+ readonly z: Schema.Finite;
54
+ }>, Schema.Struct<{
55
+ readonly x: Schema.Finite;
56
+ readonly y: Schema.Finite;
57
+ readonly z: Schema.Finite;
58
+ }>, Schema.Struct<{
59
+ readonly x: Schema.Finite;
60
+ readonly y: Schema.Finite;
61
+ readonly z: Schema.Finite;
62
+ }>]>, readonly [Schema.Struct<{
63
+ readonly x: Schema.Finite;
64
+ readonly y: Schema.Finite;
65
+ readonly z: Schema.Finite;
66
+ }>]>;
67
+ readonly kind: Schema.Literal<"prism">;
68
+ readonly offset: Schema.Struct<{
69
+ readonly x: Schema.Finite;
70
+ readonly y: Schema.Finite;
71
+ readonly z: Schema.Finite;
72
+ }>;
73
+ }>, Schema.Struct<{
74
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
75
+ readonly id: Schema.String;
76
+ readonly apex: Schema.Struct<{
77
+ readonly x: Schema.Finite;
78
+ readonly y: Schema.Finite;
79
+ readonly z: Schema.Finite;
80
+ }>;
81
+ readonly base: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
82
+ readonly x: Schema.Finite;
83
+ readonly y: Schema.Finite;
84
+ readonly z: Schema.Finite;
85
+ }>, Schema.Struct<{
86
+ readonly x: Schema.Finite;
87
+ readonly y: Schema.Finite;
88
+ readonly z: Schema.Finite;
89
+ }>, Schema.Struct<{
90
+ readonly x: Schema.Finite;
91
+ readonly y: Schema.Finite;
92
+ readonly z: Schema.Finite;
93
+ }>]>, readonly [Schema.Struct<{
94
+ readonly x: Schema.Finite;
95
+ readonly y: Schema.Finite;
96
+ readonly z: Schema.Finite;
97
+ }>]>;
98
+ readonly kind: Schema.Literal<"pyramid">;
99
+ }>, Schema.Struct<{
100
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
101
+ readonly id: Schema.String;
102
+ readonly axis: Schema.Literals<readonly ["x", "y", "z"]>;
103
+ readonly domain: Schema.Struct<{
104
+ readonly max: Schema.Finite;
105
+ readonly min: Schema.Finite;
106
+ }>;
107
+ readonly formula: Schema.String;
108
+ readonly kind: Schema.Literal<"revolution">;
109
+ }>, Schema.Struct<{
110
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
111
+ readonly id: Schema.String;
112
+ readonly kind: Schema.Literal<"surface">;
113
+ readonly u: Schema.Struct<{
114
+ readonly max: Schema.Finite;
115
+ readonly min: Schema.Finite;
116
+ }>;
117
+ readonly v: Schema.Struct<{
118
+ readonly max: Schema.Finite;
119
+ readonly min: Schema.Finite;
120
+ }>;
121
+ readonly x: Schema.String;
122
+ readonly y: Schema.String;
123
+ readonly z: Schema.String;
124
+ }>];
@@ -0,0 +1,86 @@
1
+ import { Schema } from "effect";
2
+ import { hasUniquePositions, MathAxisRangeSchema, SpacePointSchema, sameSpacePoint, } from "#contracts/math/base";
3
+ import { FormulaTextSchema } from "#contracts/math/formula/field";
4
+ import { MathObjectFields } from "#contracts/math/object";
5
+ import { hasCoplanarArea } from "#contracts/math/vector";
6
+ /** Whether a face has unique corners that lie in one plane and enclose area. */
7
+ function flatFace(base) {
8
+ return hasUniquePositions(base, sameSpacePoint) && hasCoplanarArea(base);
9
+ }
10
+ /** Whether a point stands off the plane of a flat face. */
11
+ function offPlane(base, point) {
12
+ return !hasCoplanarArea([...base, point]);
13
+ }
14
+ /** A base face: three or more coplanar corners of one simple polygon. */
15
+ export const SpaceFaceSchema = Schema.TupleWithRest(Schema.Tuple([SpacePointSchema, SpacePointSchema, SpacePointSchema]), [SpacePointSchema]);
16
+ /** A space curve traced by x(t), y(t), and z(t), such as a helix. */
17
+ const SpaceParametricObjectSchema = Schema.Struct({
18
+ ...MathObjectFields,
19
+ kind: Schema.Literal("parametric"),
20
+ parameter: MathAxisRangeSchema,
21
+ x: FormulaTextSchema,
22
+ y: FormulaTextSchema,
23
+ z: FormulaTextSchema,
24
+ });
25
+ /** The surface z = f(x, y), over its domain or, without one, the frame. */
26
+ const SpaceFunctionObjectSchema = Schema.Struct({
27
+ ...MathObjectFields,
28
+ domain: Schema.optionalKey(Schema.Struct({ x: MathAxisRangeSchema, y: MathAxisRangeSchema })),
29
+ formula: FormulaTextSchema,
30
+ kind: Schema.Literal("function"),
31
+ });
32
+ /** A surface traced by x(u, v), y(u, v), and z(u, v), such as a sphere or torus. */
33
+ const SpaceSurfaceObjectSchema = Schema.Struct({
34
+ ...MathObjectFields,
35
+ kind: Schema.Literal("surface"),
36
+ u: MathAxisRangeSchema,
37
+ v: MathAxisRangeSchema,
38
+ x: FormulaTextSchema,
39
+ y: FormulaTextSchema,
40
+ z: FormulaTextSchema,
41
+ });
42
+ /**
43
+ * The solid a profile sweeps as it turns around one axis. The formula gives
44
+ * the radius at each coordinate along that axis and is written in that
45
+ * axis's variable, so a cone about x is `r x / h` and a sphere `sqrt(4 - y^2)`.
46
+ */
47
+ const SpaceRevolutionObjectSchema = Schema.Struct({
48
+ ...MathObjectFields,
49
+ axis: Schema.Literals(["x", "y", "z"]),
50
+ domain: MathAxisRangeSchema,
51
+ formula: FormulaTextSchema,
52
+ kind: Schema.Literal("revolution"),
53
+ });
54
+ /** A prism: its base face moved along an offset that leaves the base's plane. */
55
+ const SpacePrismObjectSchema = Schema.Struct({
56
+ ...MathObjectFields,
57
+ base: SpaceFaceSchema,
58
+ kind: Schema.Literal("prism"),
59
+ offset: SpacePointSchema,
60
+ }).check(Schema.makeFilter(({ base, offset }) => {
61
+ const [first] = base;
62
+ const lifted = {
63
+ x: first.x + offset.x,
64
+ y: first.y + offset.y,
65
+ z: first.z + offset.z,
66
+ };
67
+ return ((flatFace(base) && offPlane(base, lifted)) ||
68
+ "Expected a flat base face and an offset that leaves its plane.");
69
+ }));
70
+ /** A pyramid or cone of straight edges: a base face and an apex off its plane. */
71
+ const SpacePyramidObjectSchema = Schema.Struct({
72
+ ...MathObjectFields,
73
+ apex: SpacePointSchema,
74
+ base: SpaceFaceSchema,
75
+ kind: Schema.Literal("pyramid"),
76
+ }).check(Schema.makeFilter(({ apex, base }) => (flatFace(base) && offPlane(base, apex)) ||
77
+ "Expected a flat base face and an apex off its plane."));
78
+ /** The space objects a formula or a face defines. */
79
+ export const SpaceSolidObjectSchemas = [
80
+ SpaceFunctionObjectSchema,
81
+ SpaceParametricObjectSchema,
82
+ SpacePrismObjectSchema,
83
+ SpacePyramidObjectSchema,
84
+ SpaceRevolutionObjectSchema,
85
+ SpaceSurfaceObjectSchema,
86
+ ];