@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 genewanggang-sudo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @ccpc/math
|
|
2
|
+
|
|
3
|
+
2D geometry and curve math library for Linea.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @ccpc/math
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Vec2, Line2, Circle2, BSpline2 } from '@ccpc/math'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Build
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm --filter "@ccpc/math" build
|
|
21
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum EN_GEO_TYPE {
|
|
2
|
+
Vec2 = "Vec2",
|
|
3
|
+
Mat3 = "Mat3",
|
|
4
|
+
Box2 = "Box2",
|
|
5
|
+
Coord2D = "Coord2D",
|
|
6
|
+
Line2 = "Line2",
|
|
7
|
+
Circle2 = "Circle2",
|
|
8
|
+
Arc2 = "Arc2",
|
|
9
|
+
Ellipse2 = "Ellipse2",
|
|
10
|
+
EllipseArc2 = "EllipseArc2",
|
|
11
|
+
BSpline2 = "BSpline2"
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=geom_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geom_type.d.ts","sourceRoot":"","sources":["../../src/constants/geom_type.ts"],"names":[],"mappings":"AAKA,oBAAY,WAAW;IACnB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,IAAI,SAAS;IACb,OAAO,YAAY;IAEnB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;CACxB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Linea Math - Types
|
|
3
|
+
* 用于序列化的几何类型枚举
|
|
4
|
+
*/
|
|
5
|
+
export var EN_GEO_TYPE;
|
|
6
|
+
(function (EN_GEO_TYPE) {
|
|
7
|
+
EN_GEO_TYPE["Vec2"] = "Vec2";
|
|
8
|
+
EN_GEO_TYPE["Mat3"] = "Mat3";
|
|
9
|
+
EN_GEO_TYPE["Box2"] = "Box2";
|
|
10
|
+
EN_GEO_TYPE["Coord2D"] = "Coord2D";
|
|
11
|
+
EN_GEO_TYPE["Line2"] = "Line2";
|
|
12
|
+
EN_GEO_TYPE["Circle2"] = "Circle2";
|
|
13
|
+
EN_GEO_TYPE["Arc2"] = "Arc2";
|
|
14
|
+
EN_GEO_TYPE["Ellipse2"] = "Ellipse2";
|
|
15
|
+
EN_GEO_TYPE["EllipseArc2"] = "EllipseArc2";
|
|
16
|
+
EN_GEO_TYPE["BSpline2"] = "BSpline2";
|
|
17
|
+
})(EN_GEO_TYPE || (EN_GEO_TYPE = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math_const.d.ts","sourceRoot":"","sources":["../../src/constants/math_const.ts"],"names":[],"mappings":"AAKA,qBAAa,SAAS;IAClB,kBAAkB;IAClB,gBAAuB,GAAG,SAA2B;IAErD,kBAAkB;IAClB,gBAAuB,GAAG,SAA2B;IAErD,aAAa;IACb,gBAAuB,GAAG,SAAc;CAC3C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Linea Math - Constants
|
|
3
|
+
* MathConst: 数学常量集中定义
|
|
4
|
+
*/
|
|
5
|
+
export class MathConst {
|
|
6
|
+
}
|
|
7
|
+
/** 负无穷,表示无界最小值 */
|
|
8
|
+
MathConst.MIN = Number.NEGATIVE_INFINITY;
|
|
9
|
+
/** 正无穷,表示无界最大值 */
|
|
10
|
+
MathConst.MAX = Number.POSITIVE_INFINITY;
|
|
11
|
+
/** 2 * PI */
|
|
12
|
+
MathConst.PI2 = Math.PI * 2;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { GeomBase } from './geom_base';
|
|
2
|
+
import { EN_GEO_TYPE } from '../constants/geom_type';
|
|
3
|
+
import type { IDBBox2 } from '../serialize/dump_types';
|
|
4
|
+
import { Vec2 } from './vec2';
|
|
5
|
+
import { Mat3 } from './mat3';
|
|
6
|
+
export declare class Box2 extends GeomBase {
|
|
7
|
+
/** 序列化类型标识 */
|
|
8
|
+
static readonly type = EN_GEO_TYPE.Box2;
|
|
9
|
+
/** 最小/最大边界 */
|
|
10
|
+
readonly minX: number;
|
|
11
|
+
readonly minY: number;
|
|
12
|
+
readonly maxX: number;
|
|
13
|
+
readonly maxY: number;
|
|
14
|
+
/** 创建 Box2(默认为空盒) */
|
|
15
|
+
constructor();
|
|
16
|
+
constructor(b: Box2);
|
|
17
|
+
constructor(min: Vec2, max: Vec2);
|
|
18
|
+
constructor(points: readonly Vec2[]);
|
|
19
|
+
constructor(minX: number, minY: number, maxX: number, maxY: number);
|
|
20
|
+
/** 空盒 */
|
|
21
|
+
static empty(): Box2;
|
|
22
|
+
/** 由最小/最大点创建 */
|
|
23
|
+
static fromMinMax(min: Vec2, max: Vec2): Box2;
|
|
24
|
+
/** 由点集创建 */
|
|
25
|
+
static fromPoints(points: readonly Vec2[]): Box2;
|
|
26
|
+
/** 克隆 */
|
|
27
|
+
clone(): Box2;
|
|
28
|
+
/** 是否为空盒 */
|
|
29
|
+
isEmpty(): boolean;
|
|
30
|
+
/** 是否为有限数 */
|
|
31
|
+
isFinite(): boolean;
|
|
32
|
+
/** 宽度 */
|
|
33
|
+
width(): number;
|
|
34
|
+
/** 高度 */
|
|
35
|
+
height(): number;
|
|
36
|
+
/** 尺寸 */
|
|
37
|
+
size(): Vec2;
|
|
38
|
+
/** 中心点 */
|
|
39
|
+
center(): Vec2;
|
|
40
|
+
/** 是否包含点 */
|
|
41
|
+
containsPoint(v: Vec2): boolean;
|
|
42
|
+
/** 是否包含盒 */
|
|
43
|
+
containsBox(b: Box2): boolean;
|
|
44
|
+
/** 是否相交 */
|
|
45
|
+
intersects(b: Box2): boolean;
|
|
46
|
+
/** 扩展以包含点 */
|
|
47
|
+
expandByPoint(v: Vec2): Box2;
|
|
48
|
+
/** 按标量扩展 */
|
|
49
|
+
expandByScalar(s: number): Box2;
|
|
50
|
+
/** 合并盒 */
|
|
51
|
+
union(b: Box2): Box2;
|
|
52
|
+
/** 平移 */
|
|
53
|
+
translate(dx: number, dy: number): Box2;
|
|
54
|
+
/** 变换(返回新对象) */
|
|
55
|
+
transform(m: Mat3): Box2;
|
|
56
|
+
/** 变换(返回新对象) */
|
|
57
|
+
transformed(m: Mat3): Box2;
|
|
58
|
+
/** 点到盒子的最短距离 */
|
|
59
|
+
distanceToPoint(p: Vec2): number;
|
|
60
|
+
/** 将点限制在盒子范围内 */
|
|
61
|
+
clampPoint(p: Vec2): Vec2;
|
|
62
|
+
/** 交集盒 */
|
|
63
|
+
intersect(b: Box2): Box2;
|
|
64
|
+
/** 近似相等 */
|
|
65
|
+
equals(b: Box2, eps?: number): boolean;
|
|
66
|
+
/** 序列化为结构对象 */
|
|
67
|
+
dump(): IDBBox2;
|
|
68
|
+
/** 从结构对象反序列化 */
|
|
69
|
+
static load(data: IDBBox2): Box2;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=box2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box2.d.ts","sourceRoot":"","sources":["../../src/core/box2.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAG7B,qBACa,IAAK,SAAQ,QAAQ;IAC9B,cAAc;IACd,gBAAuB,IAAI,oBAAmB;IAE9C,cAAc;IACd,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,IAAI,EAAE,MAAM,CAAA;IAE5B,qBAAqB;;gBAET,CAAC,EAAE,IAAI;gBACP,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;gBACpB,MAAM,EAAE,SAAS,IAAI,EAAE;gBACvB,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IA2ClE,SAAS;WACK,KAAK;IAInB,gBAAgB;WACF,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI;IAI7C,YAAY;WACE,UAAU,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE;IAehD,SAAS;IACF,KAAK;IAIZ,YAAY;IACL,OAAO;IAId,aAAa;IACN,QAAQ;IASf,SAAS;IACF,KAAK;IAIZ,SAAS;IACF,MAAM;IAIb,SAAS;IACF,IAAI;IAIX,UAAU;IACH,MAAM;IAQb,YAAY;IACL,aAAa,CAAC,CAAC,EAAE,IAAI;IAU5B,YAAY;IACL,WAAW,CAAC,CAAC,EAAE,IAAI;IAU1B,WAAW;IACJ,UAAU,CAAC,CAAC,EAAE,IAAI;IAUzB,aAAa;IACN,aAAa,CAAC,CAAC,EAAE,IAAI;IAY5B,YAAY;IACL,cAAc,CAAC,CAAC,EAAE,MAAM;IAU/B,UAAU;IACH,KAAK,CAAC,CAAC,EAAE,IAAI;IAWpB,SAAS;IACF,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAUvC,gBAAgB;IACT,SAAS,CAAC,CAAC,EAAE,IAAI;IAaxB,gBAAgB;IACT,WAAW,CAAC,CAAC,EAAE,IAAI;IAI1B,gBAAgB;IACT,eAAe,CAAC,CAAC,EAAE,IAAI;IAW9B,iBAAiB;IACV,UAAU,CAAC,CAAC,EAAE,IAAI;IAOzB,UAAU;IACH,SAAS,CAAC,CAAC,EAAE,IAAI;IASxB,WAAW;IACJ,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,SAAgB;IAW1C,eAAe;IACR,IAAI,IAAI,OAAO;IAUtB,gBAAgB;WACF,IAAI,CAAC,IAAI,EAAE,OAAO;CAGnC"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Linea Math - Core
|
|
3
|
+
* Box2:二维轴对齐包围盒(AABB),不可变设计
|
|
4
|
+
*/
|
|
5
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var Box2_1;
|
|
12
|
+
import { GeomBase } from './geom_base';
|
|
13
|
+
import { EN_GEO_TYPE } from '../constants/geom_type';
|
|
14
|
+
import { RegisterGeom } from '../serialize/geom_mgr';
|
|
15
|
+
import { Vec2 } from './vec2';
|
|
16
|
+
import { Precision } from '../utils/precision';
|
|
17
|
+
let Box2 = Box2_1 = class Box2 extends GeomBase {
|
|
18
|
+
constructor(a0, a1, a2, a3) {
|
|
19
|
+
super();
|
|
20
|
+
if (a0 instanceof Box2_1) {
|
|
21
|
+
this.minX = a0.minX;
|
|
22
|
+
this.minY = a0.minY;
|
|
23
|
+
this.maxX = a0.maxX;
|
|
24
|
+
this.maxY = a0.maxY;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (a0 instanceof Vec2 && a1 instanceof Vec2) {
|
|
28
|
+
this.minX = a0.x;
|
|
29
|
+
this.minY = a0.y;
|
|
30
|
+
this.maxX = a1.x;
|
|
31
|
+
this.maxY = a1.y;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(a0)) {
|
|
35
|
+
const b = Box2_1.fromPoints(a0);
|
|
36
|
+
this.minX = b.minX;
|
|
37
|
+
this.minY = b.minY;
|
|
38
|
+
this.maxX = b.maxX;
|
|
39
|
+
this.maxY = b.maxY;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const minX = typeof a0 === 'number' ? a0 : Infinity;
|
|
43
|
+
const minY = typeof a1 === 'number' ? a1 : Infinity;
|
|
44
|
+
const maxX = typeof a2 === 'number' ? a2 : -Infinity;
|
|
45
|
+
const maxY = typeof a3 === 'number' ? a3 : -Infinity;
|
|
46
|
+
this.minX = minX;
|
|
47
|
+
this.minY = minY;
|
|
48
|
+
this.maxX = maxX;
|
|
49
|
+
this.maxY = maxY;
|
|
50
|
+
}
|
|
51
|
+
/** 空盒 */
|
|
52
|
+
static empty() {
|
|
53
|
+
return new Box2_1();
|
|
54
|
+
}
|
|
55
|
+
/** 由最小/最大点创建 */
|
|
56
|
+
static fromMinMax(min, max) {
|
|
57
|
+
return new Box2_1(min.x, min.y, max.x, max.y);
|
|
58
|
+
}
|
|
59
|
+
/** 由点集创建 */
|
|
60
|
+
static fromPoints(points) {
|
|
61
|
+
if (points.length === 0)
|
|
62
|
+
return Box2_1.empty();
|
|
63
|
+
let minX = Infinity;
|
|
64
|
+
let minY = Infinity;
|
|
65
|
+
let maxX = -Infinity;
|
|
66
|
+
let maxY = -Infinity;
|
|
67
|
+
for (const p of points) {
|
|
68
|
+
if (p.x < minX)
|
|
69
|
+
minX = p.x;
|
|
70
|
+
if (p.y < minY)
|
|
71
|
+
minY = p.y;
|
|
72
|
+
if (p.x > maxX)
|
|
73
|
+
maxX = p.x;
|
|
74
|
+
if (p.y > maxY)
|
|
75
|
+
maxY = p.y;
|
|
76
|
+
}
|
|
77
|
+
return new Box2_1(minX, minY, maxX, maxY);
|
|
78
|
+
}
|
|
79
|
+
/** 克隆 */
|
|
80
|
+
clone() {
|
|
81
|
+
return new Box2_1(this.minX, this.minY, this.maxX, this.maxY);
|
|
82
|
+
}
|
|
83
|
+
/** 是否为空盒 */
|
|
84
|
+
isEmpty() {
|
|
85
|
+
return this.minX > this.maxX || this.minY > this.maxY;
|
|
86
|
+
}
|
|
87
|
+
/** 是否为有限数 */
|
|
88
|
+
isFinite() {
|
|
89
|
+
return (Number.isFinite(this.minX) &&
|
|
90
|
+
Number.isFinite(this.minY) &&
|
|
91
|
+
Number.isFinite(this.maxX) &&
|
|
92
|
+
Number.isFinite(this.maxY));
|
|
93
|
+
}
|
|
94
|
+
/** 宽度 */
|
|
95
|
+
width() {
|
|
96
|
+
return this.isEmpty() ? 0 : this.maxX - this.minX;
|
|
97
|
+
}
|
|
98
|
+
/** 高度 */
|
|
99
|
+
height() {
|
|
100
|
+
return this.isEmpty() ? 0 : this.maxY - this.minY;
|
|
101
|
+
}
|
|
102
|
+
/** 尺寸 */
|
|
103
|
+
size() {
|
|
104
|
+
return new Vec2(this.width(), this.height());
|
|
105
|
+
}
|
|
106
|
+
/** 中心点 */
|
|
107
|
+
center() {
|
|
108
|
+
if (this.isEmpty())
|
|
109
|
+
return Vec2.zero();
|
|
110
|
+
return new Vec2((this.minX + this.maxX) / 2, (this.minY + this.maxY) / 2);
|
|
111
|
+
}
|
|
112
|
+
/** 是否包含点 */
|
|
113
|
+
containsPoint(v) {
|
|
114
|
+
if (this.isEmpty())
|
|
115
|
+
return false;
|
|
116
|
+
return (v.x >= this.minX &&
|
|
117
|
+
v.x <= this.maxX &&
|
|
118
|
+
v.y >= this.minY &&
|
|
119
|
+
v.y <= this.maxY);
|
|
120
|
+
}
|
|
121
|
+
/** 是否包含盒 */
|
|
122
|
+
containsBox(b) {
|
|
123
|
+
if (this.isEmpty() || b.isEmpty())
|
|
124
|
+
return false;
|
|
125
|
+
return (b.minX >= this.minX &&
|
|
126
|
+
b.maxX <= this.maxX &&
|
|
127
|
+
b.minY >= this.minY &&
|
|
128
|
+
b.maxY <= this.maxY);
|
|
129
|
+
}
|
|
130
|
+
/** 是否相交 */
|
|
131
|
+
intersects(b) {
|
|
132
|
+
if (this.isEmpty() || b.isEmpty())
|
|
133
|
+
return false;
|
|
134
|
+
return (b.maxX >= this.minX &&
|
|
135
|
+
b.minX <= this.maxX &&
|
|
136
|
+
b.maxY >= this.minY &&
|
|
137
|
+
b.minY <= this.maxY);
|
|
138
|
+
}
|
|
139
|
+
/** 扩展以包含点 */
|
|
140
|
+
expandByPoint(v) {
|
|
141
|
+
if (this.isEmpty()) {
|
|
142
|
+
return new Box2_1(v.x, v.y, v.x, v.y);
|
|
143
|
+
}
|
|
144
|
+
return new Box2_1(Math.min(this.minX, v.x), Math.min(this.minY, v.y), Math.max(this.maxX, v.x), Math.max(this.maxY, v.y));
|
|
145
|
+
}
|
|
146
|
+
/** 按标量扩展 */
|
|
147
|
+
expandByScalar(s) {
|
|
148
|
+
if (this.isEmpty())
|
|
149
|
+
return this.clone();
|
|
150
|
+
return new Box2_1(this.minX - s, this.minY - s, this.maxX + s, this.maxY + s);
|
|
151
|
+
}
|
|
152
|
+
/** 合并盒 */
|
|
153
|
+
union(b) {
|
|
154
|
+
if (this.isEmpty())
|
|
155
|
+
return b.clone();
|
|
156
|
+
if (b.isEmpty())
|
|
157
|
+
return this.clone();
|
|
158
|
+
return new Box2_1(Math.min(this.minX, b.minX), Math.min(this.minY, b.minY), Math.max(this.maxX, b.maxX), Math.max(this.maxY, b.maxY));
|
|
159
|
+
}
|
|
160
|
+
/** 平移 */
|
|
161
|
+
translate(dx, dy) {
|
|
162
|
+
if (this.isEmpty())
|
|
163
|
+
return this.clone();
|
|
164
|
+
return new Box2_1(this.minX + dx, this.minY + dy, this.maxX + dx, this.maxY + dy);
|
|
165
|
+
}
|
|
166
|
+
/** 变换(返回新对象) */
|
|
167
|
+
transform(m) {
|
|
168
|
+
if (this.isEmpty())
|
|
169
|
+
return this.clone();
|
|
170
|
+
const p1 = m.transformedPoint(new Vec2(this.minX, this.minY));
|
|
171
|
+
const p2 = m.transformedPoint(new Vec2(this.minX, this.maxY));
|
|
172
|
+
const p3 = m.transformedPoint(new Vec2(this.maxX, this.minY));
|
|
173
|
+
const p4 = m.transformedPoint(new Vec2(this.maxX, this.maxY));
|
|
174
|
+
const minX = Math.min(p1.x, p2.x, p3.x, p4.x);
|
|
175
|
+
const minY = Math.min(p1.y, p2.y, p3.y, p4.y);
|
|
176
|
+
const maxX = Math.max(p1.x, p2.x, p3.x, p4.x);
|
|
177
|
+
const maxY = Math.max(p1.y, p2.y, p3.y, p4.y);
|
|
178
|
+
return new Box2_1(minX, minY, maxX, maxY);
|
|
179
|
+
}
|
|
180
|
+
/** 变换(返回新对象) */
|
|
181
|
+
transformed(m) {
|
|
182
|
+
return this.transform(m);
|
|
183
|
+
}
|
|
184
|
+
/** 点到盒子的最短距离 */
|
|
185
|
+
distanceToPoint(p) {
|
|
186
|
+
if (this.isEmpty())
|
|
187
|
+
return Infinity;
|
|
188
|
+
const dx = p.x < this.minX ? this.minX - p.x :
|
|
189
|
+
p.x > this.maxX ? p.x - this.maxX : 0;
|
|
190
|
+
const dy = p.y < this.minY ? this.minY - p.y :
|
|
191
|
+
p.y > this.maxY ? p.y - this.maxY : 0;
|
|
192
|
+
return Math.hypot(dx, dy);
|
|
193
|
+
}
|
|
194
|
+
/** 将点限制在盒子范围内 */
|
|
195
|
+
clampPoint(p) {
|
|
196
|
+
if (this.isEmpty())
|
|
197
|
+
return p.clone();
|
|
198
|
+
const x = Math.min(this.maxX, Math.max(this.minX, p.x));
|
|
199
|
+
const y = Math.min(this.maxY, Math.max(this.minY, p.y));
|
|
200
|
+
return new Vec2(x, y);
|
|
201
|
+
}
|
|
202
|
+
/** 交集盒 */
|
|
203
|
+
intersect(b) {
|
|
204
|
+
if (this.isEmpty() || b.isEmpty())
|
|
205
|
+
return Box2_1.empty();
|
|
206
|
+
const minX = Math.max(this.minX, b.minX);
|
|
207
|
+
const minY = Math.max(this.minY, b.minY);
|
|
208
|
+
const maxX = Math.min(this.maxX, b.maxX);
|
|
209
|
+
const maxY = Math.min(this.maxY, b.maxY);
|
|
210
|
+
return minX > maxX || minY > maxY ? Box2_1.empty() : new Box2_1(minX, minY, maxX, maxY);
|
|
211
|
+
}
|
|
212
|
+
/** 近似相等 */
|
|
213
|
+
equals(b, eps = Precision.EPS) {
|
|
214
|
+
if (this.isEmpty() && b.isEmpty())
|
|
215
|
+
return true;
|
|
216
|
+
if (this.isEmpty() || b.isEmpty())
|
|
217
|
+
return false;
|
|
218
|
+
return (Precision.equal(this.minX, b.minX, eps) &&
|
|
219
|
+
Precision.equal(this.minY, b.minY, eps) &&
|
|
220
|
+
Precision.equal(this.maxX, b.maxX, eps) &&
|
|
221
|
+
Precision.equal(this.maxY, b.maxY, eps));
|
|
222
|
+
}
|
|
223
|
+
/** 序列化为结构对象 */
|
|
224
|
+
dump() {
|
|
225
|
+
return {
|
|
226
|
+
type: Box2_1.type,
|
|
227
|
+
minX: this.minX,
|
|
228
|
+
minY: this.minY,
|
|
229
|
+
maxX: this.maxX,
|
|
230
|
+
maxY: this.maxY,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/** 从结构对象反序列化 */
|
|
234
|
+
static load(data) {
|
|
235
|
+
return new Box2_1(data.minX, data.minY, data.maxX, data.maxY);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
/** 序列化类型标识 */
|
|
239
|
+
Box2.type = EN_GEO_TYPE.Box2;
|
|
240
|
+
Box2 = Box2_1 = __decorate([
|
|
241
|
+
RegisterGeom
|
|
242
|
+
], Box2);
|
|
243
|
+
export { Box2 };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { GeomBase } from './geom_base';
|
|
2
|
+
import { EN_GEO_TYPE } from '../constants/geom_type';
|
|
3
|
+
import type { IDBCoord2D } from '../serialize/dump_types';
|
|
4
|
+
import { Vec2 } from './vec2';
|
|
5
|
+
import { Mat3 } from './mat3';
|
|
6
|
+
export declare class Coord2D extends GeomBase {
|
|
7
|
+
/** 序列化类型标识 */
|
|
8
|
+
static readonly type = EN_GEO_TYPE.Coord2D;
|
|
9
|
+
/** 原点 */
|
|
10
|
+
private _origin;
|
|
11
|
+
/** X 轴基向量(世界坐标) */
|
|
12
|
+
private _xAxis;
|
|
13
|
+
/** Y 轴基向量(世界坐标) */
|
|
14
|
+
private _yAxis;
|
|
15
|
+
/** 创建坐标系 */
|
|
16
|
+
constructor();
|
|
17
|
+
constructor(c: Coord2D);
|
|
18
|
+
constructor(m: Mat3);
|
|
19
|
+
constructor(origin: Vec2, xAxis?: Vec2, yAxis?: Vec2);
|
|
20
|
+
/** 克隆 */
|
|
21
|
+
clone(): Coord2D;
|
|
22
|
+
/** 获取原点 */
|
|
23
|
+
getOrigin(): Vec2;
|
|
24
|
+
/** 获取 X 轴方向 */
|
|
25
|
+
getDx(): Vec2;
|
|
26
|
+
/** 获取 Y 轴方向 */
|
|
27
|
+
getDy(): Vec2;
|
|
28
|
+
/** 是否为可用基(不退化) */
|
|
29
|
+
isValid(eps?: number): boolean;
|
|
30
|
+
/** 坐标系近似相等 */
|
|
31
|
+
equals(c: Coord2D, eps?: number): boolean;
|
|
32
|
+
/** 局部坐标 -> 世界坐标 */
|
|
33
|
+
toWorld(p: Vec2): Vec2;
|
|
34
|
+
/** 世界坐标 -> 局部坐标 */
|
|
35
|
+
toLocal(p: Vec2, eps?: number): Vec2;
|
|
36
|
+
/** 转为变换矩阵(列向量 + 右乘约定) */
|
|
37
|
+
toMat3(): Mat3;
|
|
38
|
+
/** 变换坐标系(就地修改) */
|
|
39
|
+
transform(m: Mat3): this;
|
|
40
|
+
/** 变换坐标系(返回新对象) */
|
|
41
|
+
transformed(m: Mat3): Coord2D;
|
|
42
|
+
/**
|
|
43
|
+
* 逆坐标系(世界 <-> 局部)
|
|
44
|
+
* - 用于把世界坐标转换为该坐标系的局部坐标
|
|
45
|
+
*/
|
|
46
|
+
inverse(eps?: number): Coord2D;
|
|
47
|
+
/** 设置原点(就地修改) */
|
|
48
|
+
setOrigin(origin: Vec2): this;
|
|
49
|
+
/** 设置 X 轴(就地修改) */
|
|
50
|
+
setXAxis(xAxis: Vec2): this;
|
|
51
|
+
/** 设置 Y 轴(就地修改) */
|
|
52
|
+
setYAxis(yAxis: Vec2): this;
|
|
53
|
+
/** 获取缩放(轴长度) */
|
|
54
|
+
getScale(): Vec2;
|
|
55
|
+
/** 设置缩放(保持轴方向不变) */
|
|
56
|
+
setScale(sx: number, sy: number, eps?: number): this;
|
|
57
|
+
/** 序列化为结构对象 */
|
|
58
|
+
dump(): IDBCoord2D;
|
|
59
|
+
/** 从结构对象反序列化 */
|
|
60
|
+
static load(data: IDBCoord2D): Coord2D;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=coord2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coord2d.d.ts","sourceRoot":"","sources":["../../src/core/coord2d.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAI7B,qBACa,OAAQ,SAAQ,QAAQ;IACjC,cAAc;IACd,gBAAuB,IAAI,uBAAsB;IAEjD,SAAS;IACT,OAAO,CAAC,OAAO,CAAM;IAErB,mBAAmB;IACnB,OAAO,CAAC,MAAM,CAAM;IAEpB,mBAAmB;IACnB,OAAO,CAAC,MAAM,CAAM;IAEpB,YAAY;;gBAEA,CAAC,EAAE,OAAO;gBACV,CAAC,EAAE,IAAI;gBACP,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,IAAI;IA6BpD,SAAS;IACF,KAAK;IAIZ,WAAW;IACJ,SAAS;IAIhB,eAAe;IACR,KAAK;IAIZ,eAAe;IACR,KAAK;IAIZ,kBAAkB;IACX,OAAO,CAAC,GAAG,SAAoB;IAKtC,cAAc;IACP,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,SAAgB;IAQ7C,mBAAmB;IACZ,OAAO,CAAC,CAAC,EAAE,IAAI;IAMtB,mBAAmB;IACZ,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,SAAoB;IAa/C,yBAAyB;IAClB,MAAM;IAQb,kBAAkB;IACX,SAAS,CAAC,CAAC,EAAE,IAAI;IAOxB,mBAAmB;IACZ,WAAW,CAAC,CAAC,EAAE,IAAI;IAI1B;;;OAGG;IACI,OAAO,CAAC,GAAG,SAAoB;IAKtC,iBAAiB;IACV,SAAS,CAAC,MAAM,EAAE,IAAI;IAK7B,mBAAmB;IACZ,QAAQ,CAAC,KAAK,EAAE,IAAI;IAK3B,mBAAmB;IACZ,QAAQ,CAAC,KAAK,EAAE,IAAI;IAK3B,gBAAgB;IACT,QAAQ;IAIf,oBAAoB;IACb,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,SAAoB;IAM/D,eAAe;IACR,IAAI,IAAI,UAAU;IASzB,gBAAgB;WACF,IAAI,CAAC,IAAI,EAAE,UAAU;CAOtC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Linea Math - Core
|
|
3
|
+
* Coord2D: 2D 坐标系(原点 + 基向量),不可变
|
|
4
|
+
*/
|
|
5
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var Coord2D_1;
|
|
12
|
+
import { GeomBase } from './geom_base';
|
|
13
|
+
import { EN_GEO_TYPE } from '../constants/geom_type';
|
|
14
|
+
import { RegisterGeom } from '../serialize/geom_mgr';
|
|
15
|
+
import { Vec2 } from './vec2';
|
|
16
|
+
import { Mat3 } from './mat3';
|
|
17
|
+
import { Precision } from '../utils/precision';
|
|
18
|
+
import { MathError } from '../utils/math_error';
|
|
19
|
+
let Coord2D = Coord2D_1 = class Coord2D extends GeomBase {
|
|
20
|
+
constructor(a0, a1, a2) {
|
|
21
|
+
super();
|
|
22
|
+
if (a0 instanceof Coord2D_1) {
|
|
23
|
+
this._origin = a0._origin;
|
|
24
|
+
this._xAxis = a0._xAxis;
|
|
25
|
+
this._yAxis = a0._yAxis;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (a0 instanceof Mat3) {
|
|
29
|
+
const e = a0.toArray();
|
|
30
|
+
this._origin = new Vec2(e[2], e[5]);
|
|
31
|
+
this._xAxis = new Vec2(e[0], e[3]);
|
|
32
|
+
this._yAxis = new Vec2(e[1], e[4]);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const origin = a0 ?? Vec2.zero();
|
|
36
|
+
const xAxis = a1 ?? Vec2.unitX();
|
|
37
|
+
const yAxis = a2 ?? xAxis.perped();
|
|
38
|
+
this._origin = origin;
|
|
39
|
+
this._xAxis = xAxis;
|
|
40
|
+
this._yAxis = yAxis;
|
|
41
|
+
}
|
|
42
|
+
/** 克隆 */
|
|
43
|
+
clone() {
|
|
44
|
+
return new Coord2D_1(this._origin, this._xAxis, this._yAxis);
|
|
45
|
+
}
|
|
46
|
+
/** 获取原点 */
|
|
47
|
+
getOrigin() {
|
|
48
|
+
return this._origin;
|
|
49
|
+
}
|
|
50
|
+
/** 获取 X 轴方向 */
|
|
51
|
+
getDx() {
|
|
52
|
+
return this._xAxis;
|
|
53
|
+
}
|
|
54
|
+
/** 获取 Y 轴方向 */
|
|
55
|
+
getDy() {
|
|
56
|
+
return this._yAxis;
|
|
57
|
+
}
|
|
58
|
+
/** 是否为可用基(不退化) */
|
|
59
|
+
isValid(eps = Precision.LEN_EPS) {
|
|
60
|
+
const det = this._xAxis.cross(this._yAxis);
|
|
61
|
+
return Math.abs(det) > eps;
|
|
62
|
+
}
|
|
63
|
+
/** 坐标系近似相等 */
|
|
64
|
+
equals(c, eps = Precision.EPS) {
|
|
65
|
+
return (this._origin.equals(c._origin, eps) &&
|
|
66
|
+
this._xAxis.equals(c._xAxis, eps) &&
|
|
67
|
+
this._yAxis.equals(c._yAxis, eps));
|
|
68
|
+
}
|
|
69
|
+
/** 局部坐标 -> 世界坐标 */
|
|
70
|
+
toWorld(p) {
|
|
71
|
+
return this._origin
|
|
72
|
+
.added(this._xAxis.scaled(p.x))
|
|
73
|
+
.added(this._yAxis.scaled(p.y));
|
|
74
|
+
}
|
|
75
|
+
/** 世界坐标 -> 局部坐标 */
|
|
76
|
+
toLocal(p, eps = Precision.LEN_EPS) {
|
|
77
|
+
const dx = p.x - this._origin.x;
|
|
78
|
+
const dy = p.y - this._origin.y;
|
|
79
|
+
const det = this._xAxis.cross(this._yAxis);
|
|
80
|
+
if (Math.abs(det) <= eps) {
|
|
81
|
+
MathError.throw('Coord2D.toLocal: basis is degenerate');
|
|
82
|
+
}
|
|
83
|
+
const invDet = 1 / det;
|
|
84
|
+
const x = (dx * this._yAxis.y - dy * this._yAxis.x) * invDet;
|
|
85
|
+
const y = (dy * this._xAxis.x - dx * this._xAxis.y) * invDet;
|
|
86
|
+
return new Vec2(x, y);
|
|
87
|
+
}
|
|
88
|
+
/** 转为变换矩阵(列向量 + 右乘约定) */
|
|
89
|
+
toMat3() {
|
|
90
|
+
return new Mat3(this._xAxis.x, this._yAxis.x, this._origin.x, this._xAxis.y, this._yAxis.y, this._origin.y, 0, 0, 1);
|
|
91
|
+
}
|
|
92
|
+
/** 变换坐标系(就地修改) */
|
|
93
|
+
transform(m) {
|
|
94
|
+
this._origin = this._origin.clone().applyMat3(m);
|
|
95
|
+
this._xAxis = m.transformedVector(this._xAxis);
|
|
96
|
+
this._yAxis = m.transformedVector(this._yAxis);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/** 变换坐标系(返回新对象) */
|
|
100
|
+
transformed(m) {
|
|
101
|
+
return this.clone().transform(m);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 逆坐标系(世界 <-> 局部)
|
|
105
|
+
* - 用于把世界坐标转换为该坐标系的局部坐标
|
|
106
|
+
*/
|
|
107
|
+
inverse(eps = Precision.LEN_EPS) {
|
|
108
|
+
const inv = this.toMat3().inverted(eps);
|
|
109
|
+
return new Coord2D_1(inv);
|
|
110
|
+
}
|
|
111
|
+
/** 设置原点(就地修改) */
|
|
112
|
+
setOrigin(origin) {
|
|
113
|
+
this._origin = origin;
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
/** 设置 X 轴(就地修改) */
|
|
117
|
+
setXAxis(xAxis) {
|
|
118
|
+
this._xAxis = xAxis;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/** 设置 Y 轴(就地修改) */
|
|
122
|
+
setYAxis(yAxis) {
|
|
123
|
+
this._yAxis = yAxis;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/** 获取缩放(轴长度) */
|
|
127
|
+
getScale() {
|
|
128
|
+
return new Vec2(this._xAxis.len(), this._yAxis.len());
|
|
129
|
+
}
|
|
130
|
+
/** 设置缩放(保持轴方向不变) */
|
|
131
|
+
setScale(sx, sy, eps = Precision.LEN_EPS) {
|
|
132
|
+
this._xAxis = this._xAxis.clone().setLength(sx, eps);
|
|
133
|
+
this._yAxis = this._yAxis.clone().setLength(sy, eps);
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/** 序列化为结构对象 */
|
|
137
|
+
dump() {
|
|
138
|
+
return {
|
|
139
|
+
type: Coord2D_1.type,
|
|
140
|
+
origin: { x: this._origin.x, y: this._origin.y },
|
|
141
|
+
xAxis: { x: this._xAxis.x, y: this._xAxis.y },
|
|
142
|
+
yAxis: { x: this._yAxis.x, y: this._yAxis.y },
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** 从结构对象反序列化 */
|
|
146
|
+
static load(data) {
|
|
147
|
+
return new Coord2D_1(new Vec2(data.origin.x, data.origin.y), new Vec2(data.xAxis.x, data.xAxis.y), new Vec2(data.yAxis.x, data.yAxis.y));
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/** 序列化类型标识 */
|
|
151
|
+
Coord2D.type = EN_GEO_TYPE.Coord2D;
|
|
152
|
+
Coord2D = Coord2D_1 = __decorate([
|
|
153
|
+
RegisterGeom
|
|
154
|
+
], Coord2D);
|
|
155
|
+
export { Coord2D };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IDB } from '../serialize/dump_types';
|
|
2
|
+
import type { IDumpable } from '../serialize/geom_mgr';
|
|
3
|
+
import type { Ctor } from '../types/type_guard';
|
|
4
|
+
export interface IGeom extends IDumpable {
|
|
5
|
+
getType(): string;
|
|
6
|
+
clone(): IGeom;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class GeomBase implements IGeom {
|
|
9
|
+
abstract dump(): IDB;
|
|
10
|
+
abstract clone(): IGeom;
|
|
11
|
+
/** 获取实例类型标识 */
|
|
12
|
+
getType(): string;
|
|
13
|
+
/**
|
|
14
|
+
* 运行时类型守卫:判断当前实例是否为目标构造器类型。
|
|
15
|
+
* 使用后可触发 TypeScript 类型收窄。
|
|
16
|
+
*/
|
|
17
|
+
isType<T extends GeomBase>(ctor: Ctor<T>): this is T;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=geom_base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geom_base.d.ts","sourceRoot":"","sources":["../../src/core/geom_base.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE/C,MAAM,WAAW,KAAM,SAAQ,SAAS;IACpC,OAAO,IAAI,MAAM,CAAA;IACjB,KAAK,IAAI,KAAK,CAAA;CACjB;AAED,8BAAsB,QAAS,YAAW,KAAK;aAC3B,IAAI,IAAI,GAAG;aACX,KAAK,IAAI,KAAK;IAE9B,eAAe;IACR,OAAO;IAKd;;;OAGG;IACI,MAAM,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC;CAG9D"}
|