@ccpc/math 0.1.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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/constants/geom_type.d.ts +13 -0
- package/dist/constants/geom_type.d.ts.map +1 -0
- package/dist/constants/geom_type.js +17 -0
- package/dist/constants/math_const.d.ts +9 -0
- package/dist/constants/math_const.d.ts.map +1 -0
- package/dist/constants/math_const.js +12 -0
- package/dist/core/box2.d.ts +71 -0
- package/dist/core/box2.d.ts.map +1 -0
- package/dist/core/box2.js +243 -0
- package/dist/core/coord2d.d.ts +62 -0
- package/dist/core/coord2d.d.ts.map +1 -0
- package/dist/core/coord2d.js +155 -0
- package/dist/core/geom_base.d.ts +19 -0
- package/dist/core/geom_base.d.ts.map +1 -0
- package/dist/core/geom_base.js +18 -0
- package/dist/core/mat3.d.ts +101 -0
- package/dist/core/mat3.d.ts.map +1 -0
- package/dist/core/mat3.js +290 -0
- package/dist/core/vec2.d.ts +138 -0
- package/dist/core/vec2.d.ts.map +1 -0
- package/dist/core/vec2.js +297 -0
- package/dist/curves/arc2.d.ts +49 -0
- package/dist/curves/arc2.d.ts.map +1 -0
- package/dist/curves/arc2.js +265 -0
- package/dist/curves/bspline2.d.ts +150 -0
- package/dist/curves/bspline2.d.ts.map +1 -0
- package/dist/curves/bspline2.js +793 -0
- package/dist/curves/circle2.d.ts +42 -0
- package/dist/curves/circle2.d.ts.map +1 -0
- package/dist/curves/circle2.js +135 -0
- package/dist/curves/circle_curve2.d.ts +38 -0
- package/dist/curves/circle_curve2.d.ts.map +1 -0
- package/dist/curves/circle_curve2.js +112 -0
- package/dist/curves/curve2.d.ts +214 -0
- package/dist/curves/curve2.d.ts.map +1 -0
- package/dist/curves/curve2.js +238 -0
- package/dist/curves/ellipse2.d.ts +42 -0
- package/dist/curves/ellipse2.d.ts.map +1 -0
- package/dist/curves/ellipse2.js +125 -0
- package/dist/curves/ellipse_arc2.d.ts +49 -0
- package/dist/curves/ellipse_arc2.d.ts.map +1 -0
- package/dist/curves/ellipse_arc2.js +184 -0
- package/dist/curves/ellipse_curve2.d.ts +56 -0
- package/dist/curves/ellipse_curve2.d.ts.map +1 -0
- package/dist/curves/ellipse_curve2.js +262 -0
- package/dist/curves/interval.d.ts +112 -0
- package/dist/curves/interval.d.ts.map +1 -0
- package/dist/curves/interval.js +200 -0
- package/dist/curves/line2.d.ts +64 -0
- package/dist/curves/line2.d.ts.map +1 -0
- package/dist/curves/line2.js +193 -0
- package/dist/curves/period_interval.d.ts +129 -0
- package/dist/curves/period_interval.d.ts.map +1 -0
- package/dist/curves/period_interval.js +240 -0
- package/dist/discretize/discretize_defaults.d.ts +12 -0
- package/dist/discretize/discretize_defaults.d.ts.map +1 -0
- package/dist/discretize/discretize_defaults.js +12 -0
- package/dist/discretize/discretize_engine.d.ts +33 -0
- package/dist/discretize/discretize_engine.d.ts.map +1 -0
- package/dist/discretize/discretize_engine.js +347 -0
- package/dist/discretize/discretize_errors.d.ts +15 -0
- package/dist/discretize/discretize_errors.d.ts.map +1 -0
- package/dist/discretize/discretize_errors.js +30 -0
- package/dist/discretize/discretize_options.d.ts +18 -0
- package/dist/discretize/discretize_options.d.ts.map +1 -0
- package/dist/discretize/discretize_options.js +19 -0
- package/dist/discretize/discretize_types.d.ts +36 -0
- package/dist/discretize/discretize_types.d.ts.map +1 -0
- package/dist/discretize/discretize_types.js +1 -0
- package/dist/discretize/internal/curve_guards.d.ts +35 -0
- package/dist/discretize/internal/curve_guards.d.ts.map +1 -0
- package/dist/discretize/internal/curve_guards.js +62 -0
- package/dist/discretize/internal/postprocess.d.ts +5 -0
- package/dist/discretize/internal/postprocess.d.ts.map +1 -0
- package/dist/discretize/internal/postprocess.js +109 -0
- package/dist/discretize/internal/sampling_utils.d.ts +8 -0
- package/dist/discretize/internal/sampling_utils.d.ts.map +1 -0
- package/dist/discretize/internal/sampling_utils.js +36 -0
- package/dist/discretize/register_builtin_strategies.d.ts +3 -0
- package/dist/discretize/register_builtin_strategies.d.ts.map +1 -0
- package/dist/discretize/register_builtin_strategies.js +10 -0
- package/dist/discretize/strategies/bspline_strategy.d.ts +4 -0
- package/dist/discretize/strategies/bspline_strategy.d.ts.map +1 -0
- package/dist/discretize/strategies/bspline_strategy.js +115 -0
- package/dist/discretize/strategies/circle_strategy.d.ts +7 -0
- package/dist/discretize/strategies/circle_strategy.d.ts.map +1 -0
- package/dist/discretize/strategies/circle_strategy.js +55 -0
- package/dist/discretize/strategies/ellipse_strategy.d.ts +7 -0
- package/dist/discretize/strategies/ellipse_strategy.d.ts.map +1 -0
- package/dist/discretize/strategies/ellipse_strategy.js +86 -0
- package/dist/discretize/strategies/line_strategy.d.ts +4 -0
- package/dist/discretize/strategies/line_strategy.d.ts.map +1 -0
- package/dist/discretize/strategies/line_strategy.js +40 -0
- package/dist/discretize/strategy_registry.d.ts +9 -0
- package/dist/discretize/strategy_registry.d.ts.map +1 -0
- package/dist/discretize/strategy_registry.js +34 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/intersections/analytic_x_algorithm.d.ts +10 -0
- package/dist/intersections/analytic_x_algorithm.d.ts.map +1 -0
- package/dist/intersections/analytic_x_algorithm.js +83 -0
- package/dist/intersections/curve_x_engine.d.ts +9 -0
- package/dist/intersections/curve_x_engine.d.ts.map +1 -0
- package/dist/intersections/curve_x_engine.js +27 -0
- package/dist/intersections/index.d.ts +5 -0
- package/dist/intersections/index.d.ts.map +1 -0
- package/dist/intersections/index.js +11 -0
- package/dist/intersections/internal/certification.d.ts +34 -0
- package/dist/intersections/internal/certification.d.ts.map +1 -0
- package/dist/intersections/internal/certification.js +238 -0
- package/dist/intersections/internal/interval_clipping.d.ts +29 -0
- package/dist/intersections/internal/interval_clipping.d.ts.map +1 -0
- package/dist/intersections/internal/interval_clipping.js +123 -0
- package/dist/intersections/internal/kind.d.ts +4 -0
- package/dist/intersections/internal/kind.d.ts.map +1 -0
- package/dist/intersections/internal/kind.js +16 -0
- package/dist/intersections/internal/pair.d.ts +9 -0
- package/dist/intersections/internal/pair.d.ts.map +1 -0
- package/dist/intersections/internal/pair.js +14 -0
- package/dist/intersections/internal/result.d.ts +20 -0
- package/dist/intersections/internal/result.d.ts.map +1 -0
- package/dist/intersections/internal/result.js +125 -0
- package/dist/intersections/internal/sampling.d.ts +15 -0
- package/dist/intersections/internal/sampling.d.ts.map +1 -0
- package/dist/intersections/internal/sampling.js +131 -0
- package/dist/intersections/internal/segment.d.ts +32 -0
- package/dist/intersections/internal/segment.d.ts.map +1 -0
- package/dist/intersections/internal/segment.js +137 -0
- package/dist/intersections/internal/tolerance.d.ts +10 -0
- package/dist/intersections/internal/tolerance.d.ts.map +1 -0
- package/dist/intersections/internal/tolerance.js +20 -0
- package/dist/intersections/intersector.d.ts +6 -0
- package/dist/intersections/intersector.d.ts.map +1 -0
- package/dist/intersections/intersector.js +1 -0
- package/dist/intersections/numeric_x_algorithm.d.ts +10 -0
- package/dist/intersections/numeric_x_algorithm.d.ts.map +1 -0
- package/dist/intersections/numeric_x_algorithm.js +73 -0
- package/dist/intersections/solvers/bspline_self_solver.d.ts +7 -0
- package/dist/intersections/solvers/bspline_self_solver.d.ts.map +1 -0
- package/dist/intersections/solvers/bspline_self_solver.js +308 -0
- package/dist/intersections/solvers/line_line_pair_solver.d.ts +7 -0
- package/dist/intersections/solvers/line_line_pair_solver.d.ts.map +1 -0
- package/dist/intersections/solvers/line_line_pair_solver.js +35 -0
- package/dist/intersections/solvers/pair_solvers.d.ts +94 -0
- package/dist/intersections/solvers/pair_solvers.d.ts.map +1 -0
- package/dist/intersections/solvers/pair_solvers.js +1078 -0
- package/dist/intersections/solvers/polyline_pair_intersector.d.ts +51 -0
- package/dist/intersections/solvers/polyline_pair_intersector.d.ts.map +1 -0
- package/dist/intersections/solvers/polyline_pair_intersector.js +731 -0
- package/dist/intersections/types.d.ts +11 -0
- package/dist/intersections/types.d.ts.map +1 -0
- package/dist/intersections/types.js +1 -0
- package/dist/serialize/dump_types.d.ts +101 -0
- package/dist/serialize/dump_types.d.ts.map +1 -0
- package/dist/serialize/dump_types.js +5 -0
- package/dist/serialize/geom_mgr.d.ts +24 -0
- package/dist/serialize/geom_mgr.d.ts.map +1 -0
- package/dist/serialize/geom_mgr.js +30 -0
- package/dist/types/type_define.d.ts +29 -0
- package/dist/types/type_define.d.ts.map +1 -0
- package/dist/types/type_define.js +10 -0
- package/dist/types/type_guard.d.ts +46 -0
- package/dist/types/type_guard.d.ts.map +1 -0
- package/dist/types/type_guard.js +5 -0
- package/dist/utils/math_error.d.ts +16 -0
- package/dist/utils/math_error.d.ts.map +1 -0
- package/dist/utils/math_error.js +35 -0
- package/dist/utils/math_utils.d.ts +9 -0
- package/dist/utils/math_utils.d.ts.map +1 -0
- package/dist/utils/math_utils.js +25 -0
- package/dist/utils/precision.d.ts +29 -0
- package/dist/utils/precision.d.ts.map +1 -0
- package/dist/utils/precision.js +44 -0
- package/package.json +38 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Precision } from '../../utils/precision';
|
|
2
|
+
import { assertDiscretize, DISCRETIZE_ERROR_PREFIX } from '../discretize_errors';
|
|
3
|
+
function cloneSample(sample) {
|
|
4
|
+
return { u: sample.u, p: sample.p.clone() };
|
|
5
|
+
}
|
|
6
|
+
function deduplicateAdjacent(samples, tol) {
|
|
7
|
+
if (samples.length <= 1)
|
|
8
|
+
return samples;
|
|
9
|
+
const deduped = [samples[0]];
|
|
10
|
+
for (let i = 1; i < samples.length; i++) {
|
|
11
|
+
const prev = deduped[deduped.length - 1];
|
|
12
|
+
const cur = samples[i];
|
|
13
|
+
if (prev.p.distanceTo(cur.p) <= tol)
|
|
14
|
+
continue;
|
|
15
|
+
deduped.push(cur);
|
|
16
|
+
}
|
|
17
|
+
return deduped;
|
|
18
|
+
}
|
|
19
|
+
function removeTrailingEndpoint(samples, endParam, endPoint, tol) {
|
|
20
|
+
while (samples.length > 1) {
|
|
21
|
+
const last = samples[samples.length - 1];
|
|
22
|
+
if (Math.abs(last.u - endParam) <= Precision.CURVE_PARAM_EPS || last.p.distanceTo(endPoint) <= tol) {
|
|
23
|
+
samples.pop();
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function ensureOpenEndIncluded(samples, endParam, endPoint, tol) {
|
|
30
|
+
const endSample = { u: endParam, p: endPoint.clone() };
|
|
31
|
+
if (samples.length === 0) {
|
|
32
|
+
samples.push(endSample);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const last = samples[samples.length - 1];
|
|
36
|
+
if (Math.abs(last.u - endParam) <= Precision.CURVE_PARAM_EPS || last.p.distanceTo(endPoint) <= tol) {
|
|
37
|
+
samples[samples.length - 1] = endSample;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (endParam > last.u + Precision.CURVE_PARAM_EPS) {
|
|
41
|
+
samples.push(endSample);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
samples[samples.length - 1] = endSample;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function removeClosedDuplicateTail(samples, tol) {
|
|
48
|
+
while (samples.length > 1) {
|
|
49
|
+
const first = samples[0];
|
|
50
|
+
const last = samples[samples.length - 1];
|
|
51
|
+
if (first.p.distanceTo(last.p) <= tol) {
|
|
52
|
+
samples.pop();
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function postprocessDiscretizeResult(curve, raw, options) {
|
|
59
|
+
const range = curve.getRange();
|
|
60
|
+
const startParam = range.start;
|
|
61
|
+
const endParam = range.end;
|
|
62
|
+
const startPoint = curve.pointAt(startParam);
|
|
63
|
+
const endPoint = curve.pointAt(endParam);
|
|
64
|
+
let samples = raw.samples.map(cloneSample);
|
|
65
|
+
if (samples.length === 0) {
|
|
66
|
+
samples = [{ u: startParam, p: startPoint.clone() }];
|
|
67
|
+
}
|
|
68
|
+
samples = deduplicateAdjacent(samples, options.effectivePointMergeTol);
|
|
69
|
+
samples[0] = { u: startParam, p: startPoint.clone() };
|
|
70
|
+
if (raw.closed) {
|
|
71
|
+
removeClosedDuplicateTail(samples, options.effectivePointMergeTol);
|
|
72
|
+
}
|
|
73
|
+
else if (options.includeEnd) {
|
|
74
|
+
ensureOpenEndIncluded(samples, endParam, endPoint, options.effectivePointMergeTol);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
removeTrailingEndpoint(samples, endParam, endPoint, options.effectivePointMergeTol);
|
|
78
|
+
}
|
|
79
|
+
if (samples.length === 0) {
|
|
80
|
+
samples.push({ u: startParam, p: startPoint.clone() });
|
|
81
|
+
}
|
|
82
|
+
const result = { samples, closed: raw.closed };
|
|
83
|
+
assertDiscretizeResult(curve, result, options);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
export function assertDiscretizeResult(curve, result, options) {
|
|
87
|
+
assertDiscretize(result.samples.length > 0, DISCRETIZE_ERROR_PREFIX.convergence, 'empty discretize result');
|
|
88
|
+
for (let i = 1; i < result.samples.length; i++) {
|
|
89
|
+
const prev = result.samples[i - 1];
|
|
90
|
+
const cur = result.samples[i];
|
|
91
|
+
assertDiscretize(cur.u > prev.u, DISCRETIZE_ERROR_PREFIX.convergence, 'sample parameters must be strictly increasing');
|
|
92
|
+
}
|
|
93
|
+
const range = curve.getRange();
|
|
94
|
+
const start = range.start;
|
|
95
|
+
const end = range.end;
|
|
96
|
+
const first = result.samples[0];
|
|
97
|
+
assertDiscretize(Math.abs(first.u - start) <= Precision.CURVE_PARAM_EPS, DISCRETIZE_ERROR_PREFIX.convergence, 'first sample must match range start');
|
|
98
|
+
if (result.closed) {
|
|
99
|
+
if (result.samples.length > 1) {
|
|
100
|
+
const last = result.samples[result.samples.length - 1];
|
|
101
|
+
assertDiscretize(first.p.distanceTo(last.p) > options.effectivePointMergeTol, DISCRETIZE_ERROR_PREFIX.convergence, 'closed result must not duplicate head/tail points');
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!options.includeEnd)
|
|
106
|
+
return;
|
|
107
|
+
const last = result.samples[result.samples.length - 1];
|
|
108
|
+
assertDiscretize(Math.abs(last.u - end) <= Precision.CURVE_PARAM_EPS, DISCRETIZE_ERROR_PREFIX.convergence, 'last sample must match range end');
|
|
109
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Vec2 } from '../../core/vec2';
|
|
2
|
+
import type { Curve2 } from '../../curves/curve2';
|
|
3
|
+
export declare const CHORD_CHECK_FRACTIONS: readonly [0.25, 0.5, 0.75];
|
|
4
|
+
export declare function lerpNumber(a: number, b: number, t: number): number;
|
|
5
|
+
export declare function distancePointToSegment(point: Vec2, segStart: Vec2, segEnd: Vec2): number;
|
|
6
|
+
export declare function tangentTurnAbs(curve: Curve2, u0: number, u1: number): number;
|
|
7
|
+
export declare function maxChordDeviationAtFractions(curve: Curve2, u0: number, u1: number, p0: Vec2, p1: Vec2, fractions?: readonly [0.25, 0.5, 0.75]): number;
|
|
8
|
+
//# sourceMappingURL=sampling_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampling_utils.d.ts","sourceRoot":"","sources":["../../../src/discretize/internal/sampling_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAEjD,eAAO,MAAM,qBAAqB,4BAA6B,CAAA;AAE/D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAEzD;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,UAW/E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAOnE;AAED,wBAAgB,4BAA4B,CACxC,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,IAAI,EACR,EAAE,EAAE,IAAI,EACR,SAAS,6BAAwB,UAYpC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Precision } from '../../utils/precision';
|
|
2
|
+
export const CHORD_CHECK_FRACTIONS = [0.25, 0.5, 0.75];
|
|
3
|
+
export function lerpNumber(a, b, t) {
|
|
4
|
+
return a + (b - a) * t;
|
|
5
|
+
}
|
|
6
|
+
export function distancePointToSegment(point, segStart, segEnd) {
|
|
7
|
+
const edge = segEnd.subtracted(segStart);
|
|
8
|
+
const lenSq = edge.lenSq();
|
|
9
|
+
if (lenSq <= Precision.CURVE_LENGTH_EPS * Precision.CURVE_LENGTH_EPS) {
|
|
10
|
+
return point.distanceTo(segStart);
|
|
11
|
+
}
|
|
12
|
+
const rel = point.subtracted(segStart);
|
|
13
|
+
const t = Math.max(0, Math.min(1, rel.dot(edge) / lenSq));
|
|
14
|
+
const proj = segStart.added(edge.scaled(t));
|
|
15
|
+
return point.distanceTo(proj);
|
|
16
|
+
}
|
|
17
|
+
export function tangentTurnAbs(curve, u0, u1) {
|
|
18
|
+
const t0 = curve.tangentAt(u0);
|
|
19
|
+
const t1 = curve.tangentAt(u1);
|
|
20
|
+
if (t0.lenSq() <= Precision.CURVE_NEWTON_EPS || t1.lenSq() <= Precision.CURVE_NEWTON_EPS) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return Math.abs(t0.angleTo(t1));
|
|
24
|
+
}
|
|
25
|
+
export function maxChordDeviationAtFractions(curve, u0, u1, p0, p1, fractions = CHORD_CHECK_FRACTIONS) {
|
|
26
|
+
let maxDeviation = 0;
|
|
27
|
+
for (const fraction of fractions) {
|
|
28
|
+
const um = lerpNumber(u0, u1, fraction);
|
|
29
|
+
const pm = curve.pointAt(um);
|
|
30
|
+
const deviation = distancePointToSegment(pm, p0, p1);
|
|
31
|
+
if (deviation > maxDeviation) {
|
|
32
|
+
maxDeviation = deviation;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return maxDeviation;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register_builtin_strategies.d.ts","sourceRoot":"","sources":["../../src/discretize/register_builtin_strategies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAA;AAMhE,wBAAgB,mCAAmC,CAAC,QAAQ,EAAE,0BAA0B,QAKvF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { bsplineDiscretizeStrategy } from './strategies/bspline_strategy';
|
|
2
|
+
import { circleDiscretizeStrategy } from './strategies/circle_strategy';
|
|
3
|
+
import { ellipseDiscretizeStrategy } from './strategies/ellipse_strategy';
|
|
4
|
+
import { lineDiscretizeStrategy } from './strategies/line_strategy';
|
|
5
|
+
export function registerBuiltinDiscretizeStrategies(registry) {
|
|
6
|
+
registry.register(lineDiscretizeStrategy);
|
|
7
|
+
registry.register(circleDiscretizeStrategy);
|
|
8
|
+
registry.register(ellipseDiscretizeStrategy);
|
|
9
|
+
registry.register(bsplineDiscretizeStrategy);
|
|
10
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BSpline2 } from '../../curves/bspline2';
|
|
2
|
+
import type { DiscretizeResult, ResolvedDiscretizeOptions } from '../discretize_types';
|
|
3
|
+
export declare function discretizeBSplineCurve(curve: BSpline2, options: ResolvedDiscretizeOptions): DiscretizeResult;
|
|
4
|
+
//# sourceMappingURL=bspline_strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bspline_strategy.d.ts","sourceRoot":"","sources":["../../../src/discretize/strategies/bspline_strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGhD,OAAO,KAAK,EAAE,gBAAgB,EAAkB,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAqHtG,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,yBAAyB,GACnC,gBAAgB,CA2BlB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Precision } from '../../utils/precision';
|
|
2
|
+
import { throwDiscretizeConvergenceError, throwDiscretizeOverflowError } from '../discretize_errors';
|
|
3
|
+
import { maxChordDeviationAtFractions, tangentTurnAbs } from '../internal/sampling_utils';
|
|
4
|
+
function getContinuityBreaks(curve) {
|
|
5
|
+
const knots = curve.expandedKnots;
|
|
6
|
+
const degree = curve.degree;
|
|
7
|
+
const range = curve.getRange();
|
|
8
|
+
const breaks = [];
|
|
9
|
+
for (let i = 0; i < knots.length;) {
|
|
10
|
+
const knot = knots[i];
|
|
11
|
+
let multiplicity = 1;
|
|
12
|
+
i++;
|
|
13
|
+
while (i < knots.length && Math.abs(knots[i] - knot) <= Precision.CURVE_PARAM_EPS) {
|
|
14
|
+
multiplicity++;
|
|
15
|
+
i++;
|
|
16
|
+
}
|
|
17
|
+
if (multiplicity >= degree && knot > range.start + Precision.CURVE_PARAM_EPS && knot < range.end - Precision.CURVE_PARAM_EPS) {
|
|
18
|
+
breaks.push(knot);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return breaks;
|
|
22
|
+
}
|
|
23
|
+
function buildInitialSegments(curve, options) {
|
|
24
|
+
const range = curve.getRange();
|
|
25
|
+
const span = range.length();
|
|
26
|
+
const boundaries = new Set([range.start, range.end, ...getContinuityBreaks(curve)]);
|
|
27
|
+
for (let i = 1; i < options.minSegments; i++) {
|
|
28
|
+
boundaries.add(range.start + (span * i) / options.minSegments);
|
|
29
|
+
}
|
|
30
|
+
const sorted = [...boundaries].sort((a, b) => a - b);
|
|
31
|
+
const segments = [];
|
|
32
|
+
for (let i = 0; i < sorted.length - 1; i++) {
|
|
33
|
+
const u0 = sorted[i];
|
|
34
|
+
const u1 = sorted[i + 1];
|
|
35
|
+
if (u1 - u0 <= Precision.CURVE_PARAM_EPS)
|
|
36
|
+
continue;
|
|
37
|
+
segments.push({
|
|
38
|
+
u0,
|
|
39
|
+
u1,
|
|
40
|
+
p0: curve.pointAt(u0),
|
|
41
|
+
p1: curve.pointAt(u1),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return segments;
|
|
45
|
+
}
|
|
46
|
+
function shouldSplitSegment(curve, segment, options) {
|
|
47
|
+
const chordLength = segment.p0.distanceTo(segment.p1);
|
|
48
|
+
const deviation = maxChordDeviationAtFractions(curve, segment.u0, segment.u1, segment.p0, segment.p1);
|
|
49
|
+
const turn = tangentTurnAbs(curve, segment.u0, segment.u1);
|
|
50
|
+
const violateMaxLength = chordLength > options.maxSegmentLength;
|
|
51
|
+
const violateChord = deviation > options.effectiveChordTol;
|
|
52
|
+
const violateTurn = turn > options.angleTolRad;
|
|
53
|
+
if (!violateMaxLength && !violateChord && !violateTurn)
|
|
54
|
+
return 'ok';
|
|
55
|
+
if (chordLength <= options.minSegmentLengthInternal) {
|
|
56
|
+
return 'blocked';
|
|
57
|
+
}
|
|
58
|
+
return 'split';
|
|
59
|
+
}
|
|
60
|
+
function refineSegments(curve, initialSegments, options) {
|
|
61
|
+
const segments = [...initialSegments];
|
|
62
|
+
for (let i = 0; i < segments.length; i++) {
|
|
63
|
+
const segment = segments[i];
|
|
64
|
+
const verdict = shouldSplitSegment(curve, segment, options);
|
|
65
|
+
if (verdict === 'ok')
|
|
66
|
+
continue;
|
|
67
|
+
if (verdict === 'blocked') {
|
|
68
|
+
throwDiscretizeOverflowError('bspline strategy cannot satisfy constraints within internal segment limit');
|
|
69
|
+
}
|
|
70
|
+
if (segments.length >= options.maxSegments) {
|
|
71
|
+
throwDiscretizeOverflowError('bspline strategy exceeds maxSegments constraints');
|
|
72
|
+
}
|
|
73
|
+
const mid = (segment.u0 + segment.u1) * 0.5;
|
|
74
|
+
if (Math.abs(mid - segment.u0) <= Precision.CURVE_PARAM_EPS || Math.abs(segment.u1 - mid) <= Precision.CURVE_PARAM_EPS) {
|
|
75
|
+
throwDiscretizeConvergenceError('bspline strategy failed to converge');
|
|
76
|
+
}
|
|
77
|
+
const pm = curve.pointAt(mid);
|
|
78
|
+
segments.splice(i, 1, { u0: segment.u0, u1: mid, p0: segment.p0, p1: pm }, { u0: mid, u1: segment.u1, p0: pm, p1: segment.p1 });
|
|
79
|
+
i--;
|
|
80
|
+
}
|
|
81
|
+
return segments;
|
|
82
|
+
}
|
|
83
|
+
function toSamples(segments) {
|
|
84
|
+
const samples = [{ u: segments[0].u0, p: segments[0].p0.clone() }];
|
|
85
|
+
for (const segment of segments) {
|
|
86
|
+
samples.push({ u: segment.u1, p: segment.p1.clone() });
|
|
87
|
+
}
|
|
88
|
+
return samples;
|
|
89
|
+
}
|
|
90
|
+
export function discretizeBSplineCurve(curve, options) {
|
|
91
|
+
const range = curve.getRange();
|
|
92
|
+
const span = range.length();
|
|
93
|
+
const curveLen = curve.length();
|
|
94
|
+
if (curveLen <= Precision.CURVE_LENGTH_EPS || span <= Precision.CURVE_PARAM_EPS) {
|
|
95
|
+
return {
|
|
96
|
+
closed: false,
|
|
97
|
+
samples: [{ u: range.start, p: curve.pointAt(range.start) }],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const initialSegments = buildInitialSegments(curve, options);
|
|
101
|
+
if (initialSegments.length === 0) {
|
|
102
|
+
return {
|
|
103
|
+
closed: false,
|
|
104
|
+
samples: [{ u: range.start, p: curve.pointAt(range.start) }],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (initialSegments.length > options.maxSegments) {
|
|
108
|
+
throwDiscretizeOverflowError('bspline strategy exceeds maxSegments constraints');
|
|
109
|
+
}
|
|
110
|
+
const refined = refineSegments(curve, initialSegments, options);
|
|
111
|
+
return {
|
|
112
|
+
closed: false,
|
|
113
|
+
samples: toSamples(refined),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Arc2 } from '../../curves/arc2';
|
|
2
|
+
import { Circle2 } from '../../curves/circle2';
|
|
3
|
+
import type { DiscretizeResult, ResolvedDiscretizeOptions } from '../discretize_types';
|
|
4
|
+
type CircleLikeCurve = Circle2 | Arc2;
|
|
5
|
+
export declare function discretizeCircleLikeCurve(curve: CircleLikeCurve, options: ResolvedDiscretizeOptions): DiscretizeResult;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=circle_strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circle_strategy.d.ts","sourceRoot":"","sources":["../../../src/discretize/strategies/circle_strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAG9C,OAAO,KAAK,EAAE,gBAAgB,EAAkB,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAEtG,KAAK,eAAe,GAAG,OAAO,GAAG,IAAI,CAAA;AAwBrC,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,yBAAyB,GACnC,gBAAgB,CAoClB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Circle2 } from '../../curves/circle2';
|
|
2
|
+
import { Precision } from '../../utils/precision';
|
|
3
|
+
import { throwDiscretizeOverflowError } from '../discretize_errors';
|
|
4
|
+
function dThetaByChord(radius, chordTol) {
|
|
5
|
+
const ratio = 1 - chordTol / radius;
|
|
6
|
+
if (ratio <= -1)
|
|
7
|
+
return Math.PI * 2;
|
|
8
|
+
const clamped = Math.min(1, Math.max(-1, ratio));
|
|
9
|
+
return 2 * Math.acos(clamped);
|
|
10
|
+
}
|
|
11
|
+
function buildCircleLikeSamples(curve, segmentCount, closed) {
|
|
12
|
+
const range = curve.getRange();
|
|
13
|
+
const start = range.start;
|
|
14
|
+
const span = range.length();
|
|
15
|
+
const steps = closed ? segmentCount : segmentCount + 1;
|
|
16
|
+
const samples = [];
|
|
17
|
+
for (let i = 0; i < steps; i++) {
|
|
18
|
+
const t = i / segmentCount;
|
|
19
|
+
const u = start + span * t;
|
|
20
|
+
samples.push({ u, p: curve.pointAt(u) });
|
|
21
|
+
}
|
|
22
|
+
return samples;
|
|
23
|
+
}
|
|
24
|
+
export function discretizeCircleLikeCurve(curve, options) {
|
|
25
|
+
const range = curve.getRange();
|
|
26
|
+
const sweep = range.length();
|
|
27
|
+
const radius = curve.radius;
|
|
28
|
+
const totalLen = curve.length();
|
|
29
|
+
const closed = curve instanceof Circle2 || Math.abs(sweep - Math.PI * 2) <= Precision.CURVE_PARAM_EPS;
|
|
30
|
+
if (totalLen <= Precision.CURVE_LENGTH_EPS || sweep <= Precision.CURVE_PARAM_EPS) {
|
|
31
|
+
return {
|
|
32
|
+
closed,
|
|
33
|
+
samples: [{ u: range.start, p: curve.pointAt(range.start) }],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const maxByInternal = Math.max(1, Math.floor(totalLen / options.minSegmentLengthInternal));
|
|
37
|
+
const dThetaChord = dThetaByChord(radius, options.effectiveChordTol);
|
|
38
|
+
const dThetaAngle = options.angleTolRad;
|
|
39
|
+
const dThetaLength = options.maxSegmentLength === Number.POSITIVE_INFINITY
|
|
40
|
+
? Number.POSITIVE_INFINITY
|
|
41
|
+
: options.maxSegmentLength / radius;
|
|
42
|
+
const dTheta = Math.max(Precision.CURVE_PARAM_EPS, Math.min(dThetaChord, dThetaAngle, dThetaLength));
|
|
43
|
+
const requiredSegments = Math.max(1, Math.ceil(sweep / dTheta));
|
|
44
|
+
if (requiredSegments > options.maxSegments || requiredSegments > maxByInternal) {
|
|
45
|
+
throwDiscretizeOverflowError('circle strategy exceeds maxSegments constraints');
|
|
46
|
+
}
|
|
47
|
+
const segmentCount = Math.max(requiredSegments, options.minSegments);
|
|
48
|
+
if (segmentCount > options.maxSegments || segmentCount > maxByInternal) {
|
|
49
|
+
throwDiscretizeOverflowError('circle strategy exceeds maxSegments constraints');
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
closed,
|
|
53
|
+
samples: buildCircleLikeSamples(curve, segmentCount, closed),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ellipse2 } from '../../curves/ellipse2';
|
|
2
|
+
import { EllipseArc2 } from '../../curves/ellipse_arc2';
|
|
3
|
+
import type { DiscretizeResult, ResolvedDiscretizeOptions } from '../discretize_types';
|
|
4
|
+
type EllipseLikeCurve = Ellipse2 | EllipseArc2;
|
|
5
|
+
export declare function discretizeEllipseLikeCurve(curve: EllipseLikeCurve, options: ResolvedDiscretizeOptions): DiscretizeResult;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=ellipse_strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ellipse_strategy.d.ts","sourceRoot":"","sources":["../../../src/discretize/strategies/ellipse_strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAGvD,OAAO,KAAK,EAAE,gBAAgB,EAAkB,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAGtG,KAAK,gBAAgB,GAAG,QAAQ,GAAG,WAAW,CAAA;AAyF9C,wBAAgB,0BAA0B,CACtC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,yBAAyB,GACnC,gBAAgB,CA2BlB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Ellipse2 } from '../../curves/ellipse2';
|
|
2
|
+
import { Precision } from '../../utils/precision';
|
|
3
|
+
import { throwDiscretizeConvergenceError, throwDiscretizeOverflowError } from '../discretize_errors';
|
|
4
|
+
import { maxChordDeviationAtFractions, tangentTurnAbs } from '../internal/sampling_utils';
|
|
5
|
+
function shouldSplitSegment(curve, segment, options) {
|
|
6
|
+
const chordLength = segment.p0.distanceTo(segment.p1);
|
|
7
|
+
const deviation = maxChordDeviationAtFractions(curve, segment.u0, segment.u1, segment.p0, segment.p1);
|
|
8
|
+
const turn = tangentTurnAbs(curve, segment.u0, segment.u1);
|
|
9
|
+
const violateMaxLength = chordLength > options.maxSegmentLength;
|
|
10
|
+
const violateChord = deviation > options.effectiveChordTol;
|
|
11
|
+
const violateTurn = turn > options.angleTolRad;
|
|
12
|
+
if (!violateMaxLength && !violateChord && !violateTurn)
|
|
13
|
+
return 'ok';
|
|
14
|
+
if (chordLength <= options.minSegmentLengthInternal) {
|
|
15
|
+
return 'blocked';
|
|
16
|
+
}
|
|
17
|
+
return 'split';
|
|
18
|
+
}
|
|
19
|
+
function buildInitialSegments(curve, segmentCount) {
|
|
20
|
+
const range = curve.getRange();
|
|
21
|
+
const start = range.start;
|
|
22
|
+
const span = range.length();
|
|
23
|
+
const segments = [];
|
|
24
|
+
for (let i = 0; i < segmentCount; i++) {
|
|
25
|
+
const u0 = start + (span * i) / segmentCount;
|
|
26
|
+
const u1 = start + (span * (i + 1)) / segmentCount;
|
|
27
|
+
segments.push({
|
|
28
|
+
u0,
|
|
29
|
+
u1,
|
|
30
|
+
p0: curve.pointAt(u0),
|
|
31
|
+
p1: curve.pointAt(u1),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return segments;
|
|
35
|
+
}
|
|
36
|
+
function refineAdaptiveSegments(curve, initialSegments, options) {
|
|
37
|
+
const segments = [...initialSegments];
|
|
38
|
+
for (let i = 0; i < segments.length; i++) {
|
|
39
|
+
const segment = segments[i];
|
|
40
|
+
const verdict = shouldSplitSegment(curve, segment, options);
|
|
41
|
+
if (verdict === 'ok')
|
|
42
|
+
continue;
|
|
43
|
+
if (verdict === 'blocked') {
|
|
44
|
+
throwDiscretizeOverflowError('ellipse strategy cannot satisfy constraints within internal segment limit');
|
|
45
|
+
}
|
|
46
|
+
if (segments.length >= options.maxSegments) {
|
|
47
|
+
throwDiscretizeOverflowError('ellipse strategy exceeds maxSegments constraints');
|
|
48
|
+
}
|
|
49
|
+
const mid = (segment.u0 + segment.u1) * 0.5;
|
|
50
|
+
if (Math.abs(mid - segment.u0) <= Precision.CURVE_PARAM_EPS || Math.abs(segment.u1 - mid) <= Precision.CURVE_PARAM_EPS) {
|
|
51
|
+
throwDiscretizeConvergenceError('ellipse strategy failed to converge');
|
|
52
|
+
}
|
|
53
|
+
const pm = curve.pointAt(mid);
|
|
54
|
+
segments.splice(i, 1, { u0: segment.u0, u1: mid, p0: segment.p0, p1: pm }, { u0: mid, u1: segment.u1, p0: pm, p1: segment.p1 });
|
|
55
|
+
i--;
|
|
56
|
+
}
|
|
57
|
+
return segments;
|
|
58
|
+
}
|
|
59
|
+
function segmentsToSamples(segments) {
|
|
60
|
+
const samples = [{ u: segments[0].u0, p: segments[0].p0.clone() }];
|
|
61
|
+
for (const segment of segments) {
|
|
62
|
+
samples.push({ u: segment.u1, p: segment.p1.clone() });
|
|
63
|
+
}
|
|
64
|
+
return samples;
|
|
65
|
+
}
|
|
66
|
+
export function discretizeEllipseLikeCurve(curve, options) {
|
|
67
|
+
const range = curve.getRange();
|
|
68
|
+
const span = range.length();
|
|
69
|
+
const curveLen = curve.length();
|
|
70
|
+
const closed = curve instanceof Ellipse2 || Math.abs(span - Math.PI * 2) <= Precision.CURVE_PARAM_EPS;
|
|
71
|
+
if (curveLen <= Precision.CURVE_LENGTH_EPS || span <= Precision.CURVE_PARAM_EPS) {
|
|
72
|
+
return {
|
|
73
|
+
closed,
|
|
74
|
+
samples: [{ u: range.start, p: curve.pointAt(range.start) }],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const initialSegmentCount = Math.max(1, options.minSegments);
|
|
78
|
+
if (initialSegmentCount > options.maxSegments) {
|
|
79
|
+
throwDiscretizeOverflowError('ellipse strategy exceeds maxSegments constraints');
|
|
80
|
+
}
|
|
81
|
+
const segments = refineAdaptiveSegments(curve, buildInitialSegments(curve, initialSegmentCount), options);
|
|
82
|
+
return {
|
|
83
|
+
closed,
|
|
84
|
+
samples: segmentsToSamples(segments),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Line2 } from '../../curves/line2';
|
|
2
|
+
import type { DiscretizeResult, ResolvedDiscretizeOptions } from '../discretize_types';
|
|
3
|
+
export declare function discretizeLineCurve(curve: Line2, options: ResolvedDiscretizeOptions): DiscretizeResult;
|
|
4
|
+
//# sourceMappingURL=line_strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line_strategy.d.ts","sourceRoot":"","sources":["../../../src/discretize/strategies/line_strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAkB,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAetG,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,yBAAyB,GACnC,gBAAgB,CA8BlB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Precision } from '../../utils/precision';
|
|
2
|
+
import { throwDiscretizeOverflowError } from '../discretize_errors';
|
|
3
|
+
function buildUniformLineSamples(curve, segmentCount) {
|
|
4
|
+
const range = curve.getRange();
|
|
5
|
+
const start = range.start;
|
|
6
|
+
const span = range.length();
|
|
7
|
+
const samples = [];
|
|
8
|
+
for (let i = 0; i <= segmentCount; i++) {
|
|
9
|
+
const u = start + (span * i) / segmentCount;
|
|
10
|
+
samples.push({ u, p: curve.pointAt(u) });
|
|
11
|
+
}
|
|
12
|
+
return samples;
|
|
13
|
+
}
|
|
14
|
+
export function discretizeLineCurve(curve, options) {
|
|
15
|
+
const curveLen = curve.length();
|
|
16
|
+
const range = curve.getRange();
|
|
17
|
+
if (curveLen <= Precision.CURVE_LENGTH_EPS || range.length() <= Precision.CURVE_PARAM_EPS) {
|
|
18
|
+
return {
|
|
19
|
+
closed: false,
|
|
20
|
+
samples: [{ u: range.start, p: curve.pointAt(range.start) }],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const requiredByMaxLen = options.maxSegmentLength === Number.POSITIVE_INFINITY
|
|
24
|
+
? 1
|
|
25
|
+
: Math.max(1, Math.ceil(curveLen / options.maxSegmentLength));
|
|
26
|
+
const maxByInternal = Math.max(1, Math.floor(curveLen / options.minSegmentLengthInternal));
|
|
27
|
+
if (requiredByMaxLen > options.maxSegments || requiredByMaxLen > maxByInternal) {
|
|
28
|
+
throwDiscretizeOverflowError('line strategy exceeds maxSegments constraints');
|
|
29
|
+
}
|
|
30
|
+
const segmentCount = options.minSegmentsExplicit
|
|
31
|
+
? Math.max(requiredByMaxLen, options.minSegments)
|
|
32
|
+
: requiredByMaxLen;
|
|
33
|
+
if (segmentCount > options.maxSegments || segmentCount > maxByInternal) {
|
|
34
|
+
throwDiscretizeOverflowError('line strategy exceeds maxSegments constraints');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
closed: false,
|
|
38
|
+
samples: buildUniformLineSamples(curve, segmentCount),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Curve2 } from '../curves/curve2';
|
|
2
|
+
import type { DiscretizeStrategy } from './discretize_types';
|
|
3
|
+
export declare class DiscretizeStrategyRegistry {
|
|
4
|
+
private _entries;
|
|
5
|
+
private _nextOrder;
|
|
6
|
+
register<T extends Curve2>(strategy: DiscretizeStrategy<T>): void;
|
|
7
|
+
resolve(curve: Curve2): DiscretizeStrategy<Curve2> | null;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=strategy_registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy_registry.d.ts","sourceRoot":"","sources":["../../src/discretize/strategy_registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAO5D,qBAAa,0BAA0B;IACnC,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,UAAU,CAAI;IAEf,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAc1D,OAAO,CAAC,KAAK,EAAE,MAAM;CAe/B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { throwDiscretizeOptionsError } from './discretize_errors';
|
|
2
|
+
export class DiscretizeStrategyRegistry {
|
|
3
|
+
constructor() {
|
|
4
|
+
this._entries = [];
|
|
5
|
+
this._nextOrder = 0;
|
|
6
|
+
}
|
|
7
|
+
register(strategy) {
|
|
8
|
+
if (strategy.ctor) {
|
|
9
|
+
const duplicated = this._entries.some((entry) => entry.strategy.ctor === strategy.ctor);
|
|
10
|
+
if (duplicated) {
|
|
11
|
+
throwDiscretizeOptionsError(`duplicated strategy constructor registration: ${strategy.id}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
this._entries.push({
|
|
15
|
+
order: this._nextOrder++,
|
|
16
|
+
strategy: strategy,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
resolve(curve) {
|
|
20
|
+
const ctorMatches = this._entries.filter((entry) => entry.strategy.ctor === curve.constructor);
|
|
21
|
+
if (ctorMatches.length > 1) {
|
|
22
|
+
throwDiscretizeOptionsError('ambiguous strategy constructor match');
|
|
23
|
+
}
|
|
24
|
+
if (ctorMatches.length === 1) {
|
|
25
|
+
return ctorMatches[0].strategy;
|
|
26
|
+
}
|
|
27
|
+
const guardMatches = this._entries
|
|
28
|
+
.filter((entry) => entry.strategy.canHandle(curve))
|
|
29
|
+
.sort((a, b) => a.order - b.order);
|
|
30
|
+
if (guardMatches.length === 0)
|
|
31
|
+
return null;
|
|
32
|
+
return guardMatches[0].strategy;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { Vec2 } from './core/vec2';
|
|
2
|
+
export { Mat3 } from './core/mat3';
|
|
3
|
+
export { Box2 } from './core/box2';
|
|
4
|
+
export { Coord2D } from './core/coord2d';
|
|
5
|
+
export { GeomBase } from './core/geom_base';
|
|
6
|
+
export { MathConst } from './constants/math_const';
|
|
7
|
+
export { Curve2 } from './curves/curve2';
|
|
8
|
+
export { Interval } from './curves/interval';
|
|
9
|
+
export { PeriodInterval } from './curves/period_interval';
|
|
10
|
+
export { CircleCurve2 } from './curves/circle_curve2';
|
|
11
|
+
export { EllipseCurve2 } from './curves/ellipse_curve2';
|
|
12
|
+
export { Line2 } from './curves/line2';
|
|
13
|
+
export { Circle2 } from './curves/circle2';
|
|
14
|
+
export { Arc2 } from './curves/arc2';
|
|
15
|
+
export { Ellipse2 } from './curves/ellipse2';
|
|
16
|
+
export { EllipseArc2 } from './curves/ellipse_arc2';
|
|
17
|
+
export { BSpline2 } from './curves/bspline2';
|
|
18
|
+
export type { IBSpline2Options } from './curves/bspline2';
|
|
19
|
+
export { Precision } from './utils/precision';
|
|
20
|
+
export { MathUtils } from './utils/math_utils';
|
|
21
|
+
export { MathError } from './utils/math_error';
|
|
22
|
+
export { DiscretizeEngine } from './discretize/discretize_engine';
|
|
23
|
+
export { DiscretizeOptions } from './discretize/discretize_options';
|
|
24
|
+
export { intersectCurveCurve, intersectCurveSelf } from './intersections';
|
|
25
|
+
export type { CurveXInfo } from './intersections';
|
|
26
|
+
export { GeomMgr, geomMgr, RegisterGeom } from './serialize/geom_mgr';
|
|
27
|
+
export type { IDumpable, ILoadable } from './serialize/geom_mgr';
|
|
28
|
+
export type { IDB, IDBVec2, IDBMat3, IDBBox2, IDBCoord2D, IDBLine2, IDBCircle2, IDBArc2, IDBEllipse2, IDBEllipseArc2, IDBBSpline2, } from './serialize/dump_types';
|
|
29
|
+
export type { IVec2, IClosestPointResult } from './types/type_define';
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAEnE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACrE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChE,YAAY,EACR,GAAG,EACH,OAAO,EACP,OAAO,EACP,OAAO,EACP,UAAU,EACV,QAAQ,EACR,UAAU,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACd,WAAW,GACd,MAAM,wBAAwB,CAAA;AAE/B,YAAY,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { Vec2 } from './core/vec2';
|
|
2
|
+
export { Mat3 } from './core/mat3';
|
|
3
|
+
export { Box2 } from './core/box2';
|
|
4
|
+
export { Coord2D } from './core/coord2d';
|
|
5
|
+
export { GeomBase } from './core/geom_base';
|
|
6
|
+
export { MathConst } from './constants/math_const';
|
|
7
|
+
export { Curve2 } from './curves/curve2';
|
|
8
|
+
export { Interval } from './curves/interval';
|
|
9
|
+
export { PeriodInterval } from './curves/period_interval';
|
|
10
|
+
export { CircleCurve2 } from './curves/circle_curve2';
|
|
11
|
+
export { EllipseCurve2 } from './curves/ellipse_curve2';
|
|
12
|
+
export { Line2 } from './curves/line2';
|
|
13
|
+
export { Circle2 } from './curves/circle2';
|
|
14
|
+
export { Arc2 } from './curves/arc2';
|
|
15
|
+
export { Ellipse2 } from './curves/ellipse2';
|
|
16
|
+
export { EllipseArc2 } from './curves/ellipse_arc2';
|
|
17
|
+
export { BSpline2 } from './curves/bspline2';
|
|
18
|
+
export { Precision } from './utils/precision';
|
|
19
|
+
export { MathUtils } from './utils/math_utils';
|
|
20
|
+
export { MathError } from './utils/math_error';
|
|
21
|
+
export { DiscretizeEngine } from './discretize/discretize_engine';
|
|
22
|
+
export { DiscretizeOptions } from './discretize/discretize_options';
|
|
23
|
+
export { intersectCurveCurve, intersectCurveSelf } from './intersections';
|
|
24
|
+
export { GeomMgr, geomMgr, RegisterGeom } from './serialize/geom_mgr';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Curve2 } from '../curves/curve2';
|
|
2
|
+
import type { CurveXInfo } from './types';
|
|
3
|
+
export declare class AnalyticXAlgorithm {
|
|
4
|
+
private readonly map;
|
|
5
|
+
private readonly retryMap;
|
|
6
|
+
intersect(c1: Curve2, c2: Curve2): CurveXInfo[];
|
|
7
|
+
private shouldRetry;
|
|
8
|
+
private boxesLikelyIntersect;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=analytic_x_algorithm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytic_x_algorithm.d.ts","sourceRoot":"","sources":["../../src/intersections/analytic_x_algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAyB9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAoBnB;IAED,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAQxB;IAEM,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,EAAE;IA2BtD,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,oBAAoB;CAM/B"}
|