@nakafa/aksara-contracts 6.1.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 +99 -6
- package/dist/math/bounds.js +21 -4
- package/dist/math/curve.d.ts +22 -0
- package/dist/math/curve.js +29 -1
- package/dist/math/formula/field.d.ts +23 -0
- package/dist/math/formula/field.js +19 -0
- package/dist/math/formula/plane.d.ts +17 -4
- package/dist/math/formula/plane.js +34 -88
- package/dist/math/formula/region.d.ts +16 -0
- package/dist/math/formula/region.js +94 -0
- package/dist/math/formula/scope.d.ts +4 -0
- package/dist/math/formula/scope.js +27 -13
- package/dist/math/formula/slider.d.ts +9 -0
- package/dist/math/formula/slider.js +32 -0
- package/dist/math/plane.d.ts +63 -5
- package/dist/math/plane.js +10 -4
- package/dist/math/scene.js +6 -2
- package/dist/math/space.d.ts +1 -0
- package/dist/math/visual.d.ts +91 -3
- package/dist/math/visual.js +12 -2
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Result } from "effect";
|
|
2
|
+
import { type SampleBox } from "#contracts/math/formula/box";
|
|
3
|
+
import { type FormulaScope } from "#contracts/math/formula/compile";
|
|
4
|
+
/** The region where every inequality holds, with each edge marked strict or not. */
|
|
5
|
+
export declare function regionGeometry(inequalities: readonly [string, ...string[]], box: SampleBox, scope: FormulaScope): Result.Result<{
|
|
6
|
+
boundary: {
|
|
7
|
+
readonly points: readonly {
|
|
8
|
+
readonly x: number;
|
|
9
|
+
readonly y: number;
|
|
10
|
+
readonly z: number;
|
|
11
|
+
}[];
|
|
12
|
+
readonly strict: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
fill: readonly import("./sample.js").SampleBranch[];
|
|
15
|
+
kind: "region";
|
|
16
|
+
}, import("./syntax.js").FormulaError>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Array as Arr, MutableList, Option, Order, Result, Schema, } from "effect";
|
|
2
|
+
import { SamplePointSchema, } from "#contracts/math/formula/box";
|
|
3
|
+
import { compileFormula, } from "#contracts/math/formula/compile";
|
|
4
|
+
import { contourFill, contourLines, } from "#contracts/math/formula/contour";
|
|
5
|
+
import { readRelation } from "#contracts/math/formula/parse";
|
|
6
|
+
/** How far a boundary piece lies from one inequality's edge, and whether that edge is strict. */
|
|
7
|
+
const ConstraintGapSchema = Schema.Struct({
|
|
8
|
+
gap: Schema.Finite,
|
|
9
|
+
strict: Schema.Boolean,
|
|
10
|
+
});
|
|
11
|
+
/** One piece of a region's outline, between two consecutive samples. */
|
|
12
|
+
const EdgePieceSchema = Schema.Struct({
|
|
13
|
+
next: SamplePointSchema,
|
|
14
|
+
point: SamplePointSchema,
|
|
15
|
+
strict: Schema.Boolean,
|
|
16
|
+
});
|
|
17
|
+
/** One run of an outline that is all strict or all inclusive. */
|
|
18
|
+
const EdgeRunSchema = Schema.Struct({
|
|
19
|
+
points: Schema.Array(SamplePointSchema),
|
|
20
|
+
strict: Schema.Boolean,
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Joins consecutive outline pieces of the same kind into one line, so a
|
|
24
|
+
* renderer draws a few dashed and solid edges instead of every short piece.
|
|
25
|
+
*/
|
|
26
|
+
function edgeRuns(pieces) {
|
|
27
|
+
const runs = MutableList.make();
|
|
28
|
+
let points = MutableList.make();
|
|
29
|
+
let strict = false;
|
|
30
|
+
Arr.forEach(pieces, (piece, index) => {
|
|
31
|
+
if (index === 0 || piece.strict !== strict) {
|
|
32
|
+
if (index > 0) {
|
|
33
|
+
MutableList.append(runs, {
|
|
34
|
+
points: MutableList.toArray(points),
|
|
35
|
+
strict,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
points = MutableList.make();
|
|
39
|
+
MutableList.append(points, piece.point);
|
|
40
|
+
({ strict } = piece);
|
|
41
|
+
}
|
|
42
|
+
MutableList.append(points, piece.next);
|
|
43
|
+
});
|
|
44
|
+
MutableList.append(runs, { points: MutableList.toArray(points), strict });
|
|
45
|
+
return MutableList.toArray(runs);
|
|
46
|
+
}
|
|
47
|
+
/** The signed room an inequality leaves at a point: positive where it holds. */
|
|
48
|
+
function margin(text) {
|
|
49
|
+
return Result.map(readRelation(text), ({ comparison, left, right }) => {
|
|
50
|
+
const leftValue = compileFormula(left);
|
|
51
|
+
const rightValue = compileFormula(right);
|
|
52
|
+
const below = comparison === "<" || comparison === "<=";
|
|
53
|
+
return {
|
|
54
|
+
field: (scope) => (x, y) => {
|
|
55
|
+
const point = { ...scope, x, y };
|
|
56
|
+
const gap = rightValue(point) - leftValue(point);
|
|
57
|
+
return below ? gap : -gap;
|
|
58
|
+
},
|
|
59
|
+
strict: comparison === "<" || comparison === ">",
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** The region where every inequality holds, with each edge marked strict or not. */
|
|
64
|
+
export function regionGeometry(inequalities, box, scope) {
|
|
65
|
+
return Result.map(Result.all(Arr.map(inequalities, margin)), (margins) => {
|
|
66
|
+
const constraints = Arr.map(margins, (each) => ({
|
|
67
|
+
field: each.field(scope),
|
|
68
|
+
strict: each.strict,
|
|
69
|
+
}));
|
|
70
|
+
/** The tightest margin at a point: where it is not negative, every inequality holds. */
|
|
71
|
+
const field = (x, y) => Math.min(...Arr.map(constraints, (each) => each.field(x, y)));
|
|
72
|
+
const byGap = Order.mapInput(Order.Number, (piece) => piece.gap);
|
|
73
|
+
/** Whether the inequality nearest a boundary piece is strict, so it draws dashed. */
|
|
74
|
+
const strictAt = (from, to) => {
|
|
75
|
+
const x = (from.x + to.x) / 2;
|
|
76
|
+
const y = (from.y + to.y) / 2;
|
|
77
|
+
const gaps = Arr.map(constraints, (each) => ({
|
|
78
|
+
gap: Math.abs(each.field(x, y)),
|
|
79
|
+
strict: each.strict,
|
|
80
|
+
}));
|
|
81
|
+
return Option.exists(Arr.head(Arr.sort(gaps, byGap)), ({ strict }) => strict);
|
|
82
|
+
};
|
|
83
|
+
const boundary = Arr.flatMap(contourLines(field, box), (line) => edgeRuns(Arr.zipWith(line, Arr.drop(line, 1), (point, next) => ({
|
|
84
|
+
next,
|
|
85
|
+
point,
|
|
86
|
+
strict: strictAt(point, next),
|
|
87
|
+
}))));
|
|
88
|
+
return {
|
|
89
|
+
boundary,
|
|
90
|
+
fill: contourFill(field, box),
|
|
91
|
+
kind: "region",
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -13,6 +13,8 @@ declare const FormulaFieldSchema: Schema.Struct<{
|
|
|
13
13
|
readonly variables: Schema.$Array<Schema.String>;
|
|
14
14
|
}>;
|
|
15
15
|
export type FormulaField = typeof FormulaFieldSchema.Type;
|
|
16
|
+
/** Builds one expression field. */
|
|
17
|
+
export declare function expression(path: readonly (string | number)[], text: string, variables: readonly string[]): FormulaField;
|
|
16
18
|
/**
|
|
17
19
|
* Lists every formula a plane object holds and the variables each may read:
|
|
18
20
|
* its input axis for a function, t for a parametric curve, theta for a polar
|
|
@@ -25,6 +27,8 @@ export declare function planeFormulaFields(object: PlaneMathObject): readonly Fo
|
|
|
25
27
|
* surface, and the axis variable for a solid of revolution.
|
|
26
28
|
*/
|
|
27
29
|
export declare function spaceFormulaFields(object: SpaceMathObject): readonly FormulaField[];
|
|
30
|
+
/** Reports one formula that reads a name it may not, at its root path. */
|
|
31
|
+
export declare function strayIssues(field: FormulaField, declared: readonly string[], root: readonly (string | number)[]): Schema.FilterIssue[];
|
|
28
32
|
/**
|
|
29
33
|
* Reports every formula that reads a name its object does not offer, and every
|
|
30
34
|
* slider whose name repeats an earlier one.
|
|
@@ -9,7 +9,7 @@ const FormulaFieldSchema = Schema.Struct({
|
|
|
9
9
|
variables: Schema.Array(Schema.String),
|
|
10
10
|
});
|
|
11
11
|
/** Builds one expression field. */
|
|
12
|
-
function expression(path, text, variables) {
|
|
12
|
+
export function expression(path, text, variables) {
|
|
13
13
|
return { path, relation: false, text, variables };
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -30,6 +30,15 @@ export function planeFormulaFields(object) {
|
|
|
30
30
|
if (object.kind === "polar") {
|
|
31
31
|
return [expression(["radius"], object.radius, ["theta"])];
|
|
32
32
|
}
|
|
33
|
+
if (object.kind === "marker") {
|
|
34
|
+
return [expression(["x"], object.x, []), expression(["y"], object.y, [])];
|
|
35
|
+
}
|
|
36
|
+
if (object.kind === "path" || object.kind === "loop") {
|
|
37
|
+
return Arr.flatMap(object.points, (point, index) => [
|
|
38
|
+
expression(["points", index, "x"], point.x, []),
|
|
39
|
+
expression(["points", index, "y"], point.y, []),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
33
42
|
if (object.kind === "implicit") {
|
|
34
43
|
return [
|
|
35
44
|
{
|
|
@@ -81,6 +90,19 @@ function namesOf(field) {
|
|
|
81
90
|
onSuccess: formulaNames,
|
|
82
91
|
});
|
|
83
92
|
}
|
|
93
|
+
/** Reports one formula that reads a name it may not, at its root path. */
|
|
94
|
+
export function strayIssues(field, declared, root) {
|
|
95
|
+
const allowed = HashSet.fromIterable([...field.variables, ...declared]);
|
|
96
|
+
const stray = Arr.sort(Arr.fromIterable(HashSet.difference(namesOf(field), allowed)), Order.String);
|
|
97
|
+
return Arr.isReadonlyArrayEmpty(stray)
|
|
98
|
+
? []
|
|
99
|
+
: [
|
|
100
|
+
{
|
|
101
|
+
issue: `Expected only ${Arr.join([...field.variables, ...declared], ", ")} in this formula, not ${Arr.join(stray, ", ")}.`,
|
|
102
|
+
path: [...root, ...field.path],
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
}
|
|
84
106
|
/**
|
|
85
107
|
* Reports every formula that reads a name its object does not offer, and every
|
|
86
108
|
* slider whose name repeats an earlier one.
|
|
@@ -96,18 +118,7 @@ export function formulaScopeIssues(objects, fields, parameters) {
|
|
|
96
118
|
},
|
|
97
119
|
]
|
|
98
120
|
: []);
|
|
99
|
-
const unknown = Arr.flatMap(objects, (object, index) => Arr.flatMap(fields(object), (field) =>
|
|
100
|
-
const allowed = HashSet.fromIterable([...field.variables, ...declared]);
|
|
101
|
-
const stray = Arr.sort(Arr.fromIterable(HashSet.difference(namesOf(field), allowed)), Order.String);
|
|
102
|
-
return Arr.isReadonlyArrayEmpty(stray)
|
|
103
|
-
? []
|
|
104
|
-
: [
|
|
105
|
-
{
|
|
106
|
-
issue: `Expected only ${Arr.join([...field.variables, ...declared], ", ")} in this formula, not ${Arr.join(stray, ", ")}.`,
|
|
107
|
-
path: ["objects", index, ...field.path],
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
}));
|
|
121
|
+
const unknown = Arr.flatMap(objects, (object, index) => Arr.flatMap(fields(object), (field) => strayIssues(field, declared, ["objects", index])));
|
|
111
122
|
return [...repeated, ...unknown];
|
|
112
123
|
}
|
|
113
124
|
/** Each slider's starting value by its name, the scope a scene first draws with. */
|
|
@@ -130,6 +141,9 @@ export function geometryVisible(geometry, box) {
|
|
|
130
141
|
if (geometry.kind === "region") {
|
|
131
142
|
return Arr.isReadonlyArrayNonEmpty(geometry.fill);
|
|
132
143
|
}
|
|
144
|
+
if (geometry.kind === "points") {
|
|
145
|
+
return Arr.some(geometry.points, (point) => inside(box, point));
|
|
146
|
+
}
|
|
133
147
|
if (geometry.kind === "grid") {
|
|
134
148
|
return Arr.some(geometry.grid.points, (point) => Option.exists(point, (each) => inside(box, each)));
|
|
135
149
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Schema } from "effect";
|
|
2
|
+
import { type FormulaParameter, type FormulaReadout } from "#contracts/math/formula/field";
|
|
3
|
+
import type { PlaneLabelAnchor } from "#contracts/math/plane";
|
|
4
|
+
/**
|
|
5
|
+
* Reports every label position or readout formula that reads a name other
|
|
6
|
+
* than a slider's, since only the sliders move them, and every readout key
|
|
7
|
+
* that repeats an earlier one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sliderFormulaIssues(labels: readonly PlaneLabelAnchor[], readouts: readonly FormulaReadout[], parameters: readonly FormulaParameter[]): readonly Schema.FilterIssue[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Array as Arr } from "effect";
|
|
2
|
+
import { isPlaneFormulaPoint, } from "#contracts/math/formula/field";
|
|
3
|
+
import { expression, strayIssues } from "#contracts/math/formula/scope";
|
|
4
|
+
/**
|
|
5
|
+
* Reports every label position or readout formula that reads a name other
|
|
6
|
+
* than a slider's, since only the sliders move them, and every readout key
|
|
7
|
+
* that repeats an earlier one.
|
|
8
|
+
*/
|
|
9
|
+
export function sliderFormulaIssues(labels, readouts, parameters) {
|
|
10
|
+
const declared = Arr.dedupe(Arr.map(parameters, ({ name }) => name));
|
|
11
|
+
const anchors = Arr.flatMap(labels, ({ at }, index) => isPlaneFormulaPoint(at)
|
|
12
|
+
? Arr.flatMap(["x", "y"], (axis) => strayIssues(expression([axis], at[axis], []), declared, [
|
|
13
|
+
"labels",
|
|
14
|
+
index,
|
|
15
|
+
"at",
|
|
16
|
+
]))
|
|
17
|
+
: []);
|
|
18
|
+
const values = Arr.flatMap(readouts, ({ formula }, index) => strayIssues(expression(["formula"], formula, []), declared, [
|
|
19
|
+
"readouts",
|
|
20
|
+
index,
|
|
21
|
+
]));
|
|
22
|
+
const keys = Arr.map(readouts, ({ key }) => key);
|
|
23
|
+
const repeated = Arr.flatMap(keys, (key, index) => Arr.contains(Arr.take(keys, index), key)
|
|
24
|
+
? [
|
|
25
|
+
{
|
|
26
|
+
issue: "Expected a unique readout key.",
|
|
27
|
+
path: ["readouts", index, "key"],
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
: []);
|
|
31
|
+
return [...anchors, ...values, ...repeated];
|
|
32
|
+
}
|
package/dist/math/plane.d.ts
CHANGED
|
@@ -15,6 +15,20 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
15
15
|
readonly id: Schema.String;
|
|
16
16
|
readonly equation: Schema.String;
|
|
17
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;
|
|
18
32
|
}>, Schema.Struct<{
|
|
19
33
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
20
34
|
readonly id: Schema.String;
|
|
@@ -25,6 +39,14 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
25
39
|
}>;
|
|
26
40
|
readonly x: Schema.String;
|
|
27
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
|
+
}>>;
|
|
28
50
|
}>, Schema.Struct<{
|
|
29
51
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
30
52
|
readonly id: Schema.String;
|
|
@@ -168,12 +190,18 @@ export declare const PlaneMathViewSchema: Schema.Struct<{
|
|
|
168
190
|
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
169
191
|
}>;
|
|
170
192
|
export type PlaneMathView = typeof PlaneMathViewSchema.Type;
|
|
171
|
-
/**
|
|
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
|
+
*/
|
|
172
197
|
export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
173
|
-
readonly at: Schema.Struct<{
|
|
198
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
174
199
|
readonly x: Schema.Finite;
|
|
175
200
|
readonly y: Schema.Finite;
|
|
176
|
-
}
|
|
201
|
+
}>, Schema.Struct<{
|
|
202
|
+
readonly x: Schema.String;
|
|
203
|
+
readonly y: Schema.String;
|
|
204
|
+
}>]>;
|
|
177
205
|
readonly key: Schema.String;
|
|
178
206
|
readonly objectId: Schema.String;
|
|
179
207
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
@@ -193,10 +221,13 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
193
221
|
}>;
|
|
194
222
|
}>;
|
|
195
223
|
readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
196
|
-
readonly at: Schema.Struct<{
|
|
224
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
197
225
|
readonly x: Schema.Finite;
|
|
198
226
|
readonly y: Schema.Finite;
|
|
199
|
-
}
|
|
227
|
+
}>, Schema.Struct<{
|
|
228
|
+
readonly x: Schema.String;
|
|
229
|
+
readonly y: Schema.String;
|
|
230
|
+
}>]>;
|
|
200
231
|
readonly key: Schema.String;
|
|
201
232
|
readonly objectId: Schema.String;
|
|
202
233
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
@@ -216,6 +247,20 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
216
247
|
readonly id: Schema.String;
|
|
217
248
|
readonly equation: Schema.String;
|
|
218
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;
|
|
219
264
|
}>, Schema.Struct<{
|
|
220
265
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
221
266
|
readonly id: Schema.String;
|
|
@@ -226,6 +271,14 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
226
271
|
}>;
|
|
227
272
|
readonly x: Schema.String;
|
|
228
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
|
+
}>>;
|
|
229
282
|
}>, Schema.Struct<{
|
|
230
283
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
231
284
|
readonly id: Schema.String;
|
|
@@ -350,12 +403,17 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
350
403
|
}>;
|
|
351
404
|
}>]>>;
|
|
352
405
|
readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
406
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
353
407
|
readonly max: Schema.Finite;
|
|
354
408
|
readonly min: Schema.Finite;
|
|
355
409
|
readonly name: Schema.String;
|
|
356
410
|
readonly step: Schema.optionalKey<Schema.Finite>;
|
|
357
411
|
readonly value: Schema.Finite;
|
|
358
412
|
}>>>;
|
|
413
|
+
readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
414
|
+
readonly formula: Schema.String;
|
|
415
|
+
readonly key: Schema.String;
|
|
416
|
+
}>>>;
|
|
359
417
|
readonly space: Schema.Literal<"plane">;
|
|
360
418
|
readonly view: Schema.Struct<{
|
|
361
419
|
readonly kind: Schema.Literal<"fit">;
|
package/dist/math/plane.js
CHANGED
|
@@ -2,8 +2,9 @@ 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
4
|
import { PlaneCurveObjectSchemas } from "#contracts/math/curve";
|
|
5
|
-
import { FormulaParameterSchema } from "#contracts/math/formula/field";
|
|
5
|
+
import { FormulaParameterSchema, FormulaReadoutSchema, PlaneFormulaPointSchema, } from "#contracts/math/formula/field";
|
|
6
6
|
import { formulaScopeIssues, parameterScope, planeFormulaFields, } from "#contracts/math/formula/scope";
|
|
7
|
+
import { sliderFormulaIssues } from "#contracts/math/formula/slider";
|
|
7
8
|
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
|
|
8
9
|
import { planeResolutionIssues } from "#contracts/math/resolution";
|
|
9
10
|
/** Checks a plane polygon has non-zero signed area. */
|
|
@@ -136,19 +137,24 @@ export const PlaneMathViewSchema = Schema.Struct({
|
|
|
136
137
|
kind: Schema.Literal("fit"),
|
|
137
138
|
padding: Schema.optionalKey(MathViewPaddingSchema),
|
|
138
139
|
});
|
|
139
|
-
/**
|
|
140
|
-
|
|
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])));
|
|
141
145
|
/** Complete stable plane visual before rich labels are attached. */
|
|
142
146
|
export const PlaneMathVisualSchema = Schema.Struct({
|
|
143
147
|
frame: PlaneMathFrameSchema,
|
|
144
148
|
labels: Schema.optionalKey(Schema.Array(PlaneLabelAnchorSchema)),
|
|
145
149
|
objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
|
|
146
150
|
parameters: Schema.optionalKey(Schema.Array(FormulaParameterSchema)),
|
|
151
|
+
readouts: Schema.optionalKey(Schema.Array(FormulaReadoutSchema)),
|
|
147
152
|
space: Schema.Literal("plane"),
|
|
148
153
|
view: PlaneMathViewSchema,
|
|
149
|
-
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, parameters = [], view }) => [
|
|
154
|
+
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, parameters = [], readouts = [], view, }) => [
|
|
150
155
|
...mathVisualIdentityIssues(objects, labels),
|
|
151
156
|
...formulaScopeIssues(objects, planeFormulaFields, parameters),
|
|
157
|
+
...sliderFormulaIssues(labels, readouts, parameters),
|
|
152
158
|
...planeBoundsIssues(frame, objects, labels, parameterScope(parameters)),
|
|
153
159
|
...planeResolutionIssues(frame, objects, labels, view),
|
|
154
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. */
|
|
@@ -89,9 +90,12 @@ function objectCoordinates(frame, object, index, threshold) {
|
|
|
89
90
|
}
|
|
90
91
|
return [];
|
|
91
92
|
}
|
|
92
|
-
/**
|
|
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
|
+
*/
|
|
93
97
|
function labelCoordinates(labels) {
|
|
94
|
-
return Arr.flatMap(labels, (
|
|
98
|
+
return Arr.flatMap(labels, ({ at }, index) => isPlaneFormulaPoint(at) ? [] : pointCoordinates(at, ["labels", index, "at"]));
|
|
95
99
|
}
|
|
96
100
|
/** Projects semantic camera or isometric coordinates before space objects. */
|
|
97
101
|
function viewCoordinates(view) {
|
package/dist/math/space.d.ts
CHANGED
|
@@ -495,6 +495,7 @@ export declare const SpaceMathVisualSchema: Schema.Struct<{
|
|
|
495
495
|
}>;
|
|
496
496
|
}>]>>;
|
|
497
497
|
readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
498
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
498
499
|
readonly max: Schema.Finite;
|
|
499
500
|
readonly min: Schema.Finite;
|
|
500
501
|
readonly name: Schema.String;
|
package/dist/math/visual.d.ts
CHANGED
|
@@ -13,10 +13,13 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
13
13
|
}>;
|
|
14
14
|
}>;
|
|
15
15
|
readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
16
|
-
readonly at: Schema.Struct<{
|
|
16
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
17
17
|
readonly x: Schema.Finite;
|
|
18
18
|
readonly y: Schema.Finite;
|
|
19
|
-
}
|
|
19
|
+
}>, Schema.Struct<{
|
|
20
|
+
readonly x: Schema.String;
|
|
21
|
+
readonly y: Schema.String;
|
|
22
|
+
}>]>;
|
|
20
23
|
readonly key: Schema.String;
|
|
21
24
|
readonly objectId: Schema.String;
|
|
22
25
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
@@ -36,6 +39,20 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
36
39
|
readonly id: Schema.String;
|
|
37
40
|
readonly equation: Schema.String;
|
|
38
41
|
readonly kind: Schema.Literal<"implicit">;
|
|
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<"loop">;
|
|
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 kind: Schema.Literal<"marker">;
|
|
54
|
+
readonly x: Schema.String;
|
|
55
|
+
readonly y: Schema.String;
|
|
39
56
|
}>, Schema.Struct<{
|
|
40
57
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
41
58
|
readonly id: Schema.String;
|
|
@@ -46,6 +63,14 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
46
63
|
}>;
|
|
47
64
|
readonly x: Schema.String;
|
|
48
65
|
readonly y: Schema.String;
|
|
66
|
+
}>, Schema.Struct<{
|
|
67
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
68
|
+
readonly id: Schema.String;
|
|
69
|
+
readonly kind: Schema.Literal<"path">;
|
|
70
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
71
|
+
readonly x: Schema.String;
|
|
72
|
+
readonly y: Schema.String;
|
|
73
|
+
}>>;
|
|
49
74
|
}>, Schema.Struct<{
|
|
50
75
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
51
76
|
readonly id: Schema.String;
|
|
@@ -170,12 +195,17 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
170
195
|
}>;
|
|
171
196
|
}>]>>;
|
|
172
197
|
readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
198
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
173
199
|
readonly max: Schema.Finite;
|
|
174
200
|
readonly min: Schema.Finite;
|
|
175
201
|
readonly name: Schema.String;
|
|
176
202
|
readonly step: Schema.optionalKey<Schema.Finite>;
|
|
177
203
|
readonly value: Schema.Finite;
|
|
178
204
|
}>>>;
|
|
205
|
+
readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
206
|
+
readonly formula: Schema.String;
|
|
207
|
+
readonly key: Schema.String;
|
|
208
|
+
}>>>;
|
|
179
209
|
readonly space: Schema.Literal<"plane">;
|
|
180
210
|
readonly view: Schema.Struct<{
|
|
181
211
|
readonly kind: Schema.Literal<"fit">;
|
|
@@ -414,6 +444,7 @@ export declare const MathVisualSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
414
444
|
}>;
|
|
415
445
|
}>]>>;
|
|
416
446
|
readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
447
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
417
448
|
readonly max: Schema.Finite;
|
|
418
449
|
readonly min: Schema.Finite;
|
|
419
450
|
readonly name: Schema.String;
|
|
@@ -885,6 +916,7 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
|
|
|
885
916
|
readonly kind: "function";
|
|
886
917
|
})[]];
|
|
887
918
|
readonly parameters?: readonly {
|
|
919
|
+
readonly label?: string;
|
|
888
920
|
readonly max: number;
|
|
889
921
|
readonly min: number;
|
|
890
922
|
readonly name: string;
|
|
@@ -929,6 +961,9 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
|
|
|
929
961
|
};
|
|
930
962
|
readonly labels?: readonly {
|
|
931
963
|
readonly at: {
|
|
964
|
+
readonly x: string;
|
|
965
|
+
readonly y: string;
|
|
966
|
+
} | {
|
|
932
967
|
readonly x: number;
|
|
933
968
|
readonly y: number;
|
|
934
969
|
};
|
|
@@ -965,6 +1000,28 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
|
|
|
965
1000
|
readonly id: string;
|
|
966
1001
|
readonly inequalities: readonly [string, ...string[]];
|
|
967
1002
|
readonly kind: "region";
|
|
1003
|
+
} | {
|
|
1004
|
+
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1005
|
+
readonly id: string;
|
|
1006
|
+
readonly kind: "marker";
|
|
1007
|
+
readonly x: string;
|
|
1008
|
+
readonly y: string;
|
|
1009
|
+
} | {
|
|
1010
|
+
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1011
|
+
readonly id: string;
|
|
1012
|
+
readonly kind: "path";
|
|
1013
|
+
readonly points: readonly {
|
|
1014
|
+
readonly x: string;
|
|
1015
|
+
readonly y: string;
|
|
1016
|
+
}[];
|
|
1017
|
+
} | {
|
|
1018
|
+
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1019
|
+
readonly id: string;
|
|
1020
|
+
readonly kind: "loop";
|
|
1021
|
+
readonly points: readonly {
|
|
1022
|
+
readonly x: string;
|
|
1023
|
+
readonly y: string;
|
|
1024
|
+
}[];
|
|
968
1025
|
} | {
|
|
969
1026
|
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
970
1027
|
readonly id: string;
|
|
@@ -1112,6 +1169,28 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
|
|
|
1112
1169
|
readonly id: string;
|
|
1113
1170
|
readonly inequalities: readonly [string, ...string[]];
|
|
1114
1171
|
readonly kind: "region";
|
|
1172
|
+
} | {
|
|
1173
|
+
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1174
|
+
readonly id: string;
|
|
1175
|
+
readonly kind: "marker";
|
|
1176
|
+
readonly x: string;
|
|
1177
|
+
readonly y: string;
|
|
1178
|
+
} | {
|
|
1179
|
+
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1180
|
+
readonly id: string;
|
|
1181
|
+
readonly kind: "path";
|
|
1182
|
+
readonly points: readonly {
|
|
1183
|
+
readonly x: string;
|
|
1184
|
+
readonly y: string;
|
|
1185
|
+
}[];
|
|
1186
|
+
} | {
|
|
1187
|
+
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1188
|
+
readonly id: string;
|
|
1189
|
+
readonly kind: "loop";
|
|
1190
|
+
readonly points: readonly {
|
|
1191
|
+
readonly x: string;
|
|
1192
|
+
readonly y: string;
|
|
1193
|
+
}[];
|
|
1115
1194
|
} | {
|
|
1116
1195
|
readonly appearance: "answer" | "construction" | "highlight" | "primary" | "reference" | "secondary" | "warning";
|
|
1117
1196
|
readonly id: string;
|
|
@@ -1232,17 +1311,26 @@ export declare const decodeMathVisual: (input: unknown) => Effect.Effect<{
|
|
|
1232
1311
|
readonly kind: "function";
|
|
1233
1312
|
})[]];
|
|
1234
1313
|
readonly parameters?: readonly {
|
|
1314
|
+
readonly label?: string;
|
|
1235
1315
|
readonly max: number;
|
|
1236
1316
|
readonly min: number;
|
|
1237
1317
|
readonly name: string;
|
|
1238
1318
|
readonly step?: number;
|
|
1239
1319
|
readonly value: number;
|
|
1240
1320
|
}[];
|
|
1321
|
+
readonly readouts?: readonly {
|
|
1322
|
+
readonly formula: string;
|
|
1323
|
+
readonly key: string;
|
|
1324
|
+
}[];
|
|
1241
1325
|
readonly space: "plane";
|
|
1242
1326
|
readonly view: {
|
|
1243
1327
|
readonly kind: "fit";
|
|
1244
1328
|
readonly padding?: number;
|
|
1245
1329
|
};
|
|
1246
1330
|
}, import("../errors.js").ContractDecodeError, never>;
|
|
1247
|
-
/**
|
|
1331
|
+
/**
|
|
1332
|
+
* Returns every rich-label key a scene names, once each: its anchors in
|
|
1333
|
+
* authored order, then its readouts and its sliders' labels. A readout or a
|
|
1334
|
+
* slider may show the same rich label as an anchor.
|
|
1335
|
+
*/
|
|
1248
1336
|
export declare function mathVisualLabelKeys(visual: MathVisual): string[];
|
package/dist/math/visual.js
CHANGED
|
@@ -9,7 +9,17 @@ export const MathVisualSchema = Schema.Union([
|
|
|
9
9
|
]);
|
|
10
10
|
/** Strictly decodes one untrusted mathematical scene into its stable contract. */
|
|
11
11
|
export const decodeMathVisual = Effect.fn("AksaraContracts.decodeMathVisual")((input) => decodeContract(MathVisualSchema, "MathVisual", input));
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Returns every rich-label key a scene names, once each: its anchors in
|
|
14
|
+
* authored order, then its readouts and its sliders' labels. A readout or a
|
|
15
|
+
* slider may show the same rich label as an anchor.
|
|
16
|
+
*/
|
|
13
17
|
export function mathVisualLabelKeys(visual) {
|
|
14
|
-
return Arr.
|
|
18
|
+
return Arr.dedupe([
|
|
19
|
+
...Arr.map(visual.labels ?? [], ({ key }) => key),
|
|
20
|
+
...(visual.space === "plane"
|
|
21
|
+
? Arr.map(visual.readouts ?? [], ({ key }) => key)
|
|
22
|
+
: []),
|
|
23
|
+
...Arr.flatMap(visual.parameters ?? [], ({ label }) => label === undefined ? [] : [label]),
|
|
24
|
+
]);
|
|
15
25
|
}
|
package/package.json
CHANGED