@nakafa/aksara-contracts 0.30.0 → 0.32.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/README.md +5 -1
- package/dist/math/base.d.ts +49 -0
- package/dist/math/base.js +103 -0
- package/dist/math/plane.d.ts +317 -0
- package/dist/math/plane.js +151 -0
- package/dist/math/space.d.ts +397 -0
- package/dist/math/space.js +129 -0
- package/dist/math/vector.d.ts +3 -0
- package/dist/math/vector.js +74 -0
- package/dist/math/visual.d.ts +984 -0
- package/dist/math/visual.js +15 -0
- package/dist/preview/artifact.js +2 -2
- package/dist/projection/digest.d.ts +36 -0
- package/dist/projection/question.d.ts +159 -1
- package/dist/projection/question.js +75 -17
- package/dist/projection/spec.d.ts +199 -1
- package/dist/projection/spec.js +8 -1
- package/dist/projection/verify.d.ts +36 -0
- package/dist/release/rollback/spec.d.ts +228 -12
- package/dist/transport/batch.d.ts +405 -0
- package/dist/transport/batch.js +14 -2
- package/dist/transport/group.d.ts +632 -32
- package/dist/transport/group.js +2 -1
- package/dist/transport/request.d.ts +1122 -132
- package/dist/transport/response.d.ts +300 -12
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -33,9 +33,13 @@ Current consumers use unversioned semantic Interfaces:
|
|
|
33
33
|
validates every signed route and projection against it.
|
|
34
34
|
- `projection/page` owns stable public page identities, localized paths, and
|
|
35
35
|
signed metadata for human, agent, and sitemap delivery.
|
|
36
|
+
- `math/visual` owns the unversioned, renderer-neutral plane and space scene
|
|
37
|
+
contract, including exact straight geometry, rich-label anchors, and the
|
|
38
|
+
axis-aligned cuboid dimension mapping.
|
|
39
|
+
|
|
36
40
|
## Publication dates
|
|
37
41
|
|
|
38
|
-
Article, material,
|
|
42
|
+
Article, material, public page, and question metadata carry one required
|
|
39
43
|
`datePublished` and one optional `dateModified`, both as exact `DateOnly`
|
|
40
44
|
values.
|
|
41
45
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
/** Relative floating-point tolerance used by normalized geometry predicates. */
|
|
3
|
+
export declare const GEOMETRY_TOLERANCE: number;
|
|
4
|
+
/** Stable source identity shared by visual objects and rich-label anchors. */
|
|
5
|
+
export declare const MathVisualKeySchema: Schema.String;
|
|
6
|
+
/** Finite point in one Cartesian plane. */
|
|
7
|
+
export declare const PlanePointSchema: Schema.Struct<{
|
|
8
|
+
readonly x: Schema.Finite;
|
|
9
|
+
readonly y: Schema.Finite;
|
|
10
|
+
}>;
|
|
11
|
+
export type PlanePoint = typeof PlanePointSchema.Type;
|
|
12
|
+
/** Finite point in one three-dimensional Cartesian space. */
|
|
13
|
+
export declare const SpacePointSchema: Schema.Struct<{
|
|
14
|
+
readonly x: Schema.Finite;
|
|
15
|
+
readonly y: Schema.Finite;
|
|
16
|
+
readonly z: Schema.Finite;
|
|
17
|
+
}>;
|
|
18
|
+
export type SpacePoint = typeof SpacePointSchema.Type;
|
|
19
|
+
/** Ordered visible interval for one Cartesian axis. */
|
|
20
|
+
export declare const MathAxisRangeSchema: Schema.Struct<{
|
|
21
|
+
readonly max: Schema.Finite;
|
|
22
|
+
readonly min: Schema.Finite;
|
|
23
|
+
}>;
|
|
24
|
+
/** Semantic visibility of one mathematical frame feature. */
|
|
25
|
+
export declare const MathFeatureVisibilitySchema: Schema.Literals<readonly ["hidden", "visible"]>;
|
|
26
|
+
/** Stable visual roles that Nakafa maps to its current design system. */
|
|
27
|
+
export declare const MathAppearanceSchema: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
28
|
+
/** Screen-relative placement of one rich label around its exact anchor. */
|
|
29
|
+
export declare const MathLabelPlacementSchema: Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>;
|
|
30
|
+
/** Optional non-negative padding used by a semantic fit view. */
|
|
31
|
+
export declare const MathViewPaddingSchema: Schema.Finite;
|
|
32
|
+
/** Strictly positive finite measurement. */
|
|
33
|
+
export declare const PositiveMeasureSchema: Schema.Finite;
|
|
34
|
+
/** Canonical start angle for one plane arc, measured in degrees. */
|
|
35
|
+
export declare const ArcStartDegreesSchema: Schema.Finite;
|
|
36
|
+
/** Non-zero directed sweep shorter than one full circle. */
|
|
37
|
+
export declare const ArcSweepDegreesSchema: Schema.Finite;
|
|
38
|
+
/** Returns whether two plane positions are exactly the same authored point. */
|
|
39
|
+
export declare function samePlanePoint(left: PlanePoint, right: PlanePoint): boolean;
|
|
40
|
+
/** Returns whether two space positions are exactly the same authored point. */
|
|
41
|
+
export declare function sameSpacePoint(left: SpacePoint, right: SpacePoint): boolean;
|
|
42
|
+
/** Reports every repeated scene identity at its exact authored key path. */
|
|
43
|
+
export declare function mathVisualIdentityIssues(objects: readonly {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
}[], labels: readonly {
|
|
46
|
+
readonly key: string;
|
|
47
|
+
}[]): readonly Schema.FilterIssue[];
|
|
48
|
+
/** Checks that an authored coordinate sequence contains no repeated position. */
|
|
49
|
+
export declare function hasUniquePositions<T>(values: readonly T[], same: (left: T, right: T) => boolean): boolean;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
const KEY_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
3
|
+
/** Relative floating-point tolerance used by normalized geometry predicates. */
|
|
4
|
+
export const GEOMETRY_TOLERANCE = Number.EPSILON * 128;
|
|
5
|
+
/** Stable source identity shared by visual objects and rich-label anchors. */
|
|
6
|
+
export const MathVisualKeySchema = Schema.String.pipe(Schema.check(Schema.makeFilter((key) => KEY_PATTERN.test(key), {
|
|
7
|
+
message: "Expected a lower-kebab mathematical visual key.",
|
|
8
|
+
})));
|
|
9
|
+
/** Finite point in one Cartesian plane. */
|
|
10
|
+
export const PlanePointSchema = Schema.Struct({
|
|
11
|
+
x: Schema.Finite,
|
|
12
|
+
y: Schema.Finite,
|
|
13
|
+
});
|
|
14
|
+
/** Finite point in one three-dimensional Cartesian space. */
|
|
15
|
+
export const SpacePointSchema = Schema.Struct({
|
|
16
|
+
x: Schema.Finite,
|
|
17
|
+
y: Schema.Finite,
|
|
18
|
+
z: Schema.Finite,
|
|
19
|
+
});
|
|
20
|
+
/** Ordered visible interval for one Cartesian axis. */
|
|
21
|
+
export const MathAxisRangeSchema = Schema.Struct({
|
|
22
|
+
max: Schema.Finite,
|
|
23
|
+
min: Schema.Finite,
|
|
24
|
+
}).pipe(Schema.check(Schema.makeFilter(({ max, min }) => min < max, {
|
|
25
|
+
message: "Expected an axis range whose minimum is below its maximum.",
|
|
26
|
+
})));
|
|
27
|
+
/** Semantic visibility of one mathematical frame feature. */
|
|
28
|
+
export const MathFeatureVisibilitySchema = Schema.Literals([
|
|
29
|
+
"hidden",
|
|
30
|
+
"visible",
|
|
31
|
+
]);
|
|
32
|
+
/** Stable visual roles that Nakafa maps to its current design system. */
|
|
33
|
+
export const MathAppearanceSchema = Schema.Literals([
|
|
34
|
+
"answer",
|
|
35
|
+
"construction",
|
|
36
|
+
"highlight",
|
|
37
|
+
"primary",
|
|
38
|
+
"reference",
|
|
39
|
+
"secondary",
|
|
40
|
+
"warning",
|
|
41
|
+
]);
|
|
42
|
+
/** Screen-relative placement of one rich label around its exact anchor. */
|
|
43
|
+
export const MathLabelPlacementSchema = Schema.Literals([
|
|
44
|
+
"above",
|
|
45
|
+
"above-left",
|
|
46
|
+
"above-right",
|
|
47
|
+
"below",
|
|
48
|
+
"below-left",
|
|
49
|
+
"below-right",
|
|
50
|
+
"center",
|
|
51
|
+
"left",
|
|
52
|
+
"right",
|
|
53
|
+
]);
|
|
54
|
+
/** Optional non-negative padding used by a semantic fit view. */
|
|
55
|
+
export const MathViewPaddingSchema = Schema.Finite.pipe(Schema.check(Schema.isGreaterThanOrEqualTo(0)));
|
|
56
|
+
/** Strictly positive finite measurement. */
|
|
57
|
+
export const PositiveMeasureSchema = Schema.Finite.pipe(Schema.check(Schema.isGreaterThan(0)));
|
|
58
|
+
/** Canonical start angle for one plane arc, measured in degrees. */
|
|
59
|
+
export const ArcStartDegreesSchema = Schema.Finite.pipe(Schema.check(Schema.isGreaterThanOrEqualTo(0)), Schema.check(Schema.isLessThan(360)));
|
|
60
|
+
/** Non-zero directed sweep shorter than one full circle. */
|
|
61
|
+
export const ArcSweepDegreesSchema = Schema.Finite.pipe(Schema.check(Schema.makeFilter((sweep) => sweep !== 0 && Math.abs(sweep) < 360, {
|
|
62
|
+
message: "Expected a non-zero arc sweep shorter than one full circle.",
|
|
63
|
+
})));
|
|
64
|
+
/** Returns whether two plane positions are exactly the same authored point. */
|
|
65
|
+
export function samePlanePoint(left, right) {
|
|
66
|
+
return left.x === right.x && left.y === right.y;
|
|
67
|
+
}
|
|
68
|
+
/** Returns whether two space positions are exactly the same authored point. */
|
|
69
|
+
export function sameSpacePoint(left, right) {
|
|
70
|
+
return left.x === right.x && left.y === right.y && left.z === right.z;
|
|
71
|
+
}
|
|
72
|
+
/** Returns every repeated-key index after its first authored occurrence. */
|
|
73
|
+
function duplicateKeyIndexes(values, keyOf) {
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
const duplicates = [];
|
|
76
|
+
for (const [index, value] of values.entries()) {
|
|
77
|
+
const key = keyOf(value);
|
|
78
|
+
if (seen.has(key)) {
|
|
79
|
+
duplicates.push(index);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
seen.add(key);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return duplicates;
|
|
86
|
+
}
|
|
87
|
+
/** Reports every repeated scene identity at its exact authored key path. */
|
|
88
|
+
export function mathVisualIdentityIssues(objects, labels) {
|
|
89
|
+
return [
|
|
90
|
+
...duplicateKeyIndexes(objects, ({ id }) => id).map((index) => ({
|
|
91
|
+
issue: "Expected a unique mathematical object id.",
|
|
92
|
+
path: ["objects", index, "id"],
|
|
93
|
+
})),
|
|
94
|
+
...duplicateKeyIndexes(labels, ({ key }) => key).map((index) => ({
|
|
95
|
+
issue: "Expected a unique mathematical label key.",
|
|
96
|
+
path: ["labels", index, "key"],
|
|
97
|
+
})),
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
/** Checks that an authored coordinate sequence contains no repeated position. */
|
|
101
|
+
export function hasUniquePositions(values, same) {
|
|
102
|
+
return values.every((value, index) => values.findIndex((candidate) => same(value, candidate)) === index);
|
|
103
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
/** Mathematical objects supported by a Cartesian plane scene. */
|
|
3
|
+
export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct<{
|
|
4
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
5
|
+
readonly id: Schema.String;
|
|
6
|
+
readonly center: Schema.Struct<{
|
|
7
|
+
readonly x: Schema.Finite;
|
|
8
|
+
readonly y: Schema.Finite;
|
|
9
|
+
}>;
|
|
10
|
+
readonly kind: Schema.Literal<"arc">;
|
|
11
|
+
readonly radius: Schema.Finite;
|
|
12
|
+
readonly startDegrees: Schema.Finite;
|
|
13
|
+
readonly sweepDegrees: Schema.Finite;
|
|
14
|
+
}>, Schema.Struct<{
|
|
15
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
16
|
+
readonly id: Schema.String;
|
|
17
|
+
readonly center: Schema.Struct<{
|
|
18
|
+
readonly x: Schema.Finite;
|
|
19
|
+
readonly y: Schema.Finite;
|
|
20
|
+
}>;
|
|
21
|
+
readonly kind: Schema.Literal<"circle">;
|
|
22
|
+
readonly radius: Schema.Finite;
|
|
23
|
+
}>, Schema.Struct<{
|
|
24
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
25
|
+
readonly id: Schema.String;
|
|
26
|
+
readonly kind: Schema.Literal<"closed-spline">;
|
|
27
|
+
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
28
|
+
readonly x: Schema.Finite;
|
|
29
|
+
readonly y: Schema.Finite;
|
|
30
|
+
}>, Schema.Struct<{
|
|
31
|
+
readonly x: Schema.Finite;
|
|
32
|
+
readonly y: Schema.Finite;
|
|
33
|
+
}>, Schema.Struct<{
|
|
34
|
+
readonly x: Schema.Finite;
|
|
35
|
+
readonly y: Schema.Finite;
|
|
36
|
+
}>]>, readonly [Schema.Struct<{
|
|
37
|
+
readonly x: Schema.Finite;
|
|
38
|
+
readonly y: Schema.Finite;
|
|
39
|
+
}>]>;
|
|
40
|
+
}>, Schema.Struct<{
|
|
41
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
42
|
+
readonly id: Schema.String;
|
|
43
|
+
readonly kind: Schema.Literal<"line">;
|
|
44
|
+
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
45
|
+
readonly x: Schema.Finite;
|
|
46
|
+
readonly y: Schema.Finite;
|
|
47
|
+
}>, Schema.Struct<{
|
|
48
|
+
readonly x: Schema.Finite;
|
|
49
|
+
readonly y: Schema.Finite;
|
|
50
|
+
}>]>;
|
|
51
|
+
}>, Schema.Struct<{
|
|
52
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
53
|
+
readonly id: Schema.String;
|
|
54
|
+
readonly at: Schema.Struct<{
|
|
55
|
+
readonly x: Schema.Finite;
|
|
56
|
+
readonly y: Schema.Finite;
|
|
57
|
+
}>;
|
|
58
|
+
readonly kind: Schema.Literal<"point">;
|
|
59
|
+
}>, Schema.Struct<{
|
|
60
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
61
|
+
readonly id: Schema.String;
|
|
62
|
+
readonly kind: Schema.Literal<"polygon">;
|
|
63
|
+
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
64
|
+
readonly x: Schema.Finite;
|
|
65
|
+
readonly y: Schema.Finite;
|
|
66
|
+
}>, Schema.Struct<{
|
|
67
|
+
readonly x: Schema.Finite;
|
|
68
|
+
readonly y: Schema.Finite;
|
|
69
|
+
}>, Schema.Struct<{
|
|
70
|
+
readonly x: Schema.Finite;
|
|
71
|
+
readonly y: Schema.Finite;
|
|
72
|
+
}>]>, readonly [Schema.Struct<{
|
|
73
|
+
readonly x: Schema.Finite;
|
|
74
|
+
readonly y: Schema.Finite;
|
|
75
|
+
}>]>;
|
|
76
|
+
}>, Schema.Struct<{
|
|
77
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
78
|
+
readonly id: Schema.String;
|
|
79
|
+
readonly kind: Schema.Literal<"polyline">;
|
|
80
|
+
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
81
|
+
readonly x: Schema.Finite;
|
|
82
|
+
readonly y: Schema.Finite;
|
|
83
|
+
}>, Schema.Struct<{
|
|
84
|
+
readonly x: Schema.Finite;
|
|
85
|
+
readonly y: Schema.Finite;
|
|
86
|
+
}>]>, readonly [Schema.Struct<{
|
|
87
|
+
readonly x: Schema.Finite;
|
|
88
|
+
readonly y: Schema.Finite;
|
|
89
|
+
}>]>;
|
|
90
|
+
}>, Schema.Struct<{
|
|
91
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
92
|
+
readonly id: Schema.String;
|
|
93
|
+
readonly from: Schema.Struct<{
|
|
94
|
+
readonly x: Schema.Finite;
|
|
95
|
+
readonly y: Schema.Finite;
|
|
96
|
+
}>;
|
|
97
|
+
readonly kind: Schema.Literal<"ray">;
|
|
98
|
+
readonly through: Schema.Struct<{
|
|
99
|
+
readonly x: Schema.Finite;
|
|
100
|
+
readonly y: Schema.Finite;
|
|
101
|
+
}>;
|
|
102
|
+
}>, Schema.Struct<{
|
|
103
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
104
|
+
readonly id: Schema.String;
|
|
105
|
+
readonly from: Schema.Struct<{
|
|
106
|
+
readonly x: Schema.Finite;
|
|
107
|
+
readonly y: Schema.Finite;
|
|
108
|
+
}>;
|
|
109
|
+
readonly kind: Schema.Literal<"segment">;
|
|
110
|
+
readonly to: Schema.Struct<{
|
|
111
|
+
readonly x: Schema.Finite;
|
|
112
|
+
readonly y: Schema.Finite;
|
|
113
|
+
}>;
|
|
114
|
+
}>, Schema.Struct<{
|
|
115
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
116
|
+
readonly id: Schema.String;
|
|
117
|
+
readonly kind: Schema.Literal<"spline">;
|
|
118
|
+
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
119
|
+
readonly x: Schema.Finite;
|
|
120
|
+
readonly y: Schema.Finite;
|
|
121
|
+
}>, Schema.Struct<{
|
|
122
|
+
readonly x: Schema.Finite;
|
|
123
|
+
readonly y: Schema.Finite;
|
|
124
|
+
}>, Schema.Struct<{
|
|
125
|
+
readonly x: Schema.Finite;
|
|
126
|
+
readonly y: Schema.Finite;
|
|
127
|
+
}>]>, readonly [Schema.Struct<{
|
|
128
|
+
readonly x: Schema.Finite;
|
|
129
|
+
readonly y: Schema.Finite;
|
|
130
|
+
}>]>;
|
|
131
|
+
}>]>;
|
|
132
|
+
/** Exact Cartesian frame presented behind a plane construction. */
|
|
133
|
+
export declare const PlaneMathFrameSchema: Schema.Struct<{
|
|
134
|
+
readonly axes: Schema.Literals<readonly ["hidden", "visible"]>;
|
|
135
|
+
readonly grid: Schema.Literals<readonly ["hidden", "visible"]>;
|
|
136
|
+
readonly kind: Schema.Literal<"cartesian">;
|
|
137
|
+
readonly x: Schema.Struct<{
|
|
138
|
+
readonly max: Schema.Finite;
|
|
139
|
+
readonly min: Schema.Finite;
|
|
140
|
+
}>;
|
|
141
|
+
readonly y: Schema.Struct<{
|
|
142
|
+
readonly max: Schema.Finite;
|
|
143
|
+
readonly min: Schema.Finite;
|
|
144
|
+
}>;
|
|
145
|
+
}>;
|
|
146
|
+
/** Plane visuals use semantic fit instead of renderer camera parameters. */
|
|
147
|
+
export declare const PlaneMathViewSchema: Schema.Struct<{
|
|
148
|
+
readonly kind: Schema.Literal<"fit">;
|
|
149
|
+
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
150
|
+
}>;
|
|
151
|
+
/** One coordinate anchor resolved against a separate rich-label map. */
|
|
152
|
+
export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
153
|
+
readonly at: Schema.Struct<{
|
|
154
|
+
readonly x: Schema.Finite;
|
|
155
|
+
readonly y: Schema.Finite;
|
|
156
|
+
}>;
|
|
157
|
+
readonly key: Schema.String;
|
|
158
|
+
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
159
|
+
}>;
|
|
160
|
+
/** Complete stable plane visual before rich labels are attached. */
|
|
161
|
+
export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
162
|
+
readonly frame: Schema.Struct<{
|
|
163
|
+
readonly axes: Schema.Literals<readonly ["hidden", "visible"]>;
|
|
164
|
+
readonly grid: Schema.Literals<readonly ["hidden", "visible"]>;
|
|
165
|
+
readonly kind: Schema.Literal<"cartesian">;
|
|
166
|
+
readonly x: Schema.Struct<{
|
|
167
|
+
readonly max: Schema.Finite;
|
|
168
|
+
readonly min: Schema.Finite;
|
|
169
|
+
}>;
|
|
170
|
+
readonly y: Schema.Struct<{
|
|
171
|
+
readonly max: Schema.Finite;
|
|
172
|
+
readonly min: Schema.Finite;
|
|
173
|
+
}>;
|
|
174
|
+
}>;
|
|
175
|
+
readonly labels: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
176
|
+
readonly at: Schema.Struct<{
|
|
177
|
+
readonly x: Schema.Finite;
|
|
178
|
+
readonly y: Schema.Finite;
|
|
179
|
+
}>;
|
|
180
|
+
readonly key: Schema.String;
|
|
181
|
+
readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
|
|
182
|
+
}>>>;
|
|
183
|
+
readonly objects: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
|
|
184
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
185
|
+
readonly id: Schema.String;
|
|
186
|
+
readonly center: Schema.Struct<{
|
|
187
|
+
readonly x: Schema.Finite;
|
|
188
|
+
readonly y: Schema.Finite;
|
|
189
|
+
}>;
|
|
190
|
+
readonly kind: Schema.Literal<"arc">;
|
|
191
|
+
readonly radius: Schema.Finite;
|
|
192
|
+
readonly startDegrees: Schema.Finite;
|
|
193
|
+
readonly sweepDegrees: Schema.Finite;
|
|
194
|
+
}>, Schema.Struct<{
|
|
195
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
196
|
+
readonly id: Schema.String;
|
|
197
|
+
readonly center: Schema.Struct<{
|
|
198
|
+
readonly x: Schema.Finite;
|
|
199
|
+
readonly y: Schema.Finite;
|
|
200
|
+
}>;
|
|
201
|
+
readonly kind: Schema.Literal<"circle">;
|
|
202
|
+
readonly radius: Schema.Finite;
|
|
203
|
+
}>, Schema.Struct<{
|
|
204
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
205
|
+
readonly id: Schema.String;
|
|
206
|
+
readonly kind: Schema.Literal<"closed-spline">;
|
|
207
|
+
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
208
|
+
readonly x: Schema.Finite;
|
|
209
|
+
readonly y: Schema.Finite;
|
|
210
|
+
}>, Schema.Struct<{
|
|
211
|
+
readonly x: Schema.Finite;
|
|
212
|
+
readonly y: Schema.Finite;
|
|
213
|
+
}>, Schema.Struct<{
|
|
214
|
+
readonly x: Schema.Finite;
|
|
215
|
+
readonly y: Schema.Finite;
|
|
216
|
+
}>]>, readonly [Schema.Struct<{
|
|
217
|
+
readonly x: Schema.Finite;
|
|
218
|
+
readonly y: Schema.Finite;
|
|
219
|
+
}>]>;
|
|
220
|
+
}>, Schema.Struct<{
|
|
221
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
222
|
+
readonly id: Schema.String;
|
|
223
|
+
readonly kind: Schema.Literal<"line">;
|
|
224
|
+
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
225
|
+
readonly x: Schema.Finite;
|
|
226
|
+
readonly y: Schema.Finite;
|
|
227
|
+
}>, Schema.Struct<{
|
|
228
|
+
readonly x: Schema.Finite;
|
|
229
|
+
readonly y: Schema.Finite;
|
|
230
|
+
}>]>;
|
|
231
|
+
}>, Schema.Struct<{
|
|
232
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
233
|
+
readonly id: Schema.String;
|
|
234
|
+
readonly at: Schema.Struct<{
|
|
235
|
+
readonly x: Schema.Finite;
|
|
236
|
+
readonly y: Schema.Finite;
|
|
237
|
+
}>;
|
|
238
|
+
readonly kind: Schema.Literal<"point">;
|
|
239
|
+
}>, Schema.Struct<{
|
|
240
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
241
|
+
readonly id: Schema.String;
|
|
242
|
+
readonly kind: Schema.Literal<"polygon">;
|
|
243
|
+
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
244
|
+
readonly x: Schema.Finite;
|
|
245
|
+
readonly y: Schema.Finite;
|
|
246
|
+
}>, Schema.Struct<{
|
|
247
|
+
readonly x: Schema.Finite;
|
|
248
|
+
readonly y: Schema.Finite;
|
|
249
|
+
}>, Schema.Struct<{
|
|
250
|
+
readonly x: Schema.Finite;
|
|
251
|
+
readonly y: Schema.Finite;
|
|
252
|
+
}>]>, readonly [Schema.Struct<{
|
|
253
|
+
readonly x: Schema.Finite;
|
|
254
|
+
readonly y: Schema.Finite;
|
|
255
|
+
}>]>;
|
|
256
|
+
}>, Schema.Struct<{
|
|
257
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
258
|
+
readonly id: Schema.String;
|
|
259
|
+
readonly kind: Schema.Literal<"polyline">;
|
|
260
|
+
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
261
|
+
readonly x: Schema.Finite;
|
|
262
|
+
readonly y: Schema.Finite;
|
|
263
|
+
}>, Schema.Struct<{
|
|
264
|
+
readonly x: Schema.Finite;
|
|
265
|
+
readonly y: Schema.Finite;
|
|
266
|
+
}>]>, readonly [Schema.Struct<{
|
|
267
|
+
readonly x: Schema.Finite;
|
|
268
|
+
readonly y: Schema.Finite;
|
|
269
|
+
}>]>;
|
|
270
|
+
}>, Schema.Struct<{
|
|
271
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
272
|
+
readonly id: Schema.String;
|
|
273
|
+
readonly from: Schema.Struct<{
|
|
274
|
+
readonly x: Schema.Finite;
|
|
275
|
+
readonly y: Schema.Finite;
|
|
276
|
+
}>;
|
|
277
|
+
readonly kind: Schema.Literal<"ray">;
|
|
278
|
+
readonly through: Schema.Struct<{
|
|
279
|
+
readonly x: Schema.Finite;
|
|
280
|
+
readonly y: Schema.Finite;
|
|
281
|
+
}>;
|
|
282
|
+
}>, Schema.Struct<{
|
|
283
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
284
|
+
readonly id: Schema.String;
|
|
285
|
+
readonly from: Schema.Struct<{
|
|
286
|
+
readonly x: Schema.Finite;
|
|
287
|
+
readonly y: Schema.Finite;
|
|
288
|
+
}>;
|
|
289
|
+
readonly kind: Schema.Literal<"segment">;
|
|
290
|
+
readonly to: Schema.Struct<{
|
|
291
|
+
readonly x: Schema.Finite;
|
|
292
|
+
readonly y: Schema.Finite;
|
|
293
|
+
}>;
|
|
294
|
+
}>, Schema.Struct<{
|
|
295
|
+
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
296
|
+
readonly id: Schema.String;
|
|
297
|
+
readonly kind: Schema.Literal<"spline">;
|
|
298
|
+
readonly samples: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
299
|
+
readonly x: Schema.Finite;
|
|
300
|
+
readonly y: Schema.Finite;
|
|
301
|
+
}>, Schema.Struct<{
|
|
302
|
+
readonly x: Schema.Finite;
|
|
303
|
+
readonly y: Schema.Finite;
|
|
304
|
+
}>, Schema.Struct<{
|
|
305
|
+
readonly x: Schema.Finite;
|
|
306
|
+
readonly y: Schema.Finite;
|
|
307
|
+
}>]>, readonly [Schema.Struct<{
|
|
308
|
+
readonly x: Schema.Finite;
|
|
309
|
+
readonly y: Schema.Finite;
|
|
310
|
+
}>]>;
|
|
311
|
+
}>]>>;
|
|
312
|
+
readonly space: Schema.Literal<"plane">;
|
|
313
|
+
readonly view: Schema.Struct<{
|
|
314
|
+
readonly kind: Schema.Literal<"fit">;
|
|
315
|
+
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
316
|
+
}>;
|
|
317
|
+
}>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathFeatureVisibilitySchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
|
|
3
|
+
const ObjectFields = {
|
|
4
|
+
appearance: MathAppearanceSchema,
|
|
5
|
+
id: MathVisualKeySchema,
|
|
6
|
+
};
|
|
7
|
+
/** Checks a plane polygon has non-zero signed area. */
|
|
8
|
+
function hasPlaneArea(vertices) {
|
|
9
|
+
const offsets = normalizedPlaneOffsets(vertices);
|
|
10
|
+
let twiceArea = 0;
|
|
11
|
+
let termMagnitude = 0;
|
|
12
|
+
let previous = { x: 0, y: 0 };
|
|
13
|
+
for (const current of offsets.slice(1)) {
|
|
14
|
+
const positive = previous.x * current.y;
|
|
15
|
+
const negative = previous.y * current.x;
|
|
16
|
+
twiceArea += positive - negative;
|
|
17
|
+
termMagnitude += Math.abs(positive) + Math.abs(negative);
|
|
18
|
+
previous = current;
|
|
19
|
+
}
|
|
20
|
+
return Math.abs(twiceArea) > GEOMETRY_TOLERANCE * Math.max(1, termMagnitude);
|
|
21
|
+
}
|
|
22
|
+
/** Translates before scaling so polygon area is independent of its location. */
|
|
23
|
+
function normalizedPlaneOffsets(vertices) {
|
|
24
|
+
const [origin] = vertices;
|
|
25
|
+
let offsets = vertices.map(({ x, y }) => ({
|
|
26
|
+
x: x - origin.x,
|
|
27
|
+
y: y - origin.y,
|
|
28
|
+
}));
|
|
29
|
+
if (offsets.some(({ x, y }) => !(Number.isFinite(x) && Number.isFinite(y)))) {
|
|
30
|
+
let sourceScale = 1;
|
|
31
|
+
for (const { x, y } of vertices) {
|
|
32
|
+
sourceScale = Math.max(sourceScale, Math.abs(x), Math.abs(y));
|
|
33
|
+
}
|
|
34
|
+
offsets = vertices.map(({ x, y }) => ({
|
|
35
|
+
x: x / sourceScale - origin.x / sourceScale,
|
|
36
|
+
y: y / sourceScale - origin.y / sourceScale,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
let extent = 0;
|
|
40
|
+
for (const { x, y } of offsets) {
|
|
41
|
+
extent = Math.max(extent, Math.abs(x), Math.abs(y));
|
|
42
|
+
}
|
|
43
|
+
const divisor = Math.max(extent, Number.MIN_VALUE);
|
|
44
|
+
return offsets.map(({ x, y }) => ({ x: x / divisor, y: y / divisor }));
|
|
45
|
+
}
|
|
46
|
+
const PlanePointObjectSchema = Schema.Struct({
|
|
47
|
+
...ObjectFields,
|
|
48
|
+
at: PlanePointSchema,
|
|
49
|
+
kind: Schema.Literal("point"),
|
|
50
|
+
});
|
|
51
|
+
const PlanePathSchema = Schema.TupleWithRest(Schema.Tuple([PlanePointSchema, PlanePointSchema]), [PlanePointSchema]);
|
|
52
|
+
const PlaneShapeSchema = Schema.TupleWithRest(Schema.Tuple([PlanePointSchema, PlanePointSchema, PlanePointSchema]), [PlanePointSchema]);
|
|
53
|
+
const PlaneLineObjectSchema = Schema.Struct({
|
|
54
|
+
...ObjectFields,
|
|
55
|
+
kind: Schema.Literal("line"),
|
|
56
|
+
through: Schema.Tuple([PlanePointSchema, PlanePointSchema]),
|
|
57
|
+
}).pipe(Schema.check(Schema.makeFilter(({ through: [from, to] }) => !samePlanePoint(from, to), {
|
|
58
|
+
message: "Expected a line through two distinct positions.",
|
|
59
|
+
})));
|
|
60
|
+
const PlaneRayObjectSchema = Schema.Struct({
|
|
61
|
+
...ObjectFields,
|
|
62
|
+
from: PlanePointSchema,
|
|
63
|
+
kind: Schema.Literal("ray"),
|
|
64
|
+
through: PlanePointSchema,
|
|
65
|
+
}).pipe(Schema.check(Schema.makeFilter(({ from, through }) => !samePlanePoint(from, through), {
|
|
66
|
+
message: "Expected a ray through a position distinct from its start.",
|
|
67
|
+
})));
|
|
68
|
+
const PlaneSegmentObjectSchema = Schema.Struct({
|
|
69
|
+
...ObjectFields,
|
|
70
|
+
from: PlanePointSchema,
|
|
71
|
+
kind: Schema.Literal("segment"),
|
|
72
|
+
to: PlanePointSchema,
|
|
73
|
+
}).pipe(Schema.check(Schema.makeFilter(({ from, to }) => !samePlanePoint(from, to), {
|
|
74
|
+
message: "Expected a segment with distinct ends.",
|
|
75
|
+
})));
|
|
76
|
+
const PlanePolylineObjectSchema = Schema.Struct({
|
|
77
|
+
...ObjectFields,
|
|
78
|
+
kind: Schema.Literal("polyline"),
|
|
79
|
+
vertices: PlanePathSchema,
|
|
80
|
+
}).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, samePlanePoint), { message: "Expected unique polyline vertices." })));
|
|
81
|
+
const PlanePolygonObjectSchema = Schema.Struct({
|
|
82
|
+
...ObjectFields,
|
|
83
|
+
kind: Schema.Literal("polygon"),
|
|
84
|
+
vertices: PlaneShapeSchema,
|
|
85
|
+
}).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, samePlanePoint) && hasPlaneArea(vertices), { message: "Expected unique vertices forming a non-degenerate polygon." })));
|
|
86
|
+
const PlaneSplineObjectSchema = Schema.Struct({
|
|
87
|
+
...ObjectFields,
|
|
88
|
+
kind: Schema.Literal("spline"),
|
|
89
|
+
samples: PlaneShapeSchema,
|
|
90
|
+
}).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, samePlanePoint), { message: "Expected at least three unique spline samples." })));
|
|
91
|
+
const PlaneClosedSplineObjectSchema = Schema.Struct({
|
|
92
|
+
...ObjectFields,
|
|
93
|
+
kind: Schema.Literal("closed-spline"),
|
|
94
|
+
samples: PlaneShapeSchema,
|
|
95
|
+
}).pipe(Schema.check(Schema.makeFilter(({ samples }) => hasUniquePositions(samples, samePlanePoint), {
|
|
96
|
+
message: "Expected unique closed-spline samples without a repeated closing sample.",
|
|
97
|
+
})));
|
|
98
|
+
const PlaneCircleObjectSchema = Schema.Struct({
|
|
99
|
+
...ObjectFields,
|
|
100
|
+
center: PlanePointSchema,
|
|
101
|
+
kind: Schema.Literal("circle"),
|
|
102
|
+
radius: PositiveMeasureSchema,
|
|
103
|
+
});
|
|
104
|
+
const PlaneArcObjectSchema = Schema.Struct({
|
|
105
|
+
...ObjectFields,
|
|
106
|
+
center: PlanePointSchema,
|
|
107
|
+
kind: Schema.Literal("arc"),
|
|
108
|
+
radius: PositiveMeasureSchema,
|
|
109
|
+
startDegrees: ArcStartDegreesSchema,
|
|
110
|
+
sweepDegrees: ArcSweepDegreesSchema,
|
|
111
|
+
});
|
|
112
|
+
/** Mathematical objects supported by a Cartesian plane scene. */
|
|
113
|
+
export const PlaneMathObjectSchema = Schema.Union([
|
|
114
|
+
PlaneArcObjectSchema,
|
|
115
|
+
PlaneCircleObjectSchema,
|
|
116
|
+
PlaneClosedSplineObjectSchema,
|
|
117
|
+
PlaneLineObjectSchema,
|
|
118
|
+
PlanePointObjectSchema,
|
|
119
|
+
PlanePolygonObjectSchema,
|
|
120
|
+
PlanePolylineObjectSchema,
|
|
121
|
+
PlaneRayObjectSchema,
|
|
122
|
+
PlaneSegmentObjectSchema,
|
|
123
|
+
PlaneSplineObjectSchema,
|
|
124
|
+
]);
|
|
125
|
+
/** Exact Cartesian frame presented behind a plane construction. */
|
|
126
|
+
export const PlaneMathFrameSchema = Schema.Struct({
|
|
127
|
+
axes: MathFeatureVisibilitySchema,
|
|
128
|
+
grid: MathFeatureVisibilitySchema,
|
|
129
|
+
kind: Schema.Literal("cartesian"),
|
|
130
|
+
x: MathAxisRangeSchema,
|
|
131
|
+
y: MathAxisRangeSchema,
|
|
132
|
+
});
|
|
133
|
+
/** Plane visuals use semantic fit instead of renderer camera parameters. */
|
|
134
|
+
export const PlaneMathViewSchema = Schema.Struct({
|
|
135
|
+
kind: Schema.Literal("fit"),
|
|
136
|
+
padding: Schema.optionalKey(MathViewPaddingSchema),
|
|
137
|
+
});
|
|
138
|
+
/** One coordinate anchor resolved against a separate rich-label map. */
|
|
139
|
+
export const PlaneLabelAnchorSchema = Schema.Struct({
|
|
140
|
+
at: PlanePointSchema,
|
|
141
|
+
key: MathVisualKeySchema,
|
|
142
|
+
placement: Schema.optionalKey(MathLabelPlacementSchema),
|
|
143
|
+
});
|
|
144
|
+
/** Complete stable plane visual before rich labels are attached. */
|
|
145
|
+
export const PlaneMathVisualSchema = Schema.Struct({
|
|
146
|
+
frame: PlaneMathFrameSchema,
|
|
147
|
+
labels: Schema.optionalKey(Schema.Array(PlaneLabelAnchorSchema)),
|
|
148
|
+
objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
|
|
149
|
+
space: Schema.Literal("plane"),
|
|
150
|
+
view: PlaneMathViewSchema,
|
|
151
|
+
}).pipe(Schema.check(Schema.makeFilter(({ labels = [], objects }) => mathVisualIdentityIssues(objects, labels))));
|