@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.
@@ -76,10 +76,13 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
76
76
  }>;
77
77
  }>;
78
78
  readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
79
- readonly at: Schema.Struct<{
79
+ readonly at: Schema.Union<readonly [Schema.Struct<{
80
80
  readonly x: Schema.Finite;
81
81
  readonly y: Schema.Finite;
82
- }>;
82
+ }>, Schema.Struct<{
83
+ readonly x: Schema.String;
84
+ readonly y: Schema.String;
85
+ }>]>;
83
86
  readonly key: Schema.String;
84
87
  readonly objectId: Schema.String;
85
88
  readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
@@ -99,6 +102,20 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
99
102
  readonly id: Schema.String;
100
103
  readonly equation: Schema.String;
101
104
  readonly kind: Schema.Literal<"implicit">;
105
+ }>, Schema.Struct<{
106
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
107
+ readonly id: Schema.String;
108
+ readonly kind: Schema.Literal<"loop">;
109
+ readonly points: Schema.$Array<Schema.Struct<{
110
+ readonly x: Schema.String;
111
+ readonly y: Schema.String;
112
+ }>>;
113
+ }>, Schema.Struct<{
114
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
115
+ readonly id: Schema.String;
116
+ readonly kind: Schema.Literal<"marker">;
117
+ readonly x: Schema.String;
118
+ readonly y: Schema.String;
102
119
  }>, Schema.Struct<{
103
120
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
104
121
  readonly id: Schema.String;
@@ -109,6 +126,14 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
109
126
  }>;
110
127
  readonly x: Schema.String;
111
128
  readonly y: Schema.String;
129
+ }>, Schema.Struct<{
130
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
131
+ readonly id: Schema.String;
132
+ readonly kind: Schema.Literal<"path">;
133
+ readonly points: Schema.$Array<Schema.Struct<{
134
+ readonly x: Schema.String;
135
+ readonly y: Schema.String;
136
+ }>>;
112
137
  }>, Schema.Struct<{
113
138
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
114
139
  readonly id: Schema.String;
@@ -233,12 +258,17 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
233
258
  }>;
234
259
  }>]>>;
235
260
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
261
+ readonly label: Schema.optionalKey<Schema.String>;
236
262
  readonly max: Schema.Finite;
237
263
  readonly min: Schema.Finite;
238
264
  readonly name: Schema.String;
239
265
  readonly step: Schema.optionalKey<Schema.Finite>;
240
266
  readonly value: Schema.Finite;
241
267
  }>>>;
268
+ readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
269
+ readonly formula: Schema.String;
270
+ readonly key: Schema.String;
271
+ }>>>;
242
272
  readonly space: Schema.Literal<"plane">;
243
273
  readonly view: Schema.Struct<{
244
274
  readonly kind: Schema.Literal<"fit">;
@@ -477,6 +507,7 @@ export declare const MathVisualPropsSchema: Schema.Struct<{
477
507
  }>;
478
508
  }>]>>;
479
509
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
510
+ readonly label: Schema.optionalKey<Schema.String>;
480
511
  readonly max: Schema.Finite;
481
512
  readonly min: Schema.Finite;
482
513
  readonly name: Schema.String;
@@ -902,10 +933,13 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
902
933
  }>;
903
934
  }>;
904
935
  readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
905
- readonly at: Schema.Struct<{
936
+ readonly at: Schema.Union<readonly [Schema.Struct<{
906
937
  readonly x: Schema.Finite;
907
938
  readonly y: Schema.Finite;
908
- }>;
939
+ }>, Schema.Struct<{
940
+ readonly x: Schema.String;
941
+ readonly y: Schema.String;
942
+ }>]>;
909
943
  readonly key: Schema.String;
910
944
  readonly objectId: Schema.String;
911
945
  readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
@@ -925,6 +959,20 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
925
959
  readonly id: Schema.String;
926
960
  readonly equation: Schema.String;
927
961
  readonly kind: Schema.Literal<"implicit">;
962
+ }>, Schema.Struct<{
963
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
964
+ readonly id: Schema.String;
965
+ readonly kind: Schema.Literal<"loop">;
966
+ readonly points: Schema.$Array<Schema.Struct<{
967
+ readonly x: Schema.String;
968
+ readonly y: Schema.String;
969
+ }>>;
970
+ }>, Schema.Struct<{
971
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
972
+ readonly id: Schema.String;
973
+ readonly kind: Schema.Literal<"marker">;
974
+ readonly x: Schema.String;
975
+ readonly y: Schema.String;
928
976
  }>, Schema.Struct<{
929
977
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
930
978
  readonly id: Schema.String;
@@ -935,6 +983,14 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
935
983
  }>;
936
984
  readonly x: Schema.String;
937
985
  readonly y: Schema.String;
986
+ }>, Schema.Struct<{
987
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
988
+ readonly id: Schema.String;
989
+ readonly kind: Schema.Literal<"path">;
990
+ readonly points: Schema.$Array<Schema.Struct<{
991
+ readonly x: Schema.String;
992
+ readonly y: Schema.String;
993
+ }>>;
938
994
  }>, Schema.Struct<{
939
995
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
940
996
  readonly id: Schema.String;
@@ -1059,12 +1115,17 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
1059
1115
  }>;
1060
1116
  }>]>>;
1061
1117
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1118
+ readonly label: Schema.optionalKey<Schema.String>;
1062
1119
  readonly max: Schema.Finite;
1063
1120
  readonly min: Schema.Finite;
1064
1121
  readonly name: Schema.String;
1065
1122
  readonly step: Schema.optionalKey<Schema.Finite>;
1066
1123
  readonly value: Schema.Finite;
1067
1124
  }>>>;
1125
+ readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1126
+ readonly formula: Schema.String;
1127
+ readonly key: Schema.String;
1128
+ }>>>;
1068
1129
  readonly space: Schema.Literal<"plane">;
1069
1130
  readonly view: Schema.Struct<{
1070
1131
  readonly kind: Schema.Literal<"fit">;
@@ -1303,6 +1364,7 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
1303
1364
  }>;
1304
1365
  }>]>>;
1305
1366
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1367
+ readonly label: Schema.optionalKey<Schema.String>;
1306
1368
  readonly max: Schema.Finite;
1307
1369
  readonly min: Schema.Finite;
1308
1370
  readonly name: Schema.String;
@@ -1799,10 +1861,13 @@ export declare const FigureNodeSchema: Schema.Struct<{
1799
1861
  }>;
1800
1862
  }>;
1801
1863
  readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1802
- readonly at: Schema.Struct<{
1864
+ readonly at: Schema.Union<readonly [Schema.Struct<{
1803
1865
  readonly x: Schema.Finite;
1804
1866
  readonly y: Schema.Finite;
1805
- }>;
1867
+ }>, Schema.Struct<{
1868
+ readonly x: Schema.String;
1869
+ readonly y: Schema.String;
1870
+ }>]>;
1806
1871
  readonly key: Schema.String;
1807
1872
  readonly objectId: Schema.String;
1808
1873
  readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
@@ -1822,6 +1887,20 @@ export declare const FigureNodeSchema: Schema.Struct<{
1822
1887
  readonly id: Schema.String;
1823
1888
  readonly equation: Schema.String;
1824
1889
  readonly kind: Schema.Literal<"implicit">;
1890
+ }>, Schema.Struct<{
1891
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1892
+ readonly id: Schema.String;
1893
+ readonly kind: Schema.Literal<"loop">;
1894
+ readonly points: Schema.$Array<Schema.Struct<{
1895
+ readonly x: Schema.String;
1896
+ readonly y: Schema.String;
1897
+ }>>;
1898
+ }>, Schema.Struct<{
1899
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1900
+ readonly id: Schema.String;
1901
+ readonly kind: Schema.Literal<"marker">;
1902
+ readonly x: Schema.String;
1903
+ readonly y: Schema.String;
1825
1904
  }>, Schema.Struct<{
1826
1905
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1827
1906
  readonly id: Schema.String;
@@ -1832,6 +1911,14 @@ export declare const FigureNodeSchema: Schema.Struct<{
1832
1911
  }>;
1833
1912
  readonly x: Schema.String;
1834
1913
  readonly y: Schema.String;
1914
+ }>, Schema.Struct<{
1915
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1916
+ readonly id: Schema.String;
1917
+ readonly kind: Schema.Literal<"path">;
1918
+ readonly points: Schema.$Array<Schema.Struct<{
1919
+ readonly x: Schema.String;
1920
+ readonly y: Schema.String;
1921
+ }>>;
1835
1922
  }>, Schema.Struct<{
1836
1923
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
1837
1924
  readonly id: Schema.String;
@@ -1956,12 +2043,17 @@ export declare const FigureNodeSchema: Schema.Struct<{
1956
2043
  }>;
1957
2044
  }>]>>;
1958
2045
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
2046
+ readonly label: Schema.optionalKey<Schema.String>;
1959
2047
  readonly max: Schema.Finite;
1960
2048
  readonly min: Schema.Finite;
1961
2049
  readonly name: Schema.String;
1962
2050
  readonly step: Schema.optionalKey<Schema.Finite>;
1963
2051
  readonly value: Schema.Finite;
1964
2052
  }>>>;
2053
+ readonly readouts: Schema.optionalKey<Schema.$Array<Schema.Struct<{
2054
+ readonly formula: Schema.String;
2055
+ readonly key: Schema.String;
2056
+ }>>>;
1965
2057
  readonly space: Schema.Literal<"plane">;
1966
2058
  readonly view: Schema.Struct<{
1967
2059
  readonly kind: Schema.Literal<"fit">;
@@ -2200,6 +2292,7 @@ export declare const FigureNodeSchema: Schema.Struct<{
2200
2292
  }>;
2201
2293
  }>]>>;
2202
2294
  readonly parameters: Schema.optionalKey<Schema.$Array<Schema.Struct<{
2295
+ readonly label: Schema.optionalKey<Schema.String>;
2203
2296
  readonly max: Schema.Finite;
2204
2297
  readonly min: Schema.Finite;
2205
2298
  readonly name: Schema.String;
@@ -1,6 +1,7 @@
1
- import { Array as Arr, Result } from "effect";
1
+ import { Array as Arr, Option, Result } from "effect";
2
2
  import { arcContained, axisContains, circleContained, cuboidContained, quadraticContained, } from "#contracts/math/extent";
3
- import { planeFormulaGeometry, } from "#contracts/math/formula/plane";
3
+ import { isPlaneFormulaPoint } from "#contracts/math/formula/field";
4
+ import { planeFormulaGeometry, planeFormulaPoint, } from "#contracts/math/formula/plane";
4
5
  import { geometryVisible } from "#contracts/math/formula/scope";
5
6
  import { spaceFormulaGeometry } from "#contracts/math/formula/space";
6
7
  import { infinitePathIntersectsBox } from "#contracts/math/intersection";
@@ -45,11 +46,14 @@ function sampledVisible(geometry, frame) {
45
46
  function planeObjectContained(frame, object, scope, labels) {
46
47
  if (object.kind === "function") {
47
48
  const axis = object.inputAxis ?? "x";
48
- const named = Arr.flatMap(labels, ({ at, objectId }) => objectId === object.id ? [at[axis]] : []);
49
+ const named = Arr.flatMap(labels, ({ at, objectId }) => objectId === object.id && !isPlaneFormulaPoint(at) ? [at[axis]] : []);
49
50
  return sampledVisible(planeFormulaGeometry(object, frame, scope, named), frame);
50
51
  }
51
52
  if (object.kind === "implicit" ||
53
+ object.kind === "loop" ||
54
+ object.kind === "marker" ||
52
55
  object.kind === "parametric" ||
56
+ object.kind === "path" ||
53
57
  object.kind === "polar" ||
54
58
  object.kind === "region") {
55
59
  return sampledVisible(planeFormulaGeometry(object, frame, scope), frame);
@@ -106,6 +110,19 @@ function spaceObjectContained(frame, object, scope) {
106
110
  }
107
111
  return cuboidContained(frame, object);
108
112
  }
113
+ /**
114
+ * Whether a plane label starts inside its frame. A label placed by formulas is
115
+ * checked where the sliders start; a formula that does not read is reported by
116
+ * its own field, so it is not reported again.
117
+ */
118
+ function planeLabelContained(frame, label, scope) {
119
+ if (!isPlaneFormulaPoint(label.at)) {
120
+ return planeContains(frame, label.at);
121
+ }
122
+ const placed = planeFormulaPoint(label.at, scope);
123
+ return (Result.isFailure(placed) ||
124
+ Option.exists(placed.success, (point) => planeContains(frame, point)));
125
+ }
109
126
  /** Reports every finite plane object or label that escapes its authored frame. */
110
127
  export function planeBoundsIssues(frame, objects, labels, scope = {}) {
111
128
  return [
@@ -117,7 +134,7 @@ export function planeBoundsIssues(frame, objects, labels, scope = {}) {
117
134
  path: ["objects", index],
118
135
  },
119
136
  ]),
120
- ...Arr.flatMap(labels, (label, index) => planeContains(frame, label.at)
137
+ ...Arr.flatMap(labels, (label, index) => planeLabelContained(frame, label, scope)
121
138
  ? []
122
139
  : [
123
140
  {
@@ -15,6 +15,20 @@ export declare const PlaneCurveObjectSchemas: 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 PlaneCurveObjectSchemas: 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;
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { MathAxisRangeSchema } from "#contracts/math/base";
3
- import { EquationTextSchema, FormulaTextSchema, InequalityTextSchema, } from "#contracts/math/formula/field";
3
+ import { EquationTextSchema, FormulaTextSchema, InequalityTextSchema, PlaneFormulaPointSchema, } from "#contracts/math/formula/field";
4
4
  import { MathObjectFields } from "#contracts/math/object";
5
5
  /**
6
6
  * The graph of y = f(x), or of x = f(y) when its input axis is y. The renderer
@@ -45,11 +45,39 @@ const PlaneRegionObjectSchema = Schema.Struct({
45
45
  inequalities: Schema.NonEmptyArray(InequalityTextSchema),
46
46
  kind: Schema.Literal("region"),
47
47
  });
48
+ /** A point placed by formulas of the sliders, which moves as they move. */
49
+ const PlaneMarkerObjectSchema = Schema.Struct({
50
+ ...MathObjectFields,
51
+ kind: Schema.Literal("marker"),
52
+ x: FormulaTextSchema,
53
+ y: FormulaTextSchema,
54
+ });
55
+ /**
56
+ * Straight segments through points placed by formulas of the sliders, such as
57
+ * the moving radius of a unit circle. A `path` stays open.
58
+ */
59
+ const PlanePathObjectSchema = Schema.Struct({
60
+ ...MathObjectFields,
61
+ kind: Schema.Literal("path"),
62
+ points: Schema.Array(PlaneFormulaPointSchema).check(Schema.isMinLength(2)),
63
+ });
64
+ /**
65
+ * A closed outline through points placed by formulas of the sliders, such as
66
+ * a right triangle with angle a: the last point joins back to the first.
67
+ */
68
+ const PlaneLoopObjectSchema = Schema.Struct({
69
+ ...MathObjectFields,
70
+ kind: Schema.Literal("loop"),
71
+ points: Schema.Array(PlaneFormulaPointSchema).check(Schema.isMinLength(3)),
72
+ });
48
73
  /** The plane objects a formula defines, which a renderer samples itself. */
49
74
  export const PlaneCurveObjectSchemas = [
50
75
  PlaneFunctionObjectSchema,
51
76
  PlaneImplicitObjectSchema,
77
+ PlaneLoopObjectSchema,
78
+ PlaneMarkerObjectSchema,
52
79
  PlaneParametricObjectSchema,
80
+ PlanePathObjectSchema,
53
81
  PlanePolarObjectSchema,
54
82
  PlaneRegionObjectSchema,
55
83
  ];
@@ -8,8 +8,11 @@ export declare const InequalityTextSchema: Schema.String;
8
8
  /**
9
9
  * One slider a learner moves to change every formula that reads its name. Its
10
10
  * value starts inside its range, and a positive step, when given, snaps it.
11
+ * A `label` names the rich label the slider shows instead of its letter, such
12
+ * as theta for an angle slider named `a`.
11
13
  */
12
14
  export declare const FormulaParameterSchema: Schema.Struct<{
15
+ readonly label: Schema.optionalKey<Schema.String>;
13
16
  readonly max: Schema.Finite;
14
17
  readonly min: Schema.Finite;
15
18
  readonly name: Schema.String;
@@ -17,3 +20,23 @@ export declare const FormulaParameterSchema: Schema.Struct<{
17
20
  readonly value: Schema.Finite;
18
21
  }>;
19
22
  export type FormulaParameter = typeof FormulaParameterSchema.Type;
23
+ /** A plane point placed by formulas of the sliders, such as (cos(a), sin(a)). */
24
+ export declare const PlaneFormulaPointSchema: Schema.Struct<{
25
+ readonly x: Schema.String;
26
+ readonly y: Schema.String;
27
+ }>;
28
+ export type PlaneFormulaPoint = typeof PlaneFormulaPointSchema.Type;
29
+ /** Whether an anchor is placed by formulas rather than written exactly. */
30
+ export declare const isPlaneFormulaPoint: <I>(input: I) => input is I & {
31
+ readonly x: string;
32
+ readonly y: string;
33
+ };
34
+ /**
35
+ * One value a scene shows under its picture, such as cos(a), next to the rich
36
+ * label its key names. It reads only the sliders and follows them.
37
+ */
38
+ export declare const FormulaReadoutSchema: Schema.Struct<{
39
+ readonly formula: Schema.String;
40
+ readonly key: Schema.String;
41
+ }>;
42
+ export type FormulaReadout = typeof FormulaReadoutSchema.Type;
@@ -1,4 +1,5 @@
1
1
  import { Array as Arr, Result, Schema } from "effect";
2
+ import { MathVisualKeySchema } from "#contracts/math/base";
2
3
  import { readFormula, readRelation } from "#contracts/math/formula/parse";
3
4
  import { FormulaParameterNameSchema, } from "#contracts/math/formula/syntax";
4
5
  /** Passes a formula that reads, or names the problem of one that does not. */
@@ -24,8 +25,11 @@ export const InequalityTextSchema = Schema.String.check(Schema.makeFilter(compar
24
25
  /**
25
26
  * One slider a learner moves to change every formula that reads its name. Its
26
27
  * value starts inside its range, and a positive step, when given, snaps it.
28
+ * A `label` names the rich label the slider shows instead of its letter, such
29
+ * as theta for an angle slider named `a`.
27
30
  */
28
31
  export const FormulaParameterSchema = Schema.Struct({
32
+ label: Schema.optionalKey(MathVisualKeySchema),
29
33
  max: Schema.Finite,
30
34
  min: Schema.Finite,
31
35
  name: FormulaParameterNameSchema,
@@ -33,3 +37,18 @@ export const FormulaParameterSchema = Schema.Struct({
33
37
  value: Schema.Finite,
34
38
  }).check(Schema.makeFilter(({ max, min, value }) => (min < max && min <= value && value <= max) ||
35
39
  "Expected min < max and a value between them."));
40
+ /** A plane point placed by formulas of the sliders, such as (cos(a), sin(a)). */
41
+ export const PlaneFormulaPointSchema = Schema.Struct({
42
+ x: FormulaTextSchema,
43
+ y: FormulaTextSchema,
44
+ });
45
+ /** Whether an anchor is placed by formulas rather than written exactly. */
46
+ export const isPlaneFormulaPoint = Schema.is(PlaneFormulaPointSchema);
47
+ /**
48
+ * One value a scene shows under its picture, such as cos(a), next to the rich
49
+ * label its key names. It reads only the sliders and follows them.
50
+ */
51
+ export const FormulaReadoutSchema = Schema.Struct({
52
+ formula: FormulaTextSchema,
53
+ key: MathVisualKeySchema,
54
+ });
@@ -1,11 +1,12 @@
1
- import { Result, Schema } from "effect";
1
+ import { Option, Result, Schema } from "effect";
2
2
  import type { PlaneCurveObjectSchemas } from "#contracts/math/curve";
3
- import { type SampleBox } from "#contracts/math/formula/box";
3
+ import { type SampleBox, type SamplePoint } from "#contracts/math/formula/box";
4
4
  import { type FormulaEvaluator, type FormulaScope } from "#contracts/math/formula/compile";
5
+ import type { PlaneFormulaPoint } from "#contracts/math/formula/field";
5
6
  import type { FormulaError } from "#contracts/math/formula/syntax";
6
7
  /**
7
- * What a formula object draws once sampled: curves, a shaded region with
8
- * solid or dashed edges, a surface grid, or the flat faces of a solid.
8
+ * What a formula object draws once sampled: curves, marked points, a shaded
9
+ * region with solid or dashed edges, a surface grid, or the faces of a solid.
9
10
  */
10
11
  export declare const FormulaGeometrySchema: Schema.Union<readonly [Schema.Struct<{
11
12
  readonly branches: Schema.$Array<Schema.$Array<Schema.Struct<{
@@ -14,6 +15,13 @@ export declare const FormulaGeometrySchema: Schema.Union<readonly [Schema.Struct
14
15
  readonly z: Schema.Finite;
15
16
  }>>>;
16
17
  readonly kind: Schema.Literal<"curves">;
18
+ }>, Schema.Struct<{
19
+ readonly kind: Schema.Literal<"points">;
20
+ readonly points: Schema.$Array<Schema.Struct<{
21
+ readonly x: Schema.Finite;
22
+ readonly y: Schema.Finite;
23
+ readonly z: Schema.Finite;
24
+ }>>;
17
25
  }>, Schema.Struct<{
18
26
  readonly boundary: Schema.$Array<Schema.Struct<{
19
27
  readonly points: Schema.$Array<Schema.Struct<{
@@ -53,6 +61,11 @@ export type FormulaGeometry = typeof FormulaGeometrySchema.Type;
53
61
  export declare function compileText(text: string): Result.Result<FormulaEvaluator, FormulaError>;
54
62
  /** Evaluates one compiled formula with one more variable bound. */
55
63
  export declare function evaluateWith(evaluate: FormulaEvaluator, scope: FormulaScope, name: string, value: number): number;
64
+ /**
65
+ * Places one formula point with the sliders' current values. A coordinate
66
+ * that is not finite there, such as ln(0), places nothing.
67
+ */
68
+ export declare function planeFormulaPoint(point: PlaneFormulaPoint, scope: FormulaScope): Result.Result<Option.Option<SamplePoint>, FormulaError>;
56
69
  /** The plane objects a formula defines. */
57
70
  export type PlaneFormulaObject = (typeof PlaneCurveObjectSchemas)[number]["Type"];
58
71
  /**
@@ -1,20 +1,22 @@
1
- import { Array as Arr, MutableList, Option, Order, Result, Schema, } from "effect";
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 { contourFill, contourLines, } from "#contracts/math/formula/contour";
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 region with
11
- * solid or dashed edges, a surface grid, or the flat faces of a solid.
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
- * Joins consecutive outline pieces of the same kind into one line, so a
59
- * renderer draws a few dashed and solid edges instead of every short piece.
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 edgeRuns(pieces) {
62
- const runs = MutableList.make();
63
- let points = MutableList.make();
64
- let strict = false;
65
- Arr.forEach(pieces, (piece, index) => {
66
- if (index === 0 || piece.strict !== strict) {
67
- if (index > 0) {
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
- /** The region where every inequality holds, with each edge marked strict or not. */
99
- function regionGeometry(inequalities, box, scope) {
100
- return Result.map(Result.all(Arr.map(inequalities, margin)), (margins) => {
101
- const constraints = Arr.map(margins, (each) => ({
102
- field: each.field(scope),
103
- strict: each.strict,
104
- }));
105
- /** The tightest margin at a point: where it is not negative, every inequality holds. */
106
- const field = (x, y) => Math.min(...Arr.map(constraints, (each) => each.field(x, y)));
107
- const byGap = Order.mapInput(Order.Number, (piece) => piece.gap);
108
- /** Whether the inequality nearest a boundary piece is strict, so it draws dashed. */
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);