@nakafa/aksara-contracts 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assessment/figure.d.ts +567 -6
- package/dist/math/bounds.d.ts +3 -2
- package/dist/math/bounds.js +55 -9
- package/dist/math/curve.d.ts +64 -0
- package/dist/math/curve.js +83 -0
- package/dist/math/formula/box.d.ts +61 -0
- package/dist/math/formula/box.js +68 -0
- package/dist/math/formula/compile.d.ts +11 -0
- package/dist/math/formula/compile.js +100 -0
- package/dist/math/formula/contour.d.ts +17 -0
- package/dist/math/formula/contour.js +162 -0
- package/dist/math/formula/field.d.ts +42 -0
- package/dist/math/formula/field.js +54 -0
- package/dist/math/formula/mesh.d.ts +25 -0
- package/dist/math/formula/mesh.js +28 -0
- package/dist/math/formula/names.d.ts +4 -0
- package/dist/math/formula/names.js +23 -0
- package/dist/math/formula/parse.d.ts +10 -0
- package/dist/math/formula/parse.js +240 -0
- package/dist/math/formula/plane.d.ts +75 -0
- package/dist/math/formula/plane.js +121 -0
- package/dist/math/formula/reader.d.ts +102 -0
- package/dist/math/formula/reader.js +58 -0
- package/dist/math/formula/region.d.ts +16 -0
- package/dist/math/formula/region.js +94 -0
- package/dist/math/formula/sample.d.ts +14 -0
- package/dist/math/formula/sample.js +182 -0
- package/dist/math/formula/scope.d.ts +41 -0
- package/dist/math/formula/scope.js +151 -0
- package/dist/math/formula/slider.d.ts +9 -0
- package/dist/math/formula/slider.js +32 -0
- package/dist/math/formula/space.d.ts +10 -0
- package/dist/math/formula/space.js +94 -0
- package/dist/math/formula/syntax.d.ts +77 -0
- package/dist/math/formula/syntax.js +111 -0
- package/dist/math/formula/token.d.ts +43 -0
- package/dist/math/formula/token.js +150 -0
- package/dist/math/plane.d.ts +148 -5
- package/dist/math/plane.js +16 -4
- package/dist/math/scene.js +17 -4
- package/dist/math/solid.d.ts +124 -0
- package/dist/math/solid.js +86 -0
- package/dist/math/space.d.ts +214 -0
- package/dist/math/space.js +8 -2
- package/dist/math/visual.d.ts +545 -3
- package/dist/math/visual.js +12 -2
- package/package.json +57 -1
|
@@ -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
|
+
}
|
package/dist/math/plane.d.ts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
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<"loop">;
|
|
22
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
23
|
+
readonly x: Schema.String;
|
|
24
|
+
readonly y: Schema.String;
|
|
25
|
+
}>>;
|
|
26
|
+
}>, Schema.Struct<{
|
|
27
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
28
|
+
readonly id: Schema.String;
|
|
29
|
+
readonly kind: Schema.Literal<"marker">;
|
|
30
|
+
readonly x: Schema.String;
|
|
31
|
+
readonly y: Schema.String;
|
|
32
|
+
}>, Schema.Struct<{
|
|
33
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
34
|
+
readonly id: Schema.String;
|
|
35
|
+
readonly kind: Schema.Literal<"parametric">;
|
|
36
|
+
readonly parameter: Schema.Struct<{
|
|
37
|
+
readonly max: Schema.Finite;
|
|
38
|
+
readonly min: Schema.Finite;
|
|
39
|
+
}>;
|
|
40
|
+
readonly x: Schema.String;
|
|
41
|
+
readonly y: Schema.String;
|
|
42
|
+
}>, Schema.Struct<{
|
|
43
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
44
|
+
readonly id: Schema.String;
|
|
45
|
+
readonly kind: Schema.Literal<"path">;
|
|
46
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
47
|
+
readonly x: Schema.String;
|
|
48
|
+
readonly y: Schema.String;
|
|
49
|
+
}>>;
|
|
50
|
+
}>, Schema.Struct<{
|
|
51
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
52
|
+
readonly id: Schema.String;
|
|
53
|
+
readonly angle: Schema.Struct<{
|
|
54
|
+
readonly max: Schema.Finite;
|
|
55
|
+
readonly min: Schema.Finite;
|
|
56
|
+
}>;
|
|
57
|
+
readonly kind: Schema.Literal<"polar">;
|
|
58
|
+
readonly radius: Schema.String;
|
|
59
|
+
}>, Schema.Struct<{
|
|
60
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
61
|
+
readonly id: Schema.String;
|
|
62
|
+
readonly inequalities: Schema.NonEmptyArray<Schema.String>;
|
|
63
|
+
readonly kind: Schema.Literal<"region">;
|
|
64
|
+
}>, Schema.Struct<{
|
|
4
65
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
5
66
|
readonly id: Schema.String;
|
|
6
67
|
readonly center: Schema.Struct<{
|
|
@@ -129,12 +190,18 @@ export declare const PlaneMathViewSchema: Schema.Struct<{
|
|
|
129
190
|
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
130
191
|
}>;
|
|
131
192
|
export type PlaneMathView = typeof PlaneMathViewSchema.Type;
|
|
132
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* One coordinate anchor resolved against a separate rich-label map. Its
|
|
195
|
+
* position is exact, or placed by formulas of the sliders so it follows them.
|
|
196
|
+
*/
|
|
133
197
|
export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
134
|
-
readonly at: Schema.Struct<{
|
|
198
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
135
199
|
readonly x: Schema.Finite;
|
|
136
200
|
readonly y: Schema.Finite;
|
|
137
|
-
}
|
|
201
|
+
}>, Schema.Struct<{
|
|
202
|
+
readonly x: Schema.String;
|
|
203
|
+
readonly y: Schema.String;
|
|
204
|
+
}>]>;
|
|
138
205
|
readonly key: Schema.String;
|
|
139
206
|
readonly objectId: Schema.String;
|
|
140
207
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
@@ -154,15 +221,79 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
154
221
|
}>;
|
|
155
222
|
}>;
|
|
156
223
|
readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
157
|
-
readonly at: Schema.Struct<{
|
|
224
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
158
225
|
readonly x: Schema.Finite;
|
|
159
226
|
readonly y: Schema.Finite;
|
|
160
|
-
}
|
|
227
|
+
}>, Schema.Struct<{
|
|
228
|
+
readonly x: Schema.String;
|
|
229
|
+
readonly y: Schema.String;
|
|
230
|
+
}>]>;
|
|
161
231
|
readonly key: Schema.String;
|
|
162
232
|
readonly objectId: Schema.String;
|
|
163
233
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
164
234
|
}>>>;
|
|
165
235
|
readonly objects: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
|
|
236
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
237
|
+
readonly id: Schema.String;
|
|
238
|
+
readonly domain: Schema.optionalKey<Schema.Struct<{
|
|
239
|
+
readonly max: Schema.Finite;
|
|
240
|
+
readonly min: Schema.Finite;
|
|
241
|
+
}>>;
|
|
242
|
+
readonly formula: Schema.String;
|
|
243
|
+
readonly inputAxis: Schema.optionalKey<Schema.Literals<readonly ["x", "y"]>>;
|
|
244
|
+
readonly kind: Schema.Literal<"function">;
|
|
245
|
+
}>, Schema.Struct<{
|
|
246
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
247
|
+
readonly id: Schema.String;
|
|
248
|
+
readonly equation: Schema.String;
|
|
249
|
+
readonly kind: Schema.Literal<"implicit">;
|
|
250
|
+
}>, Schema.Struct<{
|
|
251
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
252
|
+
readonly id: Schema.String;
|
|
253
|
+
readonly kind: Schema.Literal<"loop">;
|
|
254
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
255
|
+
readonly x: Schema.String;
|
|
256
|
+
readonly y: Schema.String;
|
|
257
|
+
}>>;
|
|
258
|
+
}>, Schema.Struct<{
|
|
259
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
260
|
+
readonly id: Schema.String;
|
|
261
|
+
readonly kind: Schema.Literal<"marker">;
|
|
262
|
+
readonly x: Schema.String;
|
|
263
|
+
readonly y: Schema.String;
|
|
264
|
+
}>, Schema.Struct<{
|
|
265
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
266
|
+
readonly id: Schema.String;
|
|
267
|
+
readonly kind: Schema.Literal<"parametric">;
|
|
268
|
+
readonly parameter: Schema.Struct<{
|
|
269
|
+
readonly max: Schema.Finite;
|
|
270
|
+
readonly min: Schema.Finite;
|
|
271
|
+
}>;
|
|
272
|
+
readonly x: Schema.String;
|
|
273
|
+
readonly y: Schema.String;
|
|
274
|
+
}>, Schema.Struct<{
|
|
275
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
276
|
+
readonly id: Schema.String;
|
|
277
|
+
readonly kind: Schema.Literal<"path">;
|
|
278
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
279
|
+
readonly x: Schema.String;
|
|
280
|
+
readonly y: Schema.String;
|
|
281
|
+
}>>;
|
|
282
|
+
}>, Schema.Struct<{
|
|
283
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
284
|
+
readonly id: Schema.String;
|
|
285
|
+
readonly angle: Schema.Struct<{
|
|
286
|
+
readonly max: Schema.Finite;
|
|
287
|
+
readonly min: Schema.Finite;
|
|
288
|
+
}>;
|
|
289
|
+
readonly kind: Schema.Literal<"polar">;
|
|
290
|
+
readonly radius: Schema.String;
|
|
291
|
+
}>, Schema.Struct<{
|
|
292
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
293
|
+
readonly id: Schema.String;
|
|
294
|
+
readonly inequalities: Schema.NonEmptyArray<Schema.String>;
|
|
295
|
+
readonly kind: Schema.Literal<"region">;
|
|
296
|
+
}>, Schema.Struct<{
|
|
166
297
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
167
298
|
readonly id: Schema.String;
|
|
168
299
|
readonly center: Schema.Struct<{
|
|
@@ -271,6 +402,18 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
271
402
|
readonly y: Schema.Finite;
|
|
272
403
|
}>;
|
|
273
404
|
}>]>>;
|
|
405
|
+
readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
406
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
407
|
+
readonly max: Schema.Finite;
|
|
408
|
+
readonly min: Schema.Finite;
|
|
409
|
+
readonly name: Schema.String;
|
|
410
|
+
readonly step: Schema.optionalKey<Schema.Finite>;
|
|
411
|
+
readonly value: Schema.Finite;
|
|
412
|
+
}>>>;
|
|
413
|
+
readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
414
|
+
readonly formula: Schema.String;
|
|
415
|
+
readonly key: Schema.String;
|
|
416
|
+
}>>>;
|
|
274
417
|
readonly space: Schema.Literal<"plane">;
|
|
275
418
|
readonly view: Schema.Struct<{
|
|
276
419
|
readonly kind: Schema.Literal<"fit">;
|
package/dist/math/plane.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
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, FormulaReadoutSchema, PlaneFormulaPointSchema, } from "#contracts/math/formula/field";
|
|
6
|
+
import { formulaScopeIssues, parameterScope, planeFormulaFields, } from "#contracts/math/formula/scope";
|
|
7
|
+
import { sliderFormulaIssues } from "#contracts/math/formula/slider";
|
|
4
8
|
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
|
|
5
9
|
import { planeResolutionIssues } from "#contracts/math/resolution";
|
|
6
10
|
/** Checks a plane polygon has non-zero signed area. */
|
|
@@ -111,6 +115,7 @@ const PlaneQuadraticObjectSchema = Schema.Struct({
|
|
|
111
115
|
});
|
|
112
116
|
/** Mathematical objects supported by a Cartesian plane scene. */
|
|
113
117
|
export const PlaneMathObjectSchema = Schema.Union([
|
|
118
|
+
...PlaneCurveObjectSchemas,
|
|
114
119
|
PlaneArcObjectSchema,
|
|
115
120
|
PlaneCircleObjectSchema,
|
|
116
121
|
PlaneLineObjectSchema,
|
|
@@ -132,17 +137,24 @@ export const PlaneMathViewSchema = Schema.Struct({
|
|
|
132
137
|
kind: Schema.Literal("fit"),
|
|
133
138
|
padding: Schema.optionalKey(MathViewPaddingSchema),
|
|
134
139
|
});
|
|
135
|
-
/**
|
|
136
|
-
|
|
140
|
+
/**
|
|
141
|
+
* One coordinate anchor resolved against a separate rich-label map. Its
|
|
142
|
+
* position is exact, or placed by formulas of the sliders so it follows them.
|
|
143
|
+
*/
|
|
144
|
+
export const PlaneLabelAnchorSchema = Schema.Struct(mathLabelAnchorFields(Schema.Union([PlanePointSchema, PlaneFormulaPointSchema])));
|
|
137
145
|
/** Complete stable plane visual before rich labels are attached. */
|
|
138
146
|
export const PlaneMathVisualSchema = Schema.Struct({
|
|
139
147
|
frame: PlaneMathFrameSchema,
|
|
140
148
|
labels: Schema.optionalKey(Schema.Array(PlaneLabelAnchorSchema)),
|
|
141
149
|
objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
|
|
150
|
+
parameters: Schema.optionalKey(Schema.Array(FormulaParameterSchema)),
|
|
151
|
+
readouts: Schema.optionalKey(Schema.Array(FormulaReadoutSchema)),
|
|
142
152
|
space: Schema.Literal("plane"),
|
|
143
153
|
view: PlaneMathViewSchema,
|
|
144
|
-
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, view }) => [
|
|
154
|
+
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, parameters = [], readouts = [], view, }) => [
|
|
145
155
|
...mathVisualIdentityIssues(objects, labels),
|
|
146
|
-
...
|
|
156
|
+
...formulaScopeIssues(objects, planeFormulaFields, parameters),
|
|
157
|
+
...sliderFormulaIssues(labels, readouts, parameters),
|
|
158
|
+
...planeBoundsIssues(frame, objects, labels, parameterScope(parameters)),
|
|
147
159
|
...planeResolutionIssues(frame, objects, labels, view),
|
|
148
160
|
])));
|
package/dist/math/scene.js
CHANGED
|
@@ -2,6 +2,7 @@ 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";
|
|
5
|
+
import { isPlaneFormulaPoint } from "#contracts/math/formula/field";
|
|
5
6
|
import { axisSpan, measureUnresolved, quadraticCurvatureUnresolved, spanUnresolved, } from "#contracts/math/precision";
|
|
6
7
|
import { decimal, decimalRatio } from "#contracts/math/rational";
|
|
7
8
|
/** Projects exact cardinal extrema from one circle or directed arc. */
|
|
@@ -47,7 +48,10 @@ function cuboidCoordinates(object, path) {
|
|
|
47
48
|
]),
|
|
48
49
|
];
|
|
49
50
|
}
|
|
50
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Projects every finite or frame-clipped coordinate of one scene object. A
|
|
53
|
+
* formula object authors no coordinate: its samples come from its formula.
|
|
54
|
+
*/
|
|
51
55
|
function objectCoordinates(frame, object, index, threshold) {
|
|
52
56
|
const root = ["objects", index];
|
|
53
57
|
if (object.kind === "point") {
|
|
@@ -78,11 +82,20 @@ function objectCoordinates(frame, object, index, threshold) {
|
|
|
78
82
|
if (object.kind === "quadratic") {
|
|
79
83
|
return quadraticCoordinates(object, root, threshold);
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
if (object.kind === "prism" || object.kind === "pyramid") {
|
|
86
|
+
return Arr.flatMap(object.base, (point, pointIndex) => pointCoordinates(point, [...root, "base", pointIndex]));
|
|
87
|
+
}
|
|
88
|
+
if (object.kind === "cuboid") {
|
|
89
|
+
return cuboidCoordinates(object, root);
|
|
90
|
+
}
|
|
91
|
+
return [];
|
|
82
92
|
}
|
|
83
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Projects all exact label anchors after the objects they annotate. An anchor
|
|
95
|
+
* placed by formulas moves with the sliders, so it holds no exact coordinate.
|
|
96
|
+
*/
|
|
84
97
|
function labelCoordinates(labels) {
|
|
85
|
-
return Arr.flatMap(labels, (
|
|
98
|
+
return Arr.flatMap(labels, ({ at }, index) => isPlaneFormulaPoint(at) ? [] : pointCoordinates(at, ["labels", index, "at"]));
|
|
86
99
|
}
|
|
87
100
|
/** Projects semantic camera or isometric coordinates before space objects. */
|
|
88
101
|
function viewCoordinates(view) {
|
|
@@ -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
|
+
];
|