@nakafa/aksara-contracts 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/math/arc-precision.d.ts +7 -0
- package/dist/math/arc-precision.js +82 -0
- package/dist/math/bounds.d.ts +3 -3
- package/dist/math/bounds.js +13 -2
- package/dist/math/collision.d.ts +7 -0
- package/dist/math/collision.js +41 -0
- package/dist/math/coordinate.d.ts +32 -0
- package/dist/math/coordinate.js +61 -0
- package/dist/math/extent.d.ts +30 -0
- package/dist/math/extent.js +63 -54
- package/dist/math/intersection.d.ts +9 -4
- package/dist/math/intersection.js +9 -5
- package/dist/math/plane.d.ts +1 -0
- package/dist/math/plane.js +3 -1
- package/dist/math/precision.d.ts +26 -0
- package/dist/math/precision.js +114 -0
- package/dist/math/proximity.d.ts +12 -0
- package/dist/math/proximity.js +138 -0
- package/dist/math/rational.d.ts +4 -0
- package/dist/math/rational.js +10 -1
- package/dist/math/resolution.d.ts +9 -0
- package/dist/math/resolution.js +110 -0
- package/dist/math/scene.d.ts +10 -0
- package/dist/math/scene.js +115 -0
- package/dist/math/space.d.ts +1 -0
- package/dist/math/space.js +4 -2
- package/dist/math/visual.d.ts +156 -156
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
/** Checks the rendered chord separating the two finite ends of one arc. */
|
|
3
|
+
export declare function arcEndpointsUnresolved(radius: number, sweepDegrees: number, threshold: BigDecimal.BigDecimal): boolean;
|
|
4
|
+
/** Checks whether one arc's non-zero curvature collapses into its chord. */
|
|
5
|
+
export declare function arcCurvatureUnresolved(radius: number, sweepDegrees: number, threshold: BigDecimal.BigDecimal): boolean;
|
|
6
|
+
/** Checks both authored endpoints against their nearest cardinal axes. */
|
|
7
|
+
export declare function arcEndpointAxesUnresolved(radius: number, startDegrees: number, sweepDegrees: number, threshold: BigDecimal.BigDecimal): boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
3
|
+
import { decimal } from "#contracts/math/rational";
|
|
4
|
+
const PI = BigDecimal.fromStringUnsafe("3.1415926535897932384626433832795028841971693993751");
|
|
5
|
+
const TWO = BigDecimal.fromBigInt(2n);
|
|
6
|
+
const NINETY = BigDecimal.fromBigInt(90n);
|
|
7
|
+
const ONE_EIGHTY = BigDecimal.fromBigInt(180n);
|
|
8
|
+
const THREE_SIXTY = BigDecimal.fromBigInt(360n);
|
|
9
|
+
const SEVEN_TWENTY = BigDecimal.fromBigInt(720n);
|
|
10
|
+
const TRIGONOMETRIC_ERROR = decimal(GEOMETRY_TOLERANCE);
|
|
11
|
+
const MINIMUM_ERROR = decimal(Number.MIN_VALUE);
|
|
12
|
+
/** Bounds a sine estimate for an angle that may fall below Number.MIN_VALUE. */
|
|
13
|
+
function stableSine(exactRadians, numericRadians) {
|
|
14
|
+
const value = BigDecimal.isZero(exactRadians) || numericRadians === 0
|
|
15
|
+
? exactRadians
|
|
16
|
+
: decimal(Math.sin(numericRadians));
|
|
17
|
+
const scale = BigDecimal.max(BigDecimal.abs(exactRadians), BigDecimal.abs(value));
|
|
18
|
+
return {
|
|
19
|
+
error: BigDecimal.max(MINIMUM_ERROR, BigDecimal.multiply(scale, TRIGONOMETRIC_ERROR)),
|
|
20
|
+
value,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Multiplies one bounded decimal by an exact scale. */
|
|
24
|
+
function scaleBounded(bounded, scale) {
|
|
25
|
+
const magnitude = BigDecimal.abs(scale);
|
|
26
|
+
return {
|
|
27
|
+
error: BigDecimal.multiply(bounded.error, magnitude),
|
|
28
|
+
value: BigDecimal.multiply(bounded.value, scale),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Squares one bounded decimal with explicit propagated error. */
|
|
32
|
+
function squareBounded(bounded) {
|
|
33
|
+
return {
|
|
34
|
+
error: BigDecimal.sum(BigDecimal.multiply(BigDecimal.multiply(TWO, BigDecimal.abs(bounded.value)), bounded.error), BigDecimal.multiply(bounded.error, bounded.error)),
|
|
35
|
+
value: BigDecimal.multiply(bounded.value, bounded.value),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Proves that one non-zero bounded measure lies below the threshold. */
|
|
39
|
+
function boundedMeasureUnresolved(bounded, threshold) {
|
|
40
|
+
const magnitude = BigDecimal.abs(bounded.value);
|
|
41
|
+
return (!BigDecimal.isZero(magnitude) &&
|
|
42
|
+
BigDecimal.isLessThan(BigDecimal.sum(magnitude, bounded.error), threshold));
|
|
43
|
+
}
|
|
44
|
+
/** Measures one endpoint's shortest authored offset from a cardinal axis. */
|
|
45
|
+
function endpointAxisMeasure(radius, exactDegrees, numericDegrees) {
|
|
46
|
+
const nearestCardinal = Math.round(numericDegrees / 90);
|
|
47
|
+
const exactDelta = BigDecimal.subtract(exactDegrees, BigDecimal.multiply(decimal(nearestCardinal), NINETY));
|
|
48
|
+
const exactRadians = BigDecimal.divideUnsafe(BigDecimal.multiply(exactDelta, PI), ONE_EIGHTY);
|
|
49
|
+
const numericDelta = numericDegrees - nearestCardinal * 90;
|
|
50
|
+
return scaleBounded(stableSine(exactRadians, numericDelta * (Math.PI / 180)), decimal(Math.abs(radius)));
|
|
51
|
+
}
|
|
52
|
+
/** Resolves the endpoint chord and curvature sagitta of one finite arc. */
|
|
53
|
+
function arcMeasures(radius, sweepDegrees) {
|
|
54
|
+
const directedSweep = Math.abs(sweepDegrees);
|
|
55
|
+
const minorSweep = Math.min(directedSweep, 360 - directedSweep);
|
|
56
|
+
const halfRadians = BigDecimal.divideUnsafe(BigDecimal.multiply(decimal(minorSweep), PI), THREE_SIXTY);
|
|
57
|
+
const halfSine = stableSine(halfRadians, minorSweep * (Math.PI / 360));
|
|
58
|
+
const directedQuarterRadians = BigDecimal.divideUnsafe(BigDecimal.multiply(decimal(directedSweep), PI), SEVEN_TWENTY);
|
|
59
|
+
const quarterSine = stableSine(directedQuarterRadians, directedSweep * (Math.PI / 720));
|
|
60
|
+
const doubledRadius = BigDecimal.multiply(decimal(radius), TWO);
|
|
61
|
+
return {
|
|
62
|
+
chord: scaleBounded(halfSine, doubledRadius),
|
|
63
|
+
sagitta: scaleBounded(squareBounded(quarterSine), doubledRadius),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Checks the rendered chord separating the two finite ends of one arc. */
|
|
67
|
+
export function arcEndpointsUnresolved(radius, sweepDegrees, threshold) {
|
|
68
|
+
return boundedMeasureUnresolved(arcMeasures(Math.abs(radius), sweepDegrees).chord, threshold);
|
|
69
|
+
}
|
|
70
|
+
/** Checks whether one arc's non-zero curvature collapses into its chord. */
|
|
71
|
+
export function arcCurvatureUnresolved(radius, sweepDegrees, threshold) {
|
|
72
|
+
return boundedMeasureUnresolved(arcMeasures(Math.abs(radius), sweepDegrees).sagitta, threshold);
|
|
73
|
+
}
|
|
74
|
+
/** Checks both authored endpoints against their nearest cardinal axes. */
|
|
75
|
+
export function arcEndpointAxesUnresolved(radius, startDegrees, sweepDegrees, threshold) {
|
|
76
|
+
const exactStart = decimal(startDegrees);
|
|
77
|
+
const exactEnd = BigDecimal.sum(exactStart, decimal(sweepDegrees));
|
|
78
|
+
return [
|
|
79
|
+
endpointAxisMeasure(radius, exactStart, startDegrees),
|
|
80
|
+
endpointAxisMeasure(radius, exactEnd, startDegrees + sweepDegrees),
|
|
81
|
+
].some((measure) => boundedMeasureUnresolved(measure, threshold));
|
|
82
|
+
}
|
package/dist/math/bounds.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Schema } from "effect";
|
|
2
2
|
import type { PlaneLabelAnchor, PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
|
|
3
|
-
import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject } from "#contracts/math/space";
|
|
3
|
+
import type { SpaceLabelAnchor, SpaceMathFrame, SpaceMathObject, SpaceMathView } from "#contracts/math/space";
|
|
4
4
|
/** Reports every finite plane object or label that escapes its authored frame. */
|
|
5
5
|
export declare function planeBoundsIssues(frame: PlaneMathFrame, objects: readonly PlaneMathObject[], labels: readonly PlaneLabelAnchor[]): readonly Schema.FilterIssue[];
|
|
6
|
-
/** Reports every finite space object or
|
|
7
|
-
export declare function spaceBoundsIssues(frame: SpaceMathFrame, objects: readonly SpaceMathObject[], labels: readonly SpaceLabelAnchor[]): readonly Schema.FilterIssue[];
|
|
6
|
+
/** Reports every finite space object, label, or view target outside its frame. */
|
|
7
|
+
export declare function spaceBoundsIssues(frame: SpaceMathFrame, objects: readonly SpaceMathObject[], labels: readonly SpaceLabelAnchor[], view: SpaceMathView): readonly Schema.FilterIssue[];
|
package/dist/math/bounds.js
CHANGED
|
@@ -97,8 +97,18 @@ export function planeBoundsIssues(frame, objects, labels) {
|
|
|
97
97
|
]),
|
|
98
98
|
];
|
|
99
99
|
}
|
|
100
|
-
/** Reports every finite space object or
|
|
101
|
-
export function spaceBoundsIssues(frame, objects, labels) {
|
|
100
|
+
/** Reports every finite space object, label, or view target outside its frame. */
|
|
101
|
+
export function spaceBoundsIssues(frame, objects, labels, view) {
|
|
102
|
+
const viewIssues = view.kind === "isometric" &&
|
|
103
|
+
view.target !== undefined &&
|
|
104
|
+
!spaceContains(frame, view.target)
|
|
105
|
+
? [
|
|
106
|
+
{
|
|
107
|
+
issue: "Expected an isometric target inside the Cartesian frame.",
|
|
108
|
+
path: ["view", "target"],
|
|
109
|
+
},
|
|
110
|
+
]
|
|
111
|
+
: [];
|
|
102
112
|
return [
|
|
103
113
|
...objects.flatMap((object, index) => spaceObjectContained(frame, object)
|
|
104
114
|
? []
|
|
@@ -116,5 +126,6 @@ export function spaceBoundsIssues(frame, objects, labels) {
|
|
|
116
126
|
path: ["labels", index, "at"],
|
|
117
127
|
},
|
|
118
128
|
]),
|
|
129
|
+
...viewIssues,
|
|
119
130
|
];
|
|
120
131
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BigDecimal } from "effect";
|
|
2
|
+
import type { SceneCoordinate, ScenePath } from "#contracts/math/coordinate";
|
|
3
|
+
import type { PlaneMathObject } from "#contracts/math/plane";
|
|
4
|
+
/** Finds reportable scene coordinates that collapse on the same axis. */
|
|
5
|
+
export declare function coordinateCollisionPaths(coordinates: readonly SceneCoordinate[], threshold: BigDecimal.BigDecimal): ScenePath[];
|
|
6
|
+
/** Finds non-zero radius deltas between concentric circles or arcs. */
|
|
7
|
+
export declare function concentricRadiusCollisionPaths(objects: readonly PlaneMathObject[], threshold: BigDecimal.BigDecimal): ScenePath[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { unresolvedProximityIndexes } from "#contracts/math/proximity";
|
|
2
|
+
import { numberRatio } from "#contracts/math/rational";
|
|
3
|
+
import { radialGeometryPath } from "#contracts/math/scene";
|
|
4
|
+
/** Keeps one authored issue path for each exact path value. */
|
|
5
|
+
function uniquePaths(paths) {
|
|
6
|
+
return [
|
|
7
|
+
...new Map(paths.map((path) => [JSON.stringify(path), path])).values(),
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
/** Finds reportable scene coordinates that collapse on the same axis. */
|
|
11
|
+
export function coordinateCollisionPaths(coordinates, threshold) {
|
|
12
|
+
const axes = ["x", "y", "z"];
|
|
13
|
+
return uniquePaths(axes.flatMap((axis) => {
|
|
14
|
+
const entries = coordinates.filter((entry) => entry.axis === axis);
|
|
15
|
+
const unresolved = unresolvedProximityIndexes(entries, threshold);
|
|
16
|
+
return entries.flatMap((entry, index) => entry.reportable && unresolved.has(index) ? [entry.path] : []);
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
/** Finds non-zero radius deltas between concentric circles or arcs. */
|
|
20
|
+
export function concentricRadiusCollisionPaths(objects, threshold) {
|
|
21
|
+
const groups = new Map();
|
|
22
|
+
for (const [index, object] of objects.entries()) {
|
|
23
|
+
if (object.kind !== "arc" && object.kind !== "circle") {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const key = `${object.center.x}:${object.center.y}`;
|
|
27
|
+
const group = groups.get(key) ?? [];
|
|
28
|
+
group.push({ index, kind: object.kind, value: numberRatio(object.radius) });
|
|
29
|
+
groups.set(key, group);
|
|
30
|
+
}
|
|
31
|
+
const paths = [];
|
|
32
|
+
for (const group of groups.values()) {
|
|
33
|
+
const unresolved = unresolvedProximityIndexes(group, threshold);
|
|
34
|
+
for (const [entryIndex, entry] of group.entries()) {
|
|
35
|
+
if (unresolved.has(entryIndex)) {
|
|
36
|
+
paths.push(radialGeometryPath(entry.kind, entry.index));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return paths;
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BigDecimal } from "effect";
|
|
2
|
+
import type { PlanePoint, SpacePoint } from "#contracts/math/base";
|
|
3
|
+
import { type AxisTraversal } from "#contracts/math/intersection";
|
|
4
|
+
import type { PlaneMathFrame } from "#contracts/math/plane";
|
|
5
|
+
import { type RenderThreshold } from "#contracts/math/precision";
|
|
6
|
+
import { type ExactRatio } from "#contracts/math/rational";
|
|
7
|
+
import type { SpaceMathFrame } from "#contracts/math/space";
|
|
8
|
+
export type SceneAxis = "x" | "y" | "z";
|
|
9
|
+
export type ScenePath = Array<number | string>;
|
|
10
|
+
/** One ordered exact coordinate projected from a complete visual scene. */
|
|
11
|
+
export interface SceneCoordinate {
|
|
12
|
+
readonly axis: SceneAxis;
|
|
13
|
+
readonly error?: BigDecimal.BigDecimal;
|
|
14
|
+
readonly path: ScenePath;
|
|
15
|
+
readonly reportable: boolean;
|
|
16
|
+
readonly value: ExactRatio;
|
|
17
|
+
}
|
|
18
|
+
export type SceneFrame = PlaneMathFrame | SpaceMathFrame;
|
|
19
|
+
interface SceneAxisTraversal extends AxisTraversal {
|
|
20
|
+
readonly axis: SceneAxis;
|
|
21
|
+
}
|
|
22
|
+
/** Creates one reportable exact scene coordinate. */
|
|
23
|
+
export declare function sceneCoordinate(axis: SceneAxis, path: ScenePath, value: ExactRatio, reportable?: boolean, error?: BigDecimal.BigDecimal): SceneCoordinate;
|
|
24
|
+
/** Projects every axis of one finite point in authored order. */
|
|
25
|
+
export declare function pointCoordinates(point: PlanePoint | SpacePoint, path: ScenePath): SceneCoordinate[];
|
|
26
|
+
/** Seeds every frame edge before reportable scene coordinates. */
|
|
27
|
+
export declare function frameCoordinates(frame: SceneFrame): SceneCoordinate[];
|
|
28
|
+
/** Maps one directed path onto every axis of its authored frame. */
|
|
29
|
+
export declare function pathAxes(frame: SceneFrame, from: PlanePoint | SpacePoint, through: PlanePoint | SpacePoint): SceneAxisTraversal[];
|
|
30
|
+
/** Projects the canonical exact endpoints of one frame-clipped line or ray. */
|
|
31
|
+
export declare function clippedPathCoordinates(frame: SceneFrame, kind: "line" | "ray", from: PlanePoint | SpacePoint, through: PlanePoint | SpacePoint, path: ScenePath, threshold: RenderThreshold): SceneCoordinate[];
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { infinitePathInterval, } from "#contracts/math/intersection";
|
|
2
|
+
import { visiblePathResolvable, } from "#contracts/math/precision";
|
|
3
|
+
import { affineRatio, numberRatio, } from "#contracts/math/rational";
|
|
4
|
+
/** Creates one reportable exact scene coordinate. */
|
|
5
|
+
export function sceneCoordinate(axis, path, value, reportable = true, error) {
|
|
6
|
+
return error === undefined
|
|
7
|
+
? { axis, path, reportable, value }
|
|
8
|
+
: { axis, error, path, reportable, value };
|
|
9
|
+
}
|
|
10
|
+
/** Projects every axis of one finite point in authored order. */
|
|
11
|
+
export function pointCoordinates(point, path) {
|
|
12
|
+
return [
|
|
13
|
+
sceneCoordinate("x", [...path, "x"], numberRatio(point.x)),
|
|
14
|
+
sceneCoordinate("y", [...path, "y"], numberRatio(point.y)),
|
|
15
|
+
...("z" in point
|
|
16
|
+
? [sceneCoordinate("z", [...path, "z"], numberRatio(point.z))]
|
|
17
|
+
: []),
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
/** Seeds every frame edge before reportable scene coordinates. */
|
|
21
|
+
export function frameCoordinates(frame) {
|
|
22
|
+
const axes = [
|
|
23
|
+
["x", frame.x],
|
|
24
|
+
["y", frame.y],
|
|
25
|
+
...("z" in frame ? [["z", frame.z]] : []),
|
|
26
|
+
];
|
|
27
|
+
return axes.flatMap(([axis, range]) => [
|
|
28
|
+
sceneCoordinate(axis, ["frame", axis], numberRatio(range.min), false),
|
|
29
|
+
sceneCoordinate(axis, ["frame", axis], numberRatio(range.max), false),
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
/** Maps one directed path onto every axis of its authored frame. */
|
|
33
|
+
export function pathAxes(frame, from, through) {
|
|
34
|
+
const axes = [
|
|
35
|
+
{ axis: "x", range: frame.x, start: from.x, through: through.x },
|
|
36
|
+
{ axis: "y", range: frame.y, start: from.y, through: through.y },
|
|
37
|
+
];
|
|
38
|
+
return "z" in frame && "z" in from && "z" in through
|
|
39
|
+
? [
|
|
40
|
+
...axes,
|
|
41
|
+
{
|
|
42
|
+
axis: "z",
|
|
43
|
+
range: frame.z,
|
|
44
|
+
start: from.z,
|
|
45
|
+
through: through.z,
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
: axes;
|
|
49
|
+
}
|
|
50
|
+
/** Projects the canonical exact endpoints of one frame-clipped line or ray. */
|
|
51
|
+
export function clippedPathCoordinates(frame, kind, from, through, path, threshold) {
|
|
52
|
+
const axes = pathAxes(frame, from, through);
|
|
53
|
+
const interval = infinitePathInterval(kind, axes);
|
|
54
|
+
if (!(interval?.entry && interval.exit)) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
if (!visiblePathResolvable(kind, axes, threshold)) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
return [interval.entry, interval.exit].flatMap((parameter) => axes.map((axis) => sceneCoordinate(axis.axis, path, affineRatio(axis.start, axis.through, parameter))));
|
|
61
|
+
}
|
package/dist/math/extent.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
1
2
|
import type { PlaneMathFrame, PlaneMathObject } from "#contracts/math/plane";
|
|
3
|
+
import { type ExactRatio } from "#contracts/math/rational";
|
|
2
4
|
import type { SpaceMathFrame, SpaceMathObject } from "#contracts/math/space";
|
|
3
5
|
export type AxisRange = PlaneMathFrame["x"];
|
|
4
6
|
/** Checks one finite coordinate against its inclusive authored range. */
|
|
5
7
|
export declare function axisContains(range: AxisRange, coordinate: number): boolean;
|
|
8
|
+
export interface RadialOffset {
|
|
9
|
+
readonly error: BigDecimal.BigDecimal;
|
|
10
|
+
readonly x: BigDecimal.BigDecimal;
|
|
11
|
+
readonly y: BigDecimal.BigDecimal;
|
|
12
|
+
}
|
|
13
|
+
/** Returns every endpoint or cardinal offset that bounds one radial object. */
|
|
14
|
+
export declare function radialOffsets(object: Extract<PlaneMathObject, {
|
|
15
|
+
readonly kind: "arc" | "circle";
|
|
16
|
+
}>): readonly RadialOffset[];
|
|
6
17
|
/** Checks the exact endpoints and cardinal extrema of one directed arc. */
|
|
7
18
|
export declare function arcContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
|
|
8
19
|
readonly kind: "arc";
|
|
@@ -11,10 +22,29 @@ export declare function arcContained(frame: PlaneMathFrame, object: Extract<Plan
|
|
|
11
22
|
export declare function circleContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
|
|
12
23
|
readonly kind: "circle";
|
|
13
24
|
}>): boolean;
|
|
25
|
+
/** One exact input and output pair at a quadratic domain extremum. */
|
|
26
|
+
export interface QuadraticExtremum {
|
|
27
|
+
readonly input: ExactRatio;
|
|
28
|
+
readonly output: ExactRatio;
|
|
29
|
+
}
|
|
30
|
+
/** Returns both domain endpoints and the in-domain vertex of one quadratic. */
|
|
31
|
+
export declare function quadraticExtrema(object: Extract<PlaneMathObject, {
|
|
32
|
+
readonly kind: "quadratic";
|
|
33
|
+
}>): readonly QuadraticExtremum[];
|
|
14
34
|
/** Checks the complete quadratic domain and exact endpoint or vertex range. */
|
|
15
35
|
export declare function quadraticContained(frame: PlaneMathFrame, object: Extract<PlaneMathObject, {
|
|
16
36
|
readonly kind: "quadratic";
|
|
17
37
|
}>): boolean;
|
|
38
|
+
export interface CuboidExtent {
|
|
39
|
+
readonly axis: "x" | "y" | "z";
|
|
40
|
+
readonly center: number;
|
|
41
|
+
readonly dimension: "height" | "length" | "width";
|
|
42
|
+
readonly extent: BigDecimal.BigDecimal;
|
|
43
|
+
}
|
|
44
|
+
/** Returns the exact positive half-extent on every cuboid axis. */
|
|
45
|
+
export declare function cuboidExtents(object: Extract<SpaceMathObject, {
|
|
46
|
+
readonly kind: "cuboid";
|
|
47
|
+
}>): readonly CuboidExtent[];
|
|
18
48
|
/** Checks one cuboid through exact half-extent-to-boundary comparisons. */
|
|
19
49
|
export declare function cuboidContained(frame: SpaceMathFrame, object: Extract<SpaceMathObject, {
|
|
20
50
|
readonly kind: "cuboid";
|
package/dist/math/extent.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import { BigDecimal } from "effect";
|
|
2
2
|
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
3
|
-
import { decimal, makeRatio, ratioInRange } from "#contracts/math/rational";
|
|
3
|
+
import { decimal, decimalRatio, makeRatio, numberRatio, ratioInRange, } from "#contracts/math/rational";
|
|
4
|
+
const ZERO = BigDecimal.fromBigInt(0n);
|
|
4
5
|
/** Checks one finite coordinate against its inclusive authored range. */
|
|
5
6
|
export function axisContains(range, coordinate) {
|
|
6
7
|
return coordinate >= range.min && coordinate <= range.max;
|
|
7
8
|
}
|
|
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
9
|
/** Checks one translated coordinate within its explicit numeric error envelope. */
|
|
25
10
|
function axisContainsTranslated(range, origin, offset, error) {
|
|
26
11
|
const coordinate = BigDecimal.sum(decimal(origin), offset);
|
|
@@ -29,7 +14,11 @@ function axisContainsTranslated(range, origin, offset, error) {
|
|
|
29
14
|
}
|
|
30
15
|
/** Normalizes one angle to the canonical half-open degree interval. */
|
|
31
16
|
function normalizeDegrees(value) {
|
|
32
|
-
|
|
17
|
+
if (value >= 0 && value < 360) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
const remainder = value % 360;
|
|
21
|
+
return remainder < 0 ? remainder + 360 : remainder;
|
|
33
22
|
}
|
|
34
23
|
/** Returns whether one cardinal angle lies on the authored directed arc. */
|
|
35
24
|
function arcContainsAngle(start, sweep, angle) {
|
|
@@ -62,8 +51,11 @@ function arcOffset(radius, angle) {
|
|
|
62
51
|
y: decimal(radius * Math.sin(radians)),
|
|
63
52
|
};
|
|
64
53
|
}
|
|
65
|
-
/**
|
|
66
|
-
export function
|
|
54
|
+
/** Returns every endpoint or cardinal offset that bounds one radial object. */
|
|
55
|
+
export function radialOffsets(object) {
|
|
56
|
+
if (object.kind === "circle") {
|
|
57
|
+
return [0, 90, 180, 270].map((angle) => arcOffset(object.radius, angle));
|
|
58
|
+
}
|
|
67
59
|
const angles = [
|
|
68
60
|
object.startDegrees,
|
|
69
61
|
object.startDegrees + object.sweepDegrees,
|
|
@@ -73,20 +65,17 @@ export function arcContained(frame, object) {
|
|
|
73
65
|
angles.push(angle);
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
|
-
return angles.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
return angles.map((angle) => arcOffset(object.radius, angle));
|
|
69
|
+
}
|
|
70
|
+
/** Checks the exact endpoints and cardinal extrema of one directed arc. */
|
|
71
|
+
export function arcContained(frame, object) {
|
|
72
|
+
return radialOffsets(object).every((offset) => axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
|
|
73
|
+
axisContainsTranslated(frame.y, object.center.y, offset.y, offset.error));
|
|
81
74
|
}
|
|
82
75
|
/** Checks one circle through exact radius-to-boundary comparisons. */
|
|
83
76
|
export function circleContained(frame, object) {
|
|
84
|
-
|
|
85
|
-
|
|
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));
|
|
77
|
+
return radialOffsets(object).every((offset) => axisContainsTranslated(frame.x, object.center.x, offset.x, offset.error) &&
|
|
78
|
+
axisContainsTranslated(frame.y, object.center.y, offset.y, offset.error));
|
|
90
79
|
}
|
|
91
80
|
/** Evaluates one quadratic exactly at a finite authored input. */
|
|
92
81
|
function quadraticValue(object, input) {
|
|
@@ -98,6 +87,22 @@ function quadraticValue(object, input) {
|
|
|
98
87
|
decimal(c),
|
|
99
88
|
]);
|
|
100
89
|
}
|
|
90
|
+
/** Returns both domain endpoints and the in-domain vertex of one quadratic. */
|
|
91
|
+
export function quadraticExtrema(object) {
|
|
92
|
+
const endpoints = [object.domain.min, object.domain.max].map((input) => ({
|
|
93
|
+
input: numberRatio(input),
|
|
94
|
+
output: decimalRatio(quadraticValue(object, input)),
|
|
95
|
+
}));
|
|
96
|
+
const a = decimal(object.coefficients.a);
|
|
97
|
+
const b = decimal(object.coefficients.b);
|
|
98
|
+
const fourA = BigDecimal.multiply(decimal(4), a);
|
|
99
|
+
const vertexInput = makeRatio(BigDecimal.negate(b), BigDecimal.multiply(decimal(2), a));
|
|
100
|
+
if (!ratioInRange(vertexInput, object.domain.min, object.domain.max)) {
|
|
101
|
+
return endpoints;
|
|
102
|
+
}
|
|
103
|
+
const vertexOutput = makeRatio(BigDecimal.subtract(BigDecimal.multiply(fourA, decimal(object.coefficients.c)), BigDecimal.multiply(b, b)), fourA);
|
|
104
|
+
return [...endpoints, { input: vertexInput, output: vertexOutput }];
|
|
105
|
+
}
|
|
101
106
|
/** Checks the complete quadratic domain and exact endpoint or vertex range. */
|
|
102
107
|
export function quadraticContained(frame, object) {
|
|
103
108
|
const inputRange = object.inputAxis === "x" ? frame.x : frame.y;
|
|
@@ -105,30 +110,34 @@ export function quadraticContained(frame, object) {
|
|
|
105
110
|
if (![object.domain.min, object.domain.max].every((input) => axisContains(inputRange, input))) {
|
|
106
111
|
return false;
|
|
107
112
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
return quadraticExtrema(object).every(({ output }) => ratioInRange(output, outputRange.min, outputRange.max));
|
|
114
|
+
}
|
|
115
|
+
/** Returns the exact positive half-extent on every cuboid axis. */
|
|
116
|
+
export function cuboidExtents(object) {
|
|
117
|
+
const half = decimal(0.5);
|
|
118
|
+
return [
|
|
119
|
+
{
|
|
120
|
+
axis: "x",
|
|
121
|
+
center: object.center.x,
|
|
122
|
+
dimension: "length",
|
|
123
|
+
extent: BigDecimal.multiply(decimal(object.size.length), half),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
axis: "y",
|
|
127
|
+
center: object.center.y,
|
|
128
|
+
dimension: "height",
|
|
129
|
+
extent: BigDecimal.multiply(decimal(object.size.height), half),
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
axis: "z",
|
|
133
|
+
center: object.center.z,
|
|
134
|
+
dimension: "width",
|
|
135
|
+
extent: BigDecimal.multiply(decimal(object.size.width), half),
|
|
136
|
+
},
|
|
137
|
+
];
|
|
121
138
|
}
|
|
122
139
|
/** Checks one cuboid through exact half-extent-to-boundary comparisons. */
|
|
123
140
|
export function cuboidContained(frame, object) {
|
|
124
|
-
|
|
125
|
-
|
|
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)));
|
|
141
|
+
return cuboidExtents(object).every(({ axis, center, extent }) => axisContainsTranslated(frame[axis], center, extent, ZERO) &&
|
|
142
|
+
axisContainsTranslated(frame[axis], center, BigDecimal.negate(extent), ZERO));
|
|
134
143
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { type AxisRange } from "#contracts/math/extent";
|
|
2
|
-
import type
|
|
2
|
+
import { type ExactRatio } from "#contracts/math/rational";
|
|
3
3
|
/** One Cartesian slab traversed by the same parametric path. */
|
|
4
4
|
export interface AxisTraversal {
|
|
5
5
|
readonly range: AxisRange;
|
|
6
6
|
readonly start: number;
|
|
7
7
|
readonly through: number;
|
|
8
8
|
}
|
|
9
|
-
type InfinitePathKind =
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
type InfinitePathKind = "line" | "ray";
|
|
10
|
+
/** Exact finite sides of one clipped infinite path parameter interval. */
|
|
11
|
+
export interface InfinitePathInterval {
|
|
12
|
+
readonly entry: ExactRatio | undefined;
|
|
13
|
+
readonly exit: ExactRatio | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** Clips one infinite line or ray against an inclusive axis-aligned box. */
|
|
16
|
+
export declare function infinitePathInterval(kind: InfinitePathKind, axes: readonly AxisTraversal[]): InfinitePathInterval | undefined;
|
|
12
17
|
/** Checks whether one infinite line or ray intersects an inclusive axis-aligned box. */
|
|
13
18
|
export declare function infinitePathIntersectsBox(kind: InfinitePathKind, axes: readonly AxisTraversal[]): boolean;
|
|
14
19
|
export {};
|
|
@@ -12,14 +12,14 @@ function earlier(current, candidate) {
|
|
|
12
12
|
? candidate
|
|
13
13
|
: current;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
export function
|
|
15
|
+
/** Clips one infinite line or ray against an inclusive axis-aligned box. */
|
|
16
|
+
export function infinitePathInterval(kind, axes) {
|
|
17
17
|
let entry = kind === "ray" ? numberRatio(0) : undefined;
|
|
18
18
|
let exit;
|
|
19
19
|
for (const axis of axes) {
|
|
20
20
|
if (axis.start === axis.through) {
|
|
21
21
|
if (!axisContains(axis.range, axis.start)) {
|
|
22
|
-
return
|
|
22
|
+
return;
|
|
23
23
|
}
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
@@ -30,8 +30,12 @@ export function infinitePathIntersectsBox(kind, axes) {
|
|
|
30
30
|
entry = later(entry, near);
|
|
31
31
|
exit = earlier(exit, far);
|
|
32
32
|
if (exit !== undefined && compareRatios(entry, exit) > 0) {
|
|
33
|
-
return
|
|
33
|
+
return;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return { entry, exit };
|
|
37
|
+
}
|
|
38
|
+
/** Checks whether one infinite line or ray intersects an inclusive axis-aligned box. */
|
|
39
|
+
export function infinitePathIntersectsBox(kind, axes) {
|
|
40
|
+
return infinitePathInterval(kind, axes) !== undefined;
|
|
37
41
|
}
|
package/dist/math/plane.d.ts
CHANGED
|
@@ -130,6 +130,7 @@ export declare const PlaneMathViewSchema: Schema.Struct<{
|
|
|
130
130
|
readonly kind: Schema.Literal<"fit">;
|
|
131
131
|
readonly padding: Schema.optionalKey<Schema.Finite>;
|
|
132
132
|
}>;
|
|
133
|
+
export type PlaneMathView = typeof PlaneMathViewSchema.Type;
|
|
133
134
|
/** One coordinate anchor resolved against a separate rich-label map. */
|
|
134
135
|
export declare const PlaneLabelAnchorSchema: Schema.Struct<{
|
|
135
136
|
readonly at: Schema.Struct<{
|
package/dist/math/plane.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
3
|
import { planeBoundsIssues } from "#contracts/math/bounds";
|
|
4
|
+
import { planeResolutionIssues } from "#contracts/math/resolution";
|
|
4
5
|
const ObjectFields = {
|
|
5
6
|
appearance: MathAppearanceSchema,
|
|
6
7
|
id: MathVisualKeySchema,
|
|
@@ -149,7 +150,8 @@ export const PlaneMathVisualSchema = Schema.Struct({
|
|
|
149
150
|
objects: Schema.NonEmptyArray(PlaneMathObjectSchema),
|
|
150
151
|
space: Schema.Literal("plane"),
|
|
151
152
|
view: PlaneMathViewSchema,
|
|
152
|
-
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects }) => [
|
|
153
|
+
}).pipe(Schema.check(Schema.makeFilter(({ frame, labels = [], objects, view }) => [
|
|
153
154
|
...mathVisualIdentityIssues(objects, labels),
|
|
154
155
|
...planeBoundsIssues(frame, objects, labels),
|
|
156
|
+
...planeResolutionIssues(frame, objects, labels, view),
|
|
155
157
|
])));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BigDecimal } from "effect";
|
|
2
|
+
import type { PlanePoint, SpacePoint } from "#contracts/math/base";
|
|
3
|
+
import type { AxisRange } from "#contracts/math/extent";
|
|
4
|
+
import { type AxisTraversal } from "#contracts/math/intersection";
|
|
5
|
+
export type RenderThreshold = BigDecimal.BigDecimal;
|
|
6
|
+
/** Returns the exact width of one finite authored axis. */
|
|
7
|
+
export declare function axisSpan(range: AxisRange): BigDecimal.BigDecimal;
|
|
8
|
+
/** Checks one exact axis width against the shared render threshold. */
|
|
9
|
+
export declare function spanUnresolved(range: AxisRange, threshold: RenderThreshold): boolean;
|
|
10
|
+
/** Checks one non-zero measurement against the shared render threshold. */
|
|
11
|
+
export declare function measureUnresolved(value: number, threshold: RenderThreshold): boolean;
|
|
12
|
+
/** Resolves 2^-23 of the complete translation-invariant render envelope. */
|
|
13
|
+
export declare function renderThreshold(ranges: readonly [AxisRange, AxisRange, ...AxisRange[]], padding: number, envelopePairs?: readonly (readonly [number, number])[]): BigDecimal.BigDecimal;
|
|
14
|
+
/** Includes both view coordinates, their separation, and one frame axis. */
|
|
15
|
+
export declare function axisEnvelopePairs(range: AxisRange, left: number, right: number): readonly (readonly [number, number])[];
|
|
16
|
+
/** Checks that the frame-visible portion of one infinite path remains visible. */
|
|
17
|
+
export declare function visiblePathResolvable(kind: "line" | "ray", axes: readonly AxisTraversal[], threshold: RenderThreshold): boolean;
|
|
18
|
+
/** Checks whether any non-zero polygon altitude collapses in the renderer. */
|
|
19
|
+
export declare function polygonAltitudeUnresolved(vertices: readonly [
|
|
20
|
+
PlanePoint | SpacePoint,
|
|
21
|
+
PlanePoint | SpacePoint,
|
|
22
|
+
PlanePoint | SpacePoint,
|
|
23
|
+
...(PlanePoint | SpacePoint)[]
|
|
24
|
+
], threshold: RenderThreshold): boolean;
|
|
25
|
+
/** Checks exact quadratic curvature without relying on renderer sampling. */
|
|
26
|
+
export declare function quadraticCurvatureUnresolved(coefficient: number, domainSpan: BigDecimal.BigDecimal, threshold: RenderThreshold): boolean;
|