@nakafa/aksara-contracts 0.32.0 → 0.33.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.
@@ -0,0 +1,7 @@
1
+ import type { Schema } from "effect";
2
+ import type { PlaneLabelAnchor, PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
3
+ import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject } from "#contracts/math/space";
4
+ /** Reports every finite plane object or label that escapes its authored frame. */
5
+ export declare function planeBoundsIssues(frame: PlaneMathFrame, objects: readonly PlaneMathObject[], labels: readonly PlaneLabelAnchor[]): readonly Schema.FilterIssue[];
6
+ /** Reports every finite space object or label that escapes its authored frame. */
7
+ export declare function spaceBoundsIssues(frame: SpaceMathFrame, objects: readonly SpaceMathObject[], labels: readonly SpaceLabelAnchor[]): readonly Schema.FilterIssue[];
@@ -0,0 +1,120 @@
1
+ import { arcContained, axisContains, circleContained, cuboidContained, quadraticContained, } from "#contracts/math/extent";
2
+ import { infinitePathIntersectsBox } from "#contracts/math/intersection";
3
+ /** Checks one plane point against both inclusive frame ranges. */
4
+ function planeContains(frame, point) {
5
+ return [
6
+ { coordinate: point.x, range: frame.x },
7
+ { coordinate: point.y, range: frame.y },
8
+ ].every(({ coordinate, range }) => axisContains(range, coordinate));
9
+ }
10
+ /** Checks one space point against all three inclusive frame ranges. */
11
+ function spaceContains(frame, point) {
12
+ return [
13
+ { coordinate: point.x, range: frame.x },
14
+ { coordinate: point.y, range: frame.y },
15
+ { coordinate: point.z, range: frame.z },
16
+ ].every(({ coordinate, range }) => axisContains(range, coordinate));
17
+ }
18
+ /** Maps one plane path onto the Cartesian frame slabs it traverses. */
19
+ function planeAxes(frame, start, through) {
20
+ return [
21
+ { range: frame.x, start: start.x, through: through.x },
22
+ { range: frame.y, start: start.y, through: through.y },
23
+ ];
24
+ }
25
+ /** Maps one space path onto the Cartesian frame slabs it traverses. */
26
+ function spaceAxes(frame, start, through) {
27
+ return [
28
+ { range: frame.x, start: start.x, through: through.x },
29
+ { range: frame.y, start: start.y, through: through.y },
30
+ { range: frame.z, start: start.z, through: through.z },
31
+ ];
32
+ }
33
+ /** Checks whether one plane object has complete visible geometry in its frame. */
34
+ function planeObjectContained(frame, object) {
35
+ if (object.kind === "line") {
36
+ const [start, through] = object.through;
37
+ return infinitePathIntersectsBox(object.kind, planeAxes(frame, start, through));
38
+ }
39
+ if (object.kind === "ray") {
40
+ return infinitePathIntersectsBox(object.kind, planeAxes(frame, object.from, object.through));
41
+ }
42
+ if (object.kind === "point") {
43
+ return planeContains(frame, object.at);
44
+ }
45
+ if (object.kind === "segment") {
46
+ return [object.from, object.to].every((point) => planeContains(frame, point));
47
+ }
48
+ if (object.kind === "polyline" || object.kind === "polygon") {
49
+ return object.vertices.every((point) => planeContains(frame, point));
50
+ }
51
+ if (object.kind === "circle") {
52
+ return circleContained(frame, object);
53
+ }
54
+ if (object.kind === "arc") {
55
+ return arcContained(frame, object);
56
+ }
57
+ return quadraticContained(frame, object);
58
+ }
59
+ /** Checks whether one space object has complete visible geometry in its frame. */
60
+ function spaceObjectContained(frame, object) {
61
+ if (object.kind === "line") {
62
+ const [start, through] = object.through;
63
+ return infinitePathIntersectsBox(object.kind, spaceAxes(frame, start, through));
64
+ }
65
+ if (object.kind === "ray") {
66
+ return infinitePathIntersectsBox(object.kind, spaceAxes(frame, object.from, object.through));
67
+ }
68
+ if (object.kind === "point") {
69
+ return spaceContains(frame, object.at);
70
+ }
71
+ if (object.kind === "segment") {
72
+ return [object.from, object.to].every((point) => spaceContains(frame, point));
73
+ }
74
+ if (object.kind === "polyline" || object.kind === "polygon") {
75
+ return object.vertices.every((point) => spaceContains(frame, point));
76
+ }
77
+ return cuboidContained(frame, object);
78
+ }
79
+ /** Reports every finite plane object or label that escapes its authored frame. */
80
+ export function planeBoundsIssues(frame, objects, labels) {
81
+ return [
82
+ ...objects.flatMap((object, index) => planeObjectContained(frame, object)
83
+ ? []
84
+ : [
85
+ {
86
+ issue: "Expected plane geometry visible inside its frame.",
87
+ path: ["objects", index],
88
+ },
89
+ ]),
90
+ ...labels.flatMap((label, index) => planeContains(frame, label.at)
91
+ ? []
92
+ : [
93
+ {
94
+ issue: "Expected a plane label anchor inside the Cartesian frame.",
95
+ path: ["labels", index, "at"],
96
+ },
97
+ ]),
98
+ ];
99
+ }
100
+ /** Reports every finite space object or label that escapes its authored frame. */
101
+ export function spaceBoundsIssues(frame, objects, labels) {
102
+ return [
103
+ ...objects.flatMap((object, index) => spaceObjectContained(frame, object)
104
+ ? []
105
+ : [
106
+ {
107
+ issue: "Expected space geometry visible inside its frame.",
108
+ path: ["objects", index],
109
+ },
110
+ ]),
111
+ ...labels.flatMap((label, index) => spaceContains(frame, label.at)
112
+ ? []
113
+ : [
114
+ {
115
+ issue: "Expected a space label anchor inside the Cartesian frame.",
116
+ path: ["labels", index, "at"],
117
+ },
118
+ ]),
119
+ ];
120
+ }
@@ -0,0 +1,21 @@
1
+ import type { PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
2
+ import type { SpaceMathFrame, SpaceMathObject } from "#contracts/math/space";
3
+ export type AxisRange = PlaneMathFrame["x"];
4
+ /** Checks one finite coordinate against its inclusive authored range. */
5
+ export declare function axisContains(range: AxisRange, coordinate: number): boolean;
6
+ /** Checks the exact endpoints and cardinal extrema of one directed arc. */
7
+ export declare function arcContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
8
+ readonly kind: "arc";
9
+ }>): boolean;
10
+ /** Checks one circle through exact radius-to-boundary comparisons. */
11
+ export declare function circleContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
12
+ readonly kind: "circle";
13
+ }>): boolean;
14
+ /** Checks the complete quadratic domain and exact endpoint or vertex range. */
15
+ export declare function quadraticContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
16
+ readonly kind: "quadratic";
17
+ }>): boolean;
18
+ /** Checks one cuboid through exact half-extent-to-boundary comparisons. */
19
+ export declare function cuboidContained(frame: SpaceMathFrame, object: Extract<SpaceMathObject, {
20
+ readonly kind: "cuboid";
21
+ }>): boolean;
@@ -0,0 +1,134 @@
1
+ import { BigDecimal } from "effect";
2
+ import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
3
+ import { decimal, makeRatio, ratioInRange } from "#contracts/math/rational";
4
+ /** Checks one finite coordinate against its inclusive authored range. */
5
+ export function axisContains(range, coordinate) {
6
+ return coordinate >= range.min && coordinate <= range.max;
7
+ }
8
+ /** Checks one exact decimal coordinate against an inclusive authored range. */
9
+ function axisContainsDecimal(range, coordinate) {
10
+ return (BigDecimal.isGreaterThanOrEqualTo(coordinate, decimal(range.min)) &&
11
+ BigDecimal.isLessThanOrEqualTo(coordinate, decimal(range.max)));
12
+ }
13
+ /** Checks an exact signed offset without rounding it into its origin. */
14
+ function axisContainsOffset(range, origin, offset) {
15
+ if (!axisContains(range, origin)) {
16
+ return false;
17
+ }
18
+ const center = decimal(origin);
19
+ const clearance = BigDecimal.isNegative(offset)
20
+ ? BigDecimal.subtract(center, decimal(range.min))
21
+ : BigDecimal.subtract(decimal(range.max), center);
22
+ return BigDecimal.isLessThanOrEqualTo(BigDecimal.abs(offset), clearance);
23
+ }
24
+ /** Checks one translated coordinate within its explicit numeric error envelope. */
25
+ function axisContainsTranslated(range, origin, offset, error) {
26
+ const coordinate = BigDecimal.sum(decimal(origin), offset);
27
+ return (BigDecimal.isGreaterThanOrEqualTo(coordinate, BigDecimal.subtract(decimal(range.min), error)) &&
28
+ BigDecimal.isLessThanOrEqualTo(coordinate, BigDecimal.sum(decimal(range.max), error)));
29
+ }
30
+ /** Normalizes one angle to the canonical half-open degree interval. */
31
+ function normalizeDegrees(value) {
32
+ return ((value % 360) + 360) % 360;
33
+ }
34
+ /** Returns whether one cardinal angle lies on the authored directed arc. */
35
+ function arcContainsAngle(start, sweep, angle) {
36
+ return sweep > 0
37
+ ? normalizeDegrees(angle - start) <= sweep
38
+ : normalizeDegrees(start - angle) <= -sweep;
39
+ }
40
+ /** Resolves exact cardinals or a trig offset with its renderer error envelope. */
41
+ function arcOffset(radius, angle) {
42
+ const normalized = normalizeDegrees(angle);
43
+ const exactRadius = decimal(radius);
44
+ const exact = BigDecimal.fromBigInt(0n);
45
+ if (normalized === 0) {
46
+ return { error: exact, x: exactRadius, y: exact };
47
+ }
48
+ if (normalized === 90) {
49
+ return { error: exact, x: exact, y: exactRadius };
50
+ }
51
+ if (normalized === 180) {
52
+ return { error: exact, x: BigDecimal.negate(exactRadius), y: exact };
53
+ }
54
+ if (normalized === 270) {
55
+ return { error: exact, x: exact, y: BigDecimal.negate(exactRadius) };
56
+ }
57
+ const radians = (normalized * Math.PI) / 180;
58
+ const error = decimal(Math.max(Number.MIN_VALUE, radius * GEOMETRY_TOLERANCE));
59
+ return {
60
+ error,
61
+ x: decimal(radius * Math.cos(radians)),
62
+ y: decimal(radius * Math.sin(radians)),
63
+ };
64
+ }
65
+ /** Checks the exact endpoints and cardinal extrema of one directed arc. */
66
+ export function arcContained(frame, object) {
67
+ const angles = [
68
+ object.startDegrees,
69
+ object.startDegrees + object.sweepDegrees,
70
+ ];
71
+ for (const angle of [0, 90, 180, 270]) {
72
+ if (arcContainsAngle(object.startDegrees, object.sweepDegrees, angle)) {
73
+ angles.push(angle);
74
+ }
75
+ }
76
+ return angles.every((angle) => {
77
+ const offset = arcOffset(object.radius, angle);
78
+ return (axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
79
+ axisContainsTranslated(frame.y, object.center.y, offset.y, offset.error));
80
+ });
81
+ }
82
+ /** Checks one circle through exact radius-to-boundary comparisons. */
83
+ export function circleContained(frame, object) {
84
+ const radius = decimal(object.radius);
85
+ const negativeRadius = BigDecimal.negate(radius);
86
+ return (axisContainsOffset(frame.x, object.center.x, radius) &&
87
+ axisContainsOffset(frame.x, object.center.x, negativeRadius) &&
88
+ axisContainsOffset(frame.y, object.center.y, radius) &&
89
+ axisContainsOffset(frame.y, object.center.y, negativeRadius));
90
+ }
91
+ /** Evaluates one quadratic exactly at a finite authored input. */
92
+ function quadraticValue(object, input) {
93
+ const value = decimal(input);
94
+ const { a, b, c } = object.coefficients;
95
+ return BigDecimal.sumAll([
96
+ BigDecimal.multiply(BigDecimal.multiply(decimal(a), value), value),
97
+ BigDecimal.multiply(decimal(b), value),
98
+ decimal(c),
99
+ ]);
100
+ }
101
+ /** Checks the complete quadratic domain and exact endpoint or vertex range. */
102
+ export function quadraticContained(frame, object) {
103
+ const inputRange = object.inputAxis === "x" ? frame.x : frame.y;
104
+ const outputRange = object.inputAxis === "x" ? frame.y : frame.x;
105
+ if (![object.domain.min, object.domain.max].every((input) => axisContains(inputRange, input))) {
106
+ return false;
107
+ }
108
+ if (![object.domain.min, object.domain.max].every((input) => axisContainsDecimal(outputRange, quadraticValue(object, input)))) {
109
+ return false;
110
+ }
111
+ const a = decimal(object.coefficients.a);
112
+ const b = decimal(object.coefficients.b);
113
+ const c = decimal(object.coefficients.c);
114
+ const fourA = BigDecimal.multiply(decimal(4), a);
115
+ const vertex = makeRatio(BigDecimal.negate(b), BigDecimal.multiply(decimal(2), a));
116
+ if (!ratioInRange(vertex, object.domain.min, object.domain.max)) {
117
+ return true;
118
+ }
119
+ const vertexValue = makeRatio(BigDecimal.subtract(BigDecimal.multiply(fourA, c), BigDecimal.multiply(b, b)), fourA);
120
+ return ratioInRange(vertexValue, outputRange.min, outputRange.max);
121
+ }
122
+ /** Checks one cuboid through exact half-extent-to-boundary comparisons. */
123
+ export function cuboidContained(frame, object) {
124
+ const halfLength = BigDecimal.multiply(decimal(object.size.length), decimal(0.5));
125
+ const halfHeight = BigDecimal.multiply(decimal(object.size.height), decimal(0.5));
126
+ const halfWidth = BigDecimal.multiply(decimal(object.size.width), decimal(0.5));
127
+ const dimensions = [
128
+ [frame.x, object.center.x, halfLength],
129
+ [frame.y, object.center.y, halfHeight],
130
+ [frame.z, object.center.z, halfWidth],
131
+ ];
132
+ return dimensions.every(([range, center, extent]) => axisContainsOffset(range, center, extent) &&
133
+ axisContainsOffset(range, center, BigDecimal.negate(extent)));
134
+ }
@@ -0,0 +1,14 @@
1
+ import { type AxisRange } from "#contracts/math/extent";
2
+ import type { PlaneMathObject } from "#contracts/math/plane";
3
+ /** One Cartesian slab traversed by the same parametric path. */
4
+ export interface AxisTraversal {
5
+ readonly range: AxisRange;
6
+ readonly start: number;
7
+ readonly through: number;
8
+ }
9
+ type InfinitePathKind = Extract<PlaneMathObject, {
10
+ readonly kind: "line" | "ray";
11
+ }>["kind"];
12
+ /** Checks whether one infinite line or ray intersects an inclusive axis-aligned box. */
13
+ export declare function infinitePathIntersectsBox(kind: InfinitePathKind, axes: readonly AxisTraversal[]): boolean;
14
+ export {};
@@ -0,0 +1,37 @@
1
+ import { axisContains } from "#contracts/math/extent";
2
+ import { compareRatios, differenceRatio, numberRatio, } from "#contracts/math/rational";
3
+ /** Keeps the greater finite side of one lower parameter boundary. */
4
+ function later(current, candidate) {
5
+ return current === undefined || compareRatios(current, candidate) < 0
6
+ ? candidate
7
+ : current;
8
+ }
9
+ /** Keeps the lesser finite side of one upper parameter boundary. */
10
+ function earlier(current, candidate) {
11
+ return current === undefined || compareRatios(candidate, current) < 0
12
+ ? candidate
13
+ : current;
14
+ }
15
+ /** Checks whether one infinite line or ray intersects an inclusive axis-aligned box. */
16
+ export function infinitePathIntersectsBox(kind, axes) {
17
+ let entry = kind === "ray" ? numberRatio(0) : undefined;
18
+ let exit;
19
+ for (const axis of axes) {
20
+ if (axis.start === axis.through) {
21
+ if (!axisContains(axis.range, axis.start)) {
22
+ return false;
23
+ }
24
+ continue;
25
+ }
26
+ const first = differenceRatio(axis.range.min, axis.start, axis.through);
27
+ const second = differenceRatio(axis.range.max, axis.start, axis.through);
28
+ const near = compareRatios(first, second) <= 0 ? first : second;
29
+ const far = near === first ? second : first;
30
+ entry = later(entry, near);
31
+ exit = earlier(exit, far);
32
+ if (exit !== undefined && compareRatios(entry, exit) > 0) {
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
@@ -20,23 +20,6 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
20
20
  }>;
21
21
  readonly kind: Schema.Literal<"circle">;
22
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
23
  }>, Schema.Struct<{
41
24
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
42
25
  readonly id: Schema.String;
@@ -87,6 +70,20 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
87
70
  readonly x: Schema.Finite;
88
71
  readonly y: Schema.Finite;
89
72
  }>]>;
73
+ }>, Schema.Struct<{
74
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
75
+ readonly id: Schema.String;
76
+ readonly coefficients: Schema.Struct<{
77
+ readonly a: Schema.Finite;
78
+ readonly b: Schema.Finite;
79
+ readonly c: Schema.Finite;
80
+ }>;
81
+ readonly domain: Schema.Struct<{
82
+ readonly max: Schema.Finite;
83
+ readonly min: Schema.Finite;
84
+ }>;
85
+ readonly inputAxis: Schema.Literals<readonly ["x", "y"]>;
86
+ readonly kind: Schema.Literal<"quadratic">;
90
87
  }>, Schema.Struct<{
91
88
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
92
89
  readonly id: Schema.String;
@@ -111,24 +108,8 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
111
108
  readonly x: Schema.Finite;
112
109
  readonly y: Schema.Finite;
113
110
  }>;
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
111
  }>]>;
112
+ export type PlaneMathObject = typeof PlaneMathObjectSchema.Type;
132
113
  /** Exact Cartesian frame presented behind a plane construction. */
133
114
  export declare const PlaneMathFrameSchema: Schema.Struct<{
134
115
  readonly axes: Schema.Literals<readonly ["hidden", "visible"]>;
@@ -143,6 +124,7 @@ export declare const PlaneMathFrameSchema: Schema.Struct<{
143
124
  readonly min: Schema.Finite;
144
125
  }>;
145
126
  }>;
127
+ export type PlaneMathFrame = typeof PlaneMathFrameSchema.Type;
146
128
  /** Plane visuals use semantic fit instead of renderer camera parameters. */
147
129
  export declare const PlaneMathViewSchema: Schema.Struct<{
148
130
  readonly kind: Schema.Literal<"fit">;
@@ -157,6 +139,7 @@ export declare const PlaneLabelAnchorSchema: Schema.Struct<{
157
139
  readonly key: Schema.String;
158
140
  readonly placement: Schema.optionalKey<Schema.Literals<readonly ["above", "above-left", "above-right", "below", "below-left", "below-right", "center", "left", "right"]>>;
159
141
  }>;
142
+ export type PlaneLabelAnchor = typeof PlaneLabelAnchorSchema.Type;
160
143
  /** Complete stable plane visual before rich labels are attached. */
161
144
  export declare const PlaneMathVisualSchema: Schema.Struct<{
162
145
  readonly frame: Schema.Struct<{
@@ -200,23 +183,6 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
200
183
  }>;
201
184
  readonly kind: Schema.Literal<"circle">;
202
185
  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
186
  }>, Schema.Struct<{
221
187
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
222
188
  readonly id: Schema.String;
@@ -267,6 +233,20 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
267
233
  readonly x: Schema.Finite;
268
234
  readonly y: Schema.Finite;
269
235
  }>]>;
236
+ }>, Schema.Struct<{
237
+ readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
238
+ readonly id: Schema.String;
239
+ readonly coefficients: Schema.Struct<{
240
+ readonly a: Schema.Finite;
241
+ readonly b: Schema.Finite;
242
+ readonly c: Schema.Finite;
243
+ }>;
244
+ readonly domain: Schema.Struct<{
245
+ readonly max: Schema.Finite;
246
+ readonly min: Schema.Finite;
247
+ }>;
248
+ readonly inputAxis: Schema.Literals<readonly ["x", "y"]>;
249
+ readonly kind: Schema.Literal<"quadratic">;
270
250
  }>, Schema.Struct<{
271
251
  readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
272
252
  readonly id: Schema.String;
@@ -291,23 +271,6 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
291
271
  readonly x: Schema.Finite;
292
272
  readonly y: Schema.Finite;
293
273
  }>;
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
274
  }>]>>;
312
275
  readonly space: Schema.Literal<"plane">;
313
276
  readonly view: Schema.Struct<{
@@ -1,5 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAppearanceSchema, MathAxisRangeSchema, MathFeatureVisibilitySchema, MathLabelPlacementSchema, MathViewPaddingSchema, MathVisualKeySchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
3
+ import { planeBoundsIssues } from "#contracts/math/bounds";
3
4
  const ObjectFields = {
4
5
  appearance: MathAppearanceSchema,
5
6
  id: MathVisualKeySchema,
@@ -83,18 +84,6 @@ const PlanePolygonObjectSchema = Schema.Struct({
83
84
  kind: Schema.Literal("polygon"),
84
85
  vertices: PlaneShapeSchema,
85
86
  }).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
87
  const PlaneCircleObjectSchema = Schema.Struct({
99
88
  ...ObjectFields,
100
89
  center: PlanePointSchema,
@@ -109,18 +98,30 @@ const PlaneArcObjectSchema = Schema.Struct({
109
98
  startDegrees: ArcStartDegreesSchema,
110
99
  sweepDegrees: ArcSweepDegreesSchema,
111
100
  });
101
+ const PlaneQuadraticObjectSchema = Schema.Struct({
102
+ ...ObjectFields,
103
+ coefficients: Schema.Struct({
104
+ a: Schema.Finite.pipe(Schema.check(Schema.makeFilter((value) => value !== 0, {
105
+ message: "Expected a non-zero quadratic coefficient.",
106
+ }))),
107
+ b: Schema.Finite,
108
+ c: Schema.Finite,
109
+ }),
110
+ domain: MathAxisRangeSchema,
111
+ inputAxis: Schema.Literals(["x", "y"]),
112
+ kind: Schema.Literal("quadratic"),
113
+ });
112
114
  /** Mathematical objects supported by a Cartesian plane scene. */
113
115
  export const PlaneMathObjectSchema = Schema.Union([
114
116
  PlaneArcObjectSchema,
115
117
  PlaneCircleObjectSchema,
116
- PlaneClosedSplineObjectSchema,
117
118
  PlaneLineObjectSchema,
118
119
  PlanePointObjectSchema,
119
120
  PlanePolygonObjectSchema,
120
121
  PlanePolylineObjectSchema,
122
+ PlaneQuadraticObjectSchema,
121
123
  PlaneRayObjectSchema,
122
124
  PlaneSegmentObjectSchema,
123
- PlaneSplineObjectSchema,
124
125
  ]);
125
126
  /** Exact Cartesian frame presented behind a plane construction. */
126
127
  export const PlaneMathFrameSchema = Schema.Struct({
@@ -148,4 +149,7 @@ export const PlaneMathVisualSchema = Schema.Struct({
148
149
  objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
149
150
  space: Schema.Literal("plane"),
150
151
  view: PlaneMathViewSchema,
151
- }).pipe(Schema.check(Schema.makeFilter(({ labels = [], objects }) => mathVisualIdentityIssues(objects, labels))));
152
+ }).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects }) => [
153
+ ...mathVisualIdentityIssues(objects, labels),
154
+ ...planeBoundsIssues(frame, objects, labels),
155
+ ])));
@@ -0,0 +1,18 @@
1
+ import { BigDecimal } from "effect";
2
+ /** Exact quotient whose denominator is normalized to a positive value. */
3
+ export interface ExactRatio {
4
+ readonly denominator: BigDecimal.BigDecimal;
5
+ readonly numerator: BigDecimal.BigDecimal;
6
+ }
7
+ /** Creates one exact decimal from a schema-validated finite number. */
8
+ export declare function decimal(value: number): BigDecimal.BigDecimal;
9
+ /** Creates one exact ratio from a known non-zero denominator. */
10
+ export declare function makeRatio(numerator: BigDecimal.BigDecimal, denominator: BigDecimal.BigDecimal): ExactRatio;
11
+ /** Creates one exact ratio from a finite number. */
12
+ export declare function numberRatio(value: number): ExactRatio;
13
+ /** Creates the exact path parameter `(boundary - start) / (through - start)`. */
14
+ export declare function differenceRatio(boundary: number, start: number, through: number): ExactRatio;
15
+ /** Compares two exact ratios without division or floating-point overflow. */
16
+ export declare function compareRatios(left: ExactRatio, right: ExactRatio): import("effect/Ordering").Ordering;
17
+ /** Checks one exact ratio against inclusive finite numeric boundaries. */
18
+ export declare function ratioInRange(ratio: ExactRatio, minimum: number, maximum: number): boolean;
@@ -0,0 +1,33 @@
1
+ import { BigDecimal } from "effect";
2
+ const unit = BigDecimal.fromBigInt(1n);
3
+ /** Creates one exact decimal from a schema-validated finite number. */
4
+ export function decimal(value) {
5
+ return BigDecimal.fromNumberUnsafe(value);
6
+ }
7
+ /** Creates one exact ratio from a known non-zero denominator. */
8
+ export function makeRatio(numerator, denominator) {
9
+ return BigDecimal.isNegative(denominator)
10
+ ? {
11
+ denominator: BigDecimal.negate(denominator),
12
+ numerator: BigDecimal.negate(numerator),
13
+ }
14
+ : { denominator, numerator };
15
+ }
16
+ /** Creates one exact ratio from a finite number. */
17
+ export function numberRatio(value) {
18
+ return { denominator: unit, numerator: decimal(value) };
19
+ }
20
+ /** Creates the exact path parameter `(boundary - start) / (through - start)`. */
21
+ export function differenceRatio(boundary, start, through) {
22
+ const origin = decimal(start);
23
+ return makeRatio(BigDecimal.subtract(decimal(boundary), origin), BigDecimal.subtract(decimal(through), origin));
24
+ }
25
+ /** Compares two exact ratios without division or floating-point overflow. */
26
+ export function compareRatios(left, right) {
27
+ return BigDecimal.Order(BigDecimal.multiply(left.numerator, right.denominator), BigDecimal.multiply(right.numerator, left.denominator));
28
+ }
29
+ /** Checks one exact ratio against inclusive finite numeric boundaries. */
30
+ export function ratioInRange(ratio, minimum, maximum) {
31
+ return (compareRatios(numberRatio(minimum), ratio) <= 0 &&
32
+ compareRatios(ratio, numberRatio(maximum)) <= 0);
33
+ }