@nakafa/aksara-contracts 6.1.0 → 6.3.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 +177 -6
- package/dist/math/bounds.js +23 -6
- 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/object.d.ts +2 -0
- package/dist/math/object.js +2 -0
- package/dist/math/plane.d.ts +87 -5
- package/dist/math/plane.js +24 -5
- package/dist/math/scene.js +7 -3
- package/dist/math/space.d.ts +29 -0
- package/dist/math/space.js +14 -1
- package/dist/math/visual.d.ts +169 -3
- package/dist/math/visual.js +12 -2
- package/package.json +1 -1
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { Array as Arr,
|
|
1
|
+
import { Array as Arr, Option, Result, Schema } from "effect";
|
|
2
2
|
import { SamplePointSchema, } from "#contracts/math/formula/box";
|
|
3
3
|
import { compileFormula, } from "#contracts/math/formula/compile";
|
|
4
|
-
import {
|
|
4
|
+
import { contourLines, } from "#contracts/math/formula/contour";
|
|
5
5
|
import { SampleGridSchema } from "#contracts/math/formula/mesh";
|
|
6
6
|
import { readFormula, readRelation } from "#contracts/math/formula/parse";
|
|
7
|
+
import { regionGeometry } from "#contracts/math/formula/region";
|
|
7
8
|
import { sampleCurve } from "#contracts/math/formula/sample";
|
|
8
9
|
const BranchSchema = Schema.Array(SamplePointSchema);
|
|
9
10
|
/**
|
|
10
|
-
* What a formula object draws once sampled: curves, a shaded
|
|
11
|
-
* solid or dashed edges, a surface grid, or the
|
|
11
|
+
* What a formula object draws once sampled: curves, marked points, a shaded
|
|
12
|
+
* region with solid or dashed edges, a surface grid, or the faces of a solid.
|
|
12
13
|
*/
|
|
13
14
|
export const FormulaGeometrySchema = Schema.Union([
|
|
14
15
|
Schema.Struct({
|
|
15
16
|
branches: Schema.Array(BranchSchema),
|
|
16
17
|
kind: Schema.Literal("curves"),
|
|
17
18
|
}),
|
|
19
|
+
Schema.Struct({ kind: Schema.Literal("points"), points: BranchSchema }),
|
|
18
20
|
Schema.Struct({
|
|
19
21
|
boundary: Schema.Array(Schema.Struct({ points: BranchSchema, strict: Schema.Boolean })),
|
|
20
22
|
fill: Schema.Array(BranchSchema),
|
|
@@ -38,94 +40,30 @@ export function evaluateWith(evaluate, scope, name, value) {
|
|
|
38
40
|
function planePoint(x, y) {
|
|
39
41
|
return { x, y, z: 0 };
|
|
40
42
|
}
|
|
41
|
-
/** How far a boundary piece lies from one inequality's edge, and whether that edge is strict. */
|
|
42
|
-
const ConstraintGapSchema = Schema.Struct({
|
|
43
|
-
gap: Schema.Finite,
|
|
44
|
-
strict: Schema.Boolean,
|
|
45
|
-
});
|
|
46
|
-
/** One piece of a region's outline, between two consecutive samples. */
|
|
47
|
-
const EdgePieceSchema = Schema.Struct({
|
|
48
|
-
next: SamplePointSchema,
|
|
49
|
-
point: SamplePointSchema,
|
|
50
|
-
strict: Schema.Boolean,
|
|
51
|
-
});
|
|
52
|
-
/** One run of an outline that is all strict or all inclusive. */
|
|
53
|
-
const EdgeRunSchema = Schema.Struct({
|
|
54
|
-
points: Schema.Array(SamplePointSchema),
|
|
55
|
-
strict: Schema.Boolean,
|
|
56
|
-
});
|
|
57
43
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
44
|
+
* Places one formula point with the sliders' current values. A coordinate
|
|
45
|
+
* that is not finite there, such as ln(0), places nothing.
|
|
60
46
|
*/
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
MutableList.append(runs, {
|
|
69
|
-
points: MutableList.toArray(points),
|
|
70
|
-
strict,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
points = MutableList.make();
|
|
74
|
-
MutableList.append(points, piece.point);
|
|
75
|
-
({ strict } = piece);
|
|
76
|
-
}
|
|
77
|
-
MutableList.append(points, piece.next);
|
|
78
|
-
});
|
|
79
|
-
MutableList.append(runs, { points: MutableList.toArray(points), strict });
|
|
80
|
-
return MutableList.toArray(runs);
|
|
81
|
-
}
|
|
82
|
-
/** The signed room an inequality leaves at a point: positive where it holds. */
|
|
83
|
-
function margin(text) {
|
|
84
|
-
return Result.map(readRelation(text), ({ comparison, left, right }) => {
|
|
85
|
-
const leftValue = compileFormula(left);
|
|
86
|
-
const rightValue = compileFormula(right);
|
|
87
|
-
const below = comparison === "<" || comparison === "<=";
|
|
88
|
-
return {
|
|
89
|
-
field: (scope) => (x, y) => {
|
|
90
|
-
const point = { ...scope, x, y };
|
|
91
|
-
const gap = rightValue(point) - leftValue(point);
|
|
92
|
-
return below ? gap : -gap;
|
|
93
|
-
},
|
|
94
|
-
strict: comparison === "<" || comparison === ">",
|
|
95
|
-
};
|
|
47
|
+
export function planeFormulaPoint(point, scope) {
|
|
48
|
+
return Result.gen(function* () {
|
|
49
|
+
const x = (yield* compileText(point.x))(scope);
|
|
50
|
+
const y = (yield* compileText(point.y))(scope);
|
|
51
|
+
return Number.isFinite(x) && Number.isFinite(y)
|
|
52
|
+
? Option.some(planePoint(x, y))
|
|
53
|
+
: Option.none();
|
|
96
54
|
});
|
|
97
55
|
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const strictAt = (from, to) => {
|
|
110
|
-
const x = (from.x + to.x) / 2;
|
|
111
|
-
const y = (from.y + to.y) / 2;
|
|
112
|
-
const gaps = Arr.map(constraints, (each) => ({
|
|
113
|
-
gap: Math.abs(each.field(x, y)),
|
|
114
|
-
strict: each.strict,
|
|
115
|
-
}));
|
|
116
|
-
return Option.exists(Arr.head(Arr.sort(gaps, byGap)), ({ strict }) => strict);
|
|
117
|
-
};
|
|
118
|
-
const boundary = Arr.flatMap(contourLines(field, box), (line) => edgeRuns(Arr.zipWith(line, Arr.drop(line, 1), (point, next) => ({
|
|
119
|
-
next,
|
|
120
|
-
point,
|
|
121
|
-
strict: strictAt(point, next),
|
|
122
|
-
}))));
|
|
123
|
-
return {
|
|
124
|
-
boundary,
|
|
125
|
-
fill: contourFill(field, box),
|
|
126
|
-
kind: "region",
|
|
127
|
-
};
|
|
128
|
-
});
|
|
56
|
+
/**
|
|
57
|
+
* Places every point of a path, back to the first for a loop; one point that
|
|
58
|
+
* is not finite breaks it.
|
|
59
|
+
*/
|
|
60
|
+
function pathBranch(points, closed, scope) {
|
|
61
|
+
return Result.map(Result.all(Arr.map(points, (point) => planeFormulaPoint(point, scope))), (placed) => Option.match(Option.all(placed), {
|
|
62
|
+
onNone: () => [],
|
|
63
|
+
onSome: (corners) => [
|
|
64
|
+
closed ? [...corners, ...Arr.take(corners, 1)] : corners,
|
|
65
|
+
],
|
|
66
|
+
}));
|
|
129
67
|
}
|
|
130
68
|
/**
|
|
131
69
|
* Samples one plane formula object inside its frame. `named` holds the input
|
|
@@ -159,6 +97,14 @@ export function planeFormulaGeometry(object, box, scope, named = []) {
|
|
|
159
97
|
}, box, object.angle);
|
|
160
98
|
return { branches, kind: "curves" };
|
|
161
99
|
}
|
|
100
|
+
if (object.kind === "marker") {
|
|
101
|
+
const placed = yield* planeFormulaPoint(object, scope);
|
|
102
|
+
return { kind: "points", points: Option.toArray(placed) };
|
|
103
|
+
}
|
|
104
|
+
if (object.kind === "path" || object.kind === "loop") {
|
|
105
|
+
const branches = yield* pathBranch(object.points, object.kind === "loop", scope);
|
|
106
|
+
return { branches, kind: "curves" };
|
|
107
|
+
}
|
|
162
108
|
if (object.kind === "implicit") {
|
|
163
109
|
const relation = yield* readRelation(object.equation);
|
|
164
110
|
const left = compileFormula(relation.left);
|
|
@@ -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/object.d.ts
CHANGED
|
@@ -22,3 +22,5 @@ export declare const MATH_POLYLINE_MESSAGE = "Expected unique polyline vertices.
|
|
|
22
22
|
export declare const MATH_RAY_MESSAGE = "Expected a ray through a position distinct from its start.";
|
|
23
23
|
/** Message for a segment whose two ends coincide. */
|
|
24
24
|
export declare const MATH_SEGMENT_MESSAGE = "Expected a segment with distinct ends.";
|
|
25
|
+
/** Message for a vector whose tail and head coincide. */
|
|
26
|
+
export declare const MATH_VECTOR_MESSAGE = "Expected a vector with distinct tail and head.";
|
package/dist/math/object.js
CHANGED
|
@@ -25,3 +25,5 @@ export const MATH_POLYLINE_MESSAGE = "Expected unique polyline vertices.";
|
|
|
25
25
|
export const MATH_RAY_MESSAGE = "Expected a ray through a position distinct from its start.";
|
|
26
26
|
/** Message for a segment whose two ends coincide. */
|
|
27
27
|
export const MATH_SEGMENT_MESSAGE = "Expected a segment with distinct ends.";
|
|
28
|
+
/** Message for a vector whose tail and head coincide. */
|
|
29
|
+
export const MATH_VECTOR_MESSAGE = "Expected a vector with distinct tail and head.";
|
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;
|
|
@@ -147,6 +169,18 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
147
169
|
readonly x: Schema.Finite;
|
|
148
170
|
readonly y: Schema.Finite;
|
|
149
171
|
}>;
|
|
172
|
+
}>, Schema.Struct<{
|
|
173
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
174
|
+
readonly id: Schema.String;
|
|
175
|
+
readonly from: Schema.Struct<{
|
|
176
|
+
readonly x: Schema.Finite;
|
|
177
|
+
readonly y: Schema.Finite;
|
|
178
|
+
}>;
|
|
179
|
+
readonly kind: Schema.Literal<"vector">;
|
|
180
|
+
readonly to: Schema.Struct<{
|
|
181
|
+
readonly x: Schema.Finite;
|
|
182
|
+
readonly y: Schema.Finite;
|
|
183
|
+
}>;
|
|
150
184
|
}>]>;
|
|
151
185
|
export type PlaneMathObject = typeof PlaneMathObjectSchema.Type;
|
|
152
186
|
/** Exact Cartesian frame presented behind a plane construction. */
|
|
@@ -168,12 +202,18 @@ export declare const PlaneMathViewSchema: Schema.Struct<{
|
|
|
168
202
|
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
169
203
|
}>;
|
|
170
204
|
export type PlaneMathView = typeof PlaneMathViewSchema.Type;
|
|
171
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* One coordinate anchor resolved against a separate rich-label map. Its
|
|
207
|
+
* position is exact, or placed by formulas of the sliders so it follows them.
|
|
208
|
+
*/
|
|
172
209
|
export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
173
|
-
readonly at: Schema.Struct<{
|
|
210
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
174
211
|
readonly x: Schema.Finite;
|
|
175
212
|
readonly y: Schema.Finite;
|
|
176
|
-
}
|
|
213
|
+
}>, Schema.Struct<{
|
|
214
|
+
readonly x: Schema.String;
|
|
215
|
+
readonly y: Schema.String;
|
|
216
|
+
}>]>;
|
|
177
217
|
readonly key: Schema.String;
|
|
178
218
|
readonly objectId: Schema.String;
|
|
179
219
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
@@ -193,10 +233,13 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
193
233
|
}>;
|
|
194
234
|
}>;
|
|
195
235
|
readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
196
|
-
readonly at: Schema.Struct<{
|
|
236
|
+
readonly at: Schema.Union<readonly [Schema.Struct<{
|
|
197
237
|
readonly x: Schema.Finite;
|
|
198
238
|
readonly y: Schema.Finite;
|
|
199
|
-
}
|
|
239
|
+
}>, Schema.Struct<{
|
|
240
|
+
readonly x: Schema.String;
|
|
241
|
+
readonly y: Schema.String;
|
|
242
|
+
}>]>;
|
|
200
243
|
readonly key: Schema.String;
|
|
201
244
|
readonly objectId: Schema.String;
|
|
202
245
|
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
@@ -216,6 +259,20 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
216
259
|
readonly id: Schema.String;
|
|
217
260
|
readonly equation: Schema.String;
|
|
218
261
|
readonly kind: Schema.Literal<"implicit">;
|
|
262
|
+
}>, Schema.Struct<{
|
|
263
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
264
|
+
readonly id: Schema.String;
|
|
265
|
+
readonly kind: Schema.Literal<"loop">;
|
|
266
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
267
|
+
readonly x: Schema.String;
|
|
268
|
+
readonly y: Schema.String;
|
|
269
|
+
}>>;
|
|
270
|
+
}>, Schema.Struct<{
|
|
271
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
272
|
+
readonly id: Schema.String;
|
|
273
|
+
readonly kind: Schema.Literal<"marker">;
|
|
274
|
+
readonly x: Schema.String;
|
|
275
|
+
readonly y: Schema.String;
|
|
219
276
|
}>, Schema.Struct<{
|
|
220
277
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
221
278
|
readonly id: Schema.String;
|
|
@@ -226,6 +283,14 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
226
283
|
}>;
|
|
227
284
|
readonly x: Schema.String;
|
|
228
285
|
readonly y: Schema.String;
|
|
286
|
+
}>, Schema.Struct<{
|
|
287
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
288
|
+
readonly id: Schema.String;
|
|
289
|
+
readonly kind: Schema.Literal<"path">;
|
|
290
|
+
readonly points: Schema.$Array<Schema.Struct<{
|
|
291
|
+
readonly x: Schema.String;
|
|
292
|
+
readonly y: Schema.String;
|
|
293
|
+
}>>;
|
|
229
294
|
}>, Schema.Struct<{
|
|
230
295
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
231
296
|
readonly id: Schema.String;
|
|
@@ -348,14 +413,31 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
348
413
|
readonly x: Schema.Finite;
|
|
349
414
|
readonly y: Schema.Finite;
|
|
350
415
|
}>;
|
|
416
|
+
}>, Schema.Struct<{
|
|
417
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
418
|
+
readonly id: Schema.String;
|
|
419
|
+
readonly from: Schema.Struct<{
|
|
420
|
+
readonly x: Schema.Finite;
|
|
421
|
+
readonly y: Schema.Finite;
|
|
422
|
+
}>;
|
|
423
|
+
readonly kind: Schema.Literal<"vector">;
|
|
424
|
+
readonly to: Schema.Struct<{
|
|
425
|
+
readonly x: Schema.Finite;
|
|
426
|
+
readonly y: Schema.Finite;
|
|
427
|
+
}>;
|
|
351
428
|
}>]>>;
|
|
352
429
|
readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
430
|
+
readonly label: Schema.optionalKey<Schema.String>;
|
|
353
431
|
readonly max: Schema.Finite;
|
|
354
432
|
readonly min: Schema.Finite;
|
|
355
433
|
readonly name: Schema.String;
|
|
356
434
|
readonly step: Schema.optionalKey<Schema.Finite>;
|
|
357
435
|
readonly value: Schema.Finite;
|
|
358
436
|
}>>>;
|
|
437
|
+
readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
438
|
+
readonly formula: Schema.String;
|
|
439
|
+
readonly key: Schema.String;
|
|
440
|
+
}>>>;
|
|
359
441
|
readonly space: Schema.Literal<"plane">;
|
|
360
442
|
readonly view: Schema.Struct<{
|
|
361
443
|
readonly kind: Schema.Literal<"fit">;
|
package/dist/math/plane.js
CHANGED
|
@@ -2,9 +2,10 @@ 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 {
|
|
7
|
+
import { sliderFormulaIssues } from "#contracts/math/formula/slider";
|
|
8
|
+
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_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. */
|
|
10
11
|
function hasPlaneArea(vertices) {
|
|
@@ -75,6 +76,18 @@ const PlaneSegmentObjectSchema = Schema.Struct({
|
|
|
75
76
|
}).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !samePlanePoint(from, to), {
|
|
76
77
|
message: MATH_SEGMENT_MESSAGE,
|
|
77
78
|
})));
|
|
79
|
+
/**
|
|
80
|
+
* An arrow from its tail to its head, such as a displacement, a force, or a
|
|
81
|
+
* position vector: a segment that ends in an arrowhead.
|
|
82
|
+
*/
|
|
83
|
+
const PlaneVectorObjectSchema = Schema.Struct({
|
|
84
|
+
...MathObjectFields,
|
|
85
|
+
from: PlanePointSchema,
|
|
86
|
+
kind: Schema.Literal("vector"),
|
|
87
|
+
to: PlanePointSchema,
|
|
88
|
+
}).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !samePlanePoint(from, to), {
|
|
89
|
+
message: MATH_VECTOR_MESSAGE,
|
|
90
|
+
})));
|
|
78
91
|
const PlanePolylineObjectSchema = Schema.Struct({
|
|
79
92
|
...MathObjectFields,
|
|
80
93
|
kind: Schema.Literal("polyline"),
|
|
@@ -124,6 +137,7 @@ export const PlaneMathObjectSchema = Schema.Union([
|
|
|
124
137
|
PlaneQuadraticObjectSchema,
|
|
125
138
|
PlaneRayObjectSchema,
|
|
126
139
|
PlaneSegmentObjectSchema,
|
|
140
|
+
PlaneVectorObjectSchema,
|
|
127
141
|
]);
|
|
128
142
|
/** Exact Cartesian frame presented behind a plane construction. */
|
|
129
143
|
export const PlaneMathFrameSchema = Schema.Struct({
|
|
@@ -136,19 +150,24 @@ export const PlaneMathViewSchema = Schema.Struct({
|
|
|
136
150
|
kind: Schema.Literal("fit"),
|
|
137
151
|
padding: Schema.optionalKey(MathViewPaddingSchema),
|
|
138
152
|
});
|
|
139
|
-
/**
|
|
140
|
-
|
|
153
|
+
/**
|
|
154
|
+
* One coordinate anchor resolved against a separate rich-label map. Its
|
|
155
|
+
* position is exact, or placed by formulas of the sliders so it follows them.
|
|
156
|
+
*/
|
|
157
|
+
export const PlaneLabelAnchorSchema = Schema.Struct(mathLabelAnchorFields(Schema.Union([PlanePointSchema, PlaneFormulaPointSchema])));
|
|
141
158
|
/** Complete stable plane visual before rich labels are attached. */
|
|
142
159
|
export const PlaneMathVisualSchema = Schema.Struct({
|
|
143
160
|
frame: PlaneMathFrameSchema,
|
|
144
161
|
labels: Schema.optionalKey(Schema.Array(PlaneLabelAnchorSchema)),
|
|
145
162
|
objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
|
|
146
163
|
parameters: Schema.optionalKey(Schema.Array(FormulaParameterSchema)),
|
|
164
|
+
readouts: Schema.optionalKey(Schema.Array(FormulaReadoutSchema)),
|
|
147
165
|
space: Schema.Literal("plane"),
|
|
148
166
|
view: PlaneMathViewSchema,
|
|
149
|
-
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, parameters = [], view }) => [
|
|
167
|
+
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, parameters = [], readouts = [], view, }) => [
|
|
150
168
|
...mathVisualIdentityIssues(objects, labels),
|
|
151
169
|
...formulaScopeIssues(objects, planeFormulaFields, parameters),
|
|
170
|
+
...sliderFormulaIssues(labels, readouts, parameters),
|
|
152
171
|
...planeBoundsIssues(frame, objects, labels, parameterScope(parameters)),
|
|
153
172
|
...planeResolutionIssues(frame, objects, labels, view),
|
|
154
173
|
])));
|