@xort/cga 0.1.1 → 0.1.3
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/THIRD_PARTY_NOTICES.md +24 -45
- package/build/@xort_cga.js +2077 -9118
- package/build/cga.d.ts +109 -42
- package/build/cga.esm.js +2077 -9119
- package/dist/THIRD_PARTY_NOTICES.md +24 -45
- package/dist/index.cjs +2077 -9118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -42
- package/dist/index.d.ts +109 -42
- package/dist/index.js +2077 -9119
- package/dist/index.js.map +1 -1
- package/dist/three.cjs +211 -1963
- package/dist/three.cjs.map +1 -1
- package/dist/three.d.cts +77 -9
- package/dist/three.d.ts +77 -9
- package/dist/three.js +211 -1963
- package/dist/three.js.map +1 -1
- package/package.json +122 -118
- package/readme.md +189 -61
package/package.json
CHANGED
|
@@ -1,123 +1,127 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"cga",
|
|
34
|
-
"cgajs",
|
|
35
|
-
"cga.js",
|
|
36
|
-
"计算几何库",
|
|
37
|
-
"webgl",
|
|
38
|
-
"threejs",
|
|
39
|
-
"compute geometry algorithm",
|
|
40
|
-
"MIT",
|
|
41
|
-
"开源",
|
|
42
|
-
"gis"
|
|
43
|
-
],
|
|
44
|
-
"license": "MIT",
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"decimal.js": "^10.6.0",
|
|
47
|
-
"earcut": "^3.0.2",
|
|
48
|
-
"geographiclib-geodesic": "2.2.0"
|
|
49
|
-
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@types/earcut": "^3.0.0",
|
|
52
|
-
"@types/node": "^24.10.0",
|
|
53
|
-
"@types/three": "0.187.0",
|
|
54
|
-
"playwright": "1.65.2",
|
|
55
|
-
"prettier": "3.10.1",
|
|
56
|
-
"rollup": "4.69.2",
|
|
57
|
-
"rollup-plugin-dts": "6.5.1",
|
|
58
|
-
"three": "0.187.0",
|
|
59
|
-
"typescript": "6.0.3",
|
|
60
|
-
"vite": "8.4.1",
|
|
61
|
-
"vitepress": "2.0.0-alpha.21",
|
|
62
|
-
"vue": "3.5.46"
|
|
63
|
-
},
|
|
64
|
-
"module": "./dist/index.js",
|
|
65
|
-
"unpkg": "./build/@xort_cga.js",
|
|
66
|
-
"files": [
|
|
67
|
-
"dist",
|
|
68
|
-
"build",
|
|
69
|
-
"readme.md",
|
|
70
|
-
"LICENSE",
|
|
71
|
-
"THIRD_PARTY_NOTICES.md"
|
|
72
|
-
],
|
|
73
|
-
"engines": {
|
|
74
|
-
"node": ">=22.12"
|
|
75
|
-
},
|
|
76
|
-
"type": "module",
|
|
77
|
-
"exports": {
|
|
78
|
-
".": {
|
|
79
|
-
"import": {
|
|
80
|
-
"types": "./dist/index.d.ts",
|
|
81
|
-
"default": "./dist/index.js"
|
|
82
|
-
},
|
|
83
|
-
"require": {
|
|
84
|
-
"types": "./dist/index.d.cts",
|
|
85
|
-
"default": "./dist/index.cjs"
|
|
86
|
-
}
|
|
2
|
+
"name": "@xort/cga",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Computational geometry algorithms for JavaScript and TypeScript",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node scripts/build.mjs",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"test": "npm run build && node --test",
|
|
11
|
+
"test:coverage": "npm run build && node --experimental-test-coverage --test",
|
|
12
|
+
"dev": "vite --host 127.0.0.1",
|
|
13
|
+
"build:demo": "vite build",
|
|
14
|
+
"docs:dev": "vitepress dev docs",
|
|
15
|
+
"docs:build": "vitepress build docs && node scripts/docs-manifest.mjs",
|
|
16
|
+
"docs:preview": "vitepress preview docs",
|
|
17
|
+
"format": "node scripts/format.mjs --write",
|
|
18
|
+
"format:check": "node scripts/format.mjs",
|
|
19
|
+
"prepublishOnly": "npm run release:check -- --complete && npm run verify",
|
|
20
|
+
"release:check": "node scripts/release-check.mjs",
|
|
21
|
+
"verify": "npm run release:check && npm run source:check && npm run algorithms:check && npm run typecheck && npm run docs:typecheck && npm run format:check && npm test && npm run readme:check && npm run demos:check && npm run api:check && npm run media:check && npm run docs:build && npm run build:demo && npm run browser:check && npm audit && npm pack --dry-run && npm run package:check",
|
|
22
|
+
"source:check": "node scripts/source-check.mjs",
|
|
23
|
+
"browser:check": "node scripts/browser-check.mjs",
|
|
24
|
+
"package:check": "node scripts/package-check.mjs",
|
|
25
|
+
"docs:typecheck": "vue-tsc --noEmit -p docs/tsconfig.json",
|
|
26
|
+
"demos:check": "node scripts/demo-coverage.mjs",
|
|
27
|
+
"docs:deploy": "node scripts/deploy-docs.mjs",
|
|
28
|
+
"docs:screenshots": "npm run docs:build && node scripts/capture-demos.mjs && npm run docs:build",
|
|
29
|
+
"media:check": "node scripts/media-check.mjs",
|
|
30
|
+
"api:check": "node scripts/api-methods.mjs",
|
|
31
|
+
"readme:check": "node scripts/readme-check.mjs",
|
|
32
|
+
"algorithms:check": "node scripts/algorithm-check.mjs"
|
|
87
33
|
},
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
"
|
|
92
|
-
"default": "./dist/three.js"
|
|
93
|
-
},
|
|
94
|
-
"require": {
|
|
95
|
-
"types": "./dist/three.d.cts",
|
|
96
|
-
"default": "./dist/three.cjs"
|
|
97
|
-
}
|
|
34
|
+
"private": false,
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/yszhao91/cga.js.git"
|
|
98
38
|
},
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
39
|
+
"author": "Zhao YS",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"cga",
|
|
42
|
+
"cgajs",
|
|
43
|
+
"cga.js",
|
|
44
|
+
"计算几何库",
|
|
45
|
+
"webgl",
|
|
46
|
+
"threejs",
|
|
47
|
+
"compute geometry algorithm",
|
|
48
|
+
"MIT",
|
|
49
|
+
"开源",
|
|
50
|
+
"gis"
|
|
51
|
+
],
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "26.6.11",
|
|
55
|
+
"@types/three": "0.187.0",
|
|
56
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
57
|
+
"playwright": "1.65.2",
|
|
58
|
+
"prettier": "3.10.1",
|
|
59
|
+
"rollup": "4.69.3",
|
|
60
|
+
"rollup-plugin-dts": "6.5.1",
|
|
61
|
+
"three": "0.187.0",
|
|
62
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
63
|
+
"vite": "8.4.1",
|
|
64
|
+
"vitepress": "2.0.0-alpha.21",
|
|
65
|
+
"vue": "3.5.46",
|
|
66
|
+
"vue-tsc": "3.3.14"
|
|
67
|
+
},
|
|
68
|
+
"module": "./dist/index.js",
|
|
69
|
+
"unpkg": "./build/@xort_cga.js",
|
|
70
|
+
"files": [
|
|
71
|
+
"dist",
|
|
72
|
+
"build",
|
|
73
|
+
"readme.md",
|
|
74
|
+
"LICENSE",
|
|
75
|
+
"THIRD_PARTY_NOTICES.md"
|
|
76
|
+
],
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=22.12"
|
|
79
|
+
},
|
|
80
|
+
"type": "module",
|
|
81
|
+
"exports": {
|
|
82
|
+
".": {
|
|
83
|
+
"import": {
|
|
84
|
+
"types": "./dist/index.d.ts",
|
|
85
|
+
"default": "./dist/index.js"
|
|
86
|
+
},
|
|
87
|
+
"require": {
|
|
88
|
+
"types": "./dist/index.d.cts",
|
|
89
|
+
"default": "./dist/index.cjs"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"./package.json": "./package.json",
|
|
93
|
+
"./three": {
|
|
94
|
+
"import": {
|
|
95
|
+
"types": "./dist/three.d.ts",
|
|
96
|
+
"default": "./dist/three.js"
|
|
97
|
+
},
|
|
98
|
+
"require": {
|
|
99
|
+
"types": "./dist/three.d.cts",
|
|
100
|
+
"default": "./dist/three.cjs"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"./shaders": {
|
|
104
|
+
"import": {
|
|
105
|
+
"types": "./dist/shaders.d.ts",
|
|
106
|
+
"default": "./dist/shaders.js"
|
|
107
|
+
},
|
|
108
|
+
"require": {
|
|
109
|
+
"types": "./dist/shaders.d.cts",
|
|
110
|
+
"default": "./dist/shaders.cjs"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"sideEffects": false,
|
|
115
|
+
"publishConfig": {
|
|
116
|
+
"access": "public",
|
|
117
|
+
"registry": "https://registry.npmjs.org/"
|
|
118
|
+
},
|
|
119
|
+
"peerDependencies": {
|
|
120
|
+
"three": "^0.187.0"
|
|
121
|
+
},
|
|
122
|
+
"peerDependenciesMeta": {
|
|
123
|
+
"three": {
|
|
124
|
+
"optional": true
|
|
125
|
+
}
|
|
121
126
|
}
|
|
122
|
-
}
|
|
123
127
|
}
|
package/readme.md
CHANGED
|
@@ -1,111 +1,239 @@
|
|
|
1
1
|
# cga.js
|
|
2
2
|
|
|
3
|
-
JavaScript / TypeScript
|
|
3
|
+
**JavaScript / TypeScript 计算几何库。** 用统一数据结构计算距离、最近点、相交、多边形布尔、剖分、点云和路径网格,并提供高精度 CSG、IK、GIS 与可选 Three.js / GLSL 适配。
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[](https://www.npmjs.com/package/@xort/cga) [](https://github.com/yszhao91/cga.js/actions/workflows/ci.yml) [](LICENSE)
|
|
6
|
+
|
|
7
|
+
[快速开始](#安装与快速开始) · [在线演示](https://yszhao91.github.io/cga.js/guide/playground.html) · [真实图册](https://yszhao91.github.io/cga.js/guide/gallery.html) · [API](https://yszhao91.github.io/cga.js/guide/api.html) · [复审与路线图](docs/guide/review-0.1.3.md) · [贡献](CONTRIBUTING.md)
|
|
6
8
|
|
|
7
9
|
<!-- release-status:start -->
|
|
8
|
-
|
|
10
|
+
本轮发行版本 **0.1.3**:全部计算算法使用内部 TypeScript、核心零运行时依赖;丰富 README、真实截图和演示;修复方端盖、微小尺度剖分与非法轮廓校验。npm latest、发布标签和线上部署的实际状态见[发布记录](https://yszhao91.github.io/cga.js/release-status.html)。版本按发布递增,提交和授权重试不重复升版。
|
|
9
11
|
<!-- release-status:end -->
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## 看看实际效果
|
|
14
|
+
|
|
15
|
+
图片由当前项目在真实浏览器中计算并截取。点击可操作对应场景;图册还保留带控件、图例和计算结果的完整截图。
|
|
16
|
+
|
|
17
|
+
| 几何距离与最近点 | 凹多边形和多个孔洞 |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| [](https://yszhao91.github.io/cga.js/guide/playground.html#geometry-distance?a=Capsule&b=Triangle&ax=0.5&ay=3&az=1) | [](https://yszhao91.github.io/cga.js/guide/playground.html#triangulation-multiple-holes) |
|
|
20
|
+
| **带孔截面与路径扫掠** | **高精度实体布尔** |
|
|
21
|
+
| [](https://yszhao91.github.io/cga.js/guide/playground.html#extrude-holes-closed?width=0.65) | [](https://yszhao91.github.io/cga.js/guide/playground.html#csg-subtract?x=0.5) |
|
|
22
|
+
| **带约束的逆运动学** | **GIS 球面瓦片** |
|
|
23
|
+
| [](https://yszhao91.github.io/cga.js/guide/playground.html#ik-hinge?x=1.5&y=2) | [](https://yszhao91.github.io/cga.js/guide/playground.html#gis-globe?level=2) |
|
|
24
|
+
|
|
25
|
+
**94 个可操作案例 · 184 个公开入口映射 · 15 类几何体的 225 种有序组合。** 这些数字描述案例和入口覆盖,公有方法的逐项演示另见[方法级清单](docs/guide/method-coverage.md),数值正确性由解析、随机和退化测试验证。
|
|
26
|
+
|
|
27
|
+
[查看全部 14 组真实预览](https://yszhao91.github.io/cga.js/guide/gallery.html) · [带参数的案例目录](docs/guide/demo-coverage.md) · [截图复现方法](#开发与验证)
|
|
28
|
+
|
|
29
|
+
## 安装与快速开始
|
|
12
30
|
|
|
13
31
|
```sh
|
|
14
32
|
npm install @xort/cga
|
|
15
33
|
```
|
|
16
34
|
|
|
17
|
-
|
|
18
|
-
|
|
35
|
+
### 距离、最近点和参数
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
// example:distance
|
|
39
|
+
import { v3, segment, distance, intersects } from '@xort/cga';
|
|
19
40
|
|
|
20
41
|
const point = v3(1, 2, 0);
|
|
21
|
-
const
|
|
22
|
-
const result = distance(point,
|
|
23
|
-
|
|
24
|
-
console.log(result.
|
|
25
|
-
console.log(result.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(
|
|
30
|
-
console.log(intersects(segment, arc)); // true
|
|
42
|
+
const edge = segment(v3(0, 0, 0), v3(4, 0, 0));
|
|
43
|
+
const result = distance(point, edge);
|
|
44
|
+
|
|
45
|
+
console.log(result.distance); // 2
|
|
46
|
+
console.log(result.distanceSqr); // 4
|
|
47
|
+
console.log(result.closests.map(p => p.toArray())); // [[1, 2, 0], [1, 0, 0]]
|
|
48
|
+
console.log(result.parameters); // [0, 0.25]
|
|
49
|
+
console.log(intersects(point, edge)); // false
|
|
50
|
+
console.log(point.queryDistance(edge).distance); // 2
|
|
31
51
|
```
|
|
32
52
|
|
|
33
|
-
|
|
53
|
+
`distance(a, b)`、`a.queryDistance(b)` 返回相同结果契约。`Vec3.distanceTo(otherPoint)` 则返回点间距离数字。
|
|
34
54
|
|
|
35
|
-
|
|
55
|
+
### CommonJS
|
|
36
56
|
|
|
37
|
-
|
|
57
|
+
```js
|
|
58
|
+
// example:commonjs
|
|
59
|
+
const { v3, segment, distance } = require('@xort/cga');
|
|
60
|
+
const result = distance(v3(1, 2, 0), segment(v3(), v3(4, 0, 0)));
|
|
61
|
+
console.log(result.distance); // 2
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 克隆和序列化
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
// example:serialization
|
|
68
|
+
import { Triangle, geometryFromJSON, v3 } from '@xort/cga';
|
|
69
|
+
|
|
70
|
+
const original = new Triangle(v3(), v3(2, 0, 0), v3(0, 2, 0));
|
|
71
|
+
const clone = original.clone();
|
|
72
|
+
const restored = geometryFromJSON(JSON.parse(JSON.stringify(original)));
|
|
73
|
+
original[0].x = 3;
|
|
74
|
+
console.log(clone[0].x, restored[0].x); // 0, 0:坐标相互独立
|
|
75
|
+
```
|
|
38
76
|
|
|
39
|
-
|
|
40
|
-
- `distance / distanceSqr / closests / parameters` 是必填字段;最近点和参数始终按操作数 `[a, b]` 排列。
|
|
41
|
-
- 构造器与克隆拥有坐标;查询不修改输入。固定顶点几何体支持索引和迭代,顶点数量不可被数组操作改变。
|
|
42
|
-
- `geometryFromJSON` 校验并恢复统一数据;`Shape` 的孔洞一起序列化。
|
|
77
|
+
### 自有 TypeScript 多边形内核
|
|
43
78
|
|
|
44
|
-
|
|
79
|
+
```js
|
|
80
|
+
// example:polygon
|
|
81
|
+
import { v3, triangulation, clipPolygons } from '@xort/cga';
|
|
45
82
|
|
|
46
|
-
|
|
83
|
+
const outer = [v3(-2,-2,0), v3(2,-2,0), v3(2,2,0), v3(-2,2,0)];
|
|
84
|
+
const hole = [v3(-.5,-.5,0), v3(.5,-.5,0), v3(.5,.5,0), v3(-.5,.5,0)];
|
|
85
|
+
const vertices = [...outer, ...hole];
|
|
86
|
+
const indices = triangulation(outer, [hole]);
|
|
87
|
+
console.log(vertices.length, indices.length / 3); // 8 顶点、8 三角形
|
|
47
88
|
|
|
48
|
-
|
|
89
|
+
const contours = clipPolygons([outer], [hole], 'difference', v3(0,0,1));
|
|
90
|
+
console.log(contours.length); // 2:外边界和孔洞,绕序相反
|
|
91
|
+
```
|
|
49
92
|
|
|
50
|
-
|
|
93
|
+
剖分、裁剪、偏移、清理均由本项目维护的 TypeScript 内核实现。输入限制、精度和复杂度见[多边形内核说明](docs/guide/polygon-kernels.md)。
|
|
94
|
+
|
|
95
|
+
## 算法与示例导航
|
|
96
|
+
|
|
97
|
+
| 范围 | 可操作示例 | 关键能力 |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| 几何查询 | [距离与求交](https://yszhao91.github.io/cga.js/guide/playground.html#geometry-distance) | 最近点、参数、双向查询、容差相交 |
|
|
100
|
+
| 圆弧与圆盘 | [有向圆弧](https://yszhao91.github.io/cga.js/guide/playground.html#circle-arc) | 弧段范围、端点限制、迭代误差界 |
|
|
101
|
+
| 平面布尔 | [拓扑变化](https://yszhao91.github.io/cga.js/guide/playground.html#polygon-topology) | 交/并/差/异或、多轮廓、孔洞、共边 |
|
|
102
|
+
| 偏移与描边 | [斜线端盖](https://yszhao91.github.io/cga.js/guide/playground.html#offset-open-caps) | 尖/圆/方连接,平/圆/方端盖 |
|
|
103
|
+
| 三角剖分 | [多孔凹轮廓](https://yszhao91.github.io/cga.js/guide/playground.html#triangulation-multiple-holes) | 3D 平面投影、原始顶点索引、多个孔洞 |
|
|
104
|
+
| Delaunay / Voronoi | [三角网](https://yszhao91.github.io/cga.js/guide/playground.html#delaunay-delaunay) · [单元和邻居](https://yszhao91.github.io/cga.js/guide/playground.html#voronoi) | 平面剖分、裁剪单元、站点与邻接 |
|
|
105
|
+
| 点云 | [三维凸包](https://yszhao91.github.io/cga.js/guide/playground.html#hull-degeneracy) · [最近点对](https://yszhao91.github.io/cga.js/guide/playground.html#closest-pair) | 共面/共线退化、三维 hull、最近点对 |
|
|
106
|
+
| 曲线与路径 | [Catmull–Rom](https://yszhao91.github.io/cga.js/guide/playground.html#curve-catmull) · [里程采样](https://yszhao91.github.io/cga.js/guide/playground.html#path-mileage) | 参数化、累计长度、切片与重采样 |
|
|
107
|
+
| 挤压与网格 | [带孔扫掠](https://yszhao91.github.io/cga.js/guide/playground.html#extrude-holes-closed) | 平行移动标架、连接、封口、UV 与法线 |
|
|
108
|
+
| 平面切割 | [体积守恒](https://yszhao91.github.io/cga.js/guide/playground.html#mesh-split-volume) | 分侧网格、属性插值、多轮廓封口 |
|
|
109
|
+
| 空间结构 | [KdTree](https://yszhao91.github.io/cga.js/guide/playground.html#tree-kdtree) · [QuadTree](https://yszhao91.github.io/cga.js/guide/playground.html#tree-quadtree) · [Frustum](https://yszhao91.github.io/cga.js/guide/playground.html#frustum) | 最近邻、范围、空间划分、剔除与裁剪 |
|
|
110
|
+
| 高精度与 CSG | [精度投影](https://yszhao91.github.io/cga.js/guide/playground.html#precision-projection) · [实体差集](https://yszhao91.github.io/cga.js/guide/playground.html#csg-subtract) | Decimal 向量、平面、BSP 并/交/差 |
|
|
111
|
+
| IK | [自由 CCD](https://yszhao91.github.io/cga.js/guide/playground.html#ik-free) · [铰链](https://yszhao91.github.io/cga.js/guide/playground.html#ik-hinge) · [滑块](https://yszhao91.github.io/cga.js/guide/playground.html#ik-slider) | 目标求解、累计限位、收敛与骨长 |
|
|
112
|
+
| GIS | [坐标转换](https://yszhao91.github.io/cga.js/guide/playground.html#gis-coordinates) · [测地线](https://yszhao91.github.io/cga.js/guide/playground.html#gis-geodesic) · [地形](https://yszhao91.github.io/cga.js/guide/playground.html#gis-heightmap) | ECEF/WGS84、瓦片、影像、地形和任务 |
|
|
113
|
+
| 渲染与 GLSL | [查看器](https://yszhao91.github.io/cga.js/guide/playground.html#glview) · [噪声](https://yszhao91.github.io/cga.js/guide/playground.html#shader-classicnoise3d) | 可选 Three.js、材质、噪声和距离场 |
|
|
114
|
+
|
|
115
|
+
## 统一数据结构与接口
|
|
116
|
+
|
|
117
|
+
15 类几何体:`Point / Vec3`、`Line`、`Ray`、`Segment`、`Plane`、`Triangle`、`Rectangle`、`Circle`、`Disk`、`Sphere`、`Capsule`、`Box`、`Polyline`、`Polygon`、`Shape`。
|
|
118
|
+
|
|
119
|
+
- 查询共有 `kind`、`copy`、`clone`、`distancePoint`、`queryDistance` 和 `toJSON`;`geometryFromJSON` 校验并恢复数据。
|
|
120
|
+
- 距离结果必含 `distance / distanceSqr / closests / parameters`。最近点和参数始终按 `[a, b]` 排列;迭代圆类查询可报告 `errorBound`。
|
|
121
|
+
- 构造和克隆拥有独立坐标;查询保留输入。固定顶点对象支持索引与迭代,顶点数量固定。
|
|
122
|
+
- 网格统一使用 `IGeometry`:`position:number[]`,可选 `index / normal / uv / uv2 / tangent`。索引相对于该次返回的顶点数组。
|
|
123
|
+
- `Shape` 在外轮廓之外保留孔洞,并统一参与查询、剖分和序列化。
|
|
124
|
+
|
|
125
|
+
### 使用时需要明确的约定
|
|
126
|
+
|
|
127
|
+
| 项目 | 约定 |
|
|
51
128
|
| --- | --- |
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## 领域模块
|
|
67
|
-
|
|
68
|
-
```ts
|
|
129
|
+
| 直线 | `Line(origin, end)` 的第二项是另一个点 |
|
|
130
|
+
| 射线 | `Ray(origin, direction)` 的第二项是方向 |
|
|
131
|
+
| 线段 | 参数区间为 `[0, 1]` |
|
|
132
|
+
| 平面 | `normal · point + w = 0`;数值有符号距离单独定义 |
|
|
133
|
+
| 圆圈 / 圆盘 | `Circle` 表示圆周或有向圆弧;`Disk` 表示填充面 |
|
|
134
|
+
| 多边形 | 填充面;自交轮廓先整理,剖分孔洞须互不接触 |
|
|
135
|
+
| 单位 | 核心几何使用调用者的模型单位;GIS 经纬度内部为弧度,高度为米 |
|
|
136
|
+
| 资源所有权 | 查看器与效果显式释放;宿主模型的几何和材质由宿主管理 |
|
|
137
|
+
|
|
138
|
+
## 高精度、IK 与 GIS
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
// example:domains
|
|
69
142
|
import { HVec3, IK, GIS, v3 } from '@xort/cga';
|
|
70
143
|
|
|
71
|
-
|
|
144
|
+
const precise = new HVec3('0.1', '0.2', '0.3').add(new HVec3('0.2', 0, 0));
|
|
145
|
+
console.log(precise.x.toString()); // 0.3:用字符串保留十进制输入
|
|
72
146
|
|
|
73
|
-
const
|
|
74
|
-
const solved = new IK.CCDSolver().solve(
|
|
147
|
+
const skeleton = IK.Skeleton.fromPoints([v3(), v3(1,0,0), v3(2,0,0)]);
|
|
148
|
+
const solved = new IK.CCDSolver().solve(skeleton, v3(1,1,0));
|
|
75
149
|
console.log(solved.converged, solved.distance);
|
|
76
150
|
|
|
77
|
-
const
|
|
78
|
-
console.log(
|
|
151
|
+
const ecef = GIS.GVec3.fromDegrees(116.4, 39.9, 50);
|
|
152
|
+
console.log(ecef.toCartographic()); // 经度/纬度为弧度,高度为米
|
|
79
153
|
```
|
|
80
154
|
|
|
155
|
+
CSG 使用凸多边形面组成的闭合定向实体。GIS 的 `Globe` 提供瓦片和网格数据层,宿主负责渲染;`pick` 查询参考椭球,`getHeight` 读取已加载地形。影像和地形服务通过 fetch / 解码器接入,演示中明确使用本地注入数据。详见[领域模块指南](docs/guide/experimental.md)。
|
|
156
|
+
|
|
157
|
+
## 浏览器与可选 Three.js
|
|
158
|
+
|
|
159
|
+
核心计算无需 DOM、Three.js 或 GPU。按需安装渲染依赖:
|
|
160
|
+
|
|
81
161
|
```sh
|
|
82
162
|
npm install three
|
|
83
163
|
```
|
|
84
164
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
165
|
+
在 Vite 等支持包导入的浏览器工程中,先提供有高度的容器:
|
|
166
|
+
|
|
167
|
+
```html
|
|
168
|
+
<div id="view" style="height:420px;width:100%"></div>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
// example:browser
|
|
173
|
+
import { GLView, BreathLight } from '@xort/cga/three';
|
|
174
|
+
|
|
175
|
+
const view = new GLView({ container: document.querySelector('#view') });
|
|
89
176
|
const light = new BreathLight();
|
|
90
177
|
view.add(light);
|
|
91
178
|
view.addUpdates(time => light.update(time));
|
|
92
179
|
view.run();
|
|
93
|
-
|
|
180
|
+
|
|
181
|
+
// 在组件卸载或页面销毁时调用;自有模型资源也应按所有权释放。
|
|
182
|
+
const dispose = () => { light.dispose(); view.dispose(); };
|
|
183
|
+
window.addEventListener('pagehide', dispose, { once: true });
|
|
94
184
|
```
|
|
95
185
|
|
|
96
|
-
|
|
186
|
+
另有 `@xort/cga/shaders` 文本入口、`ThreeBSP` 和 `DiamondShader`。不使用打包器时可选择 `build/@xort_cga.js` 的全局 `cga`,或 `build/cga.esm.js` 的 ESM;这两个核心文件不包含 Three.js 查看器。
|
|
97
187
|
|
|
98
|
-
##
|
|
188
|
+
## 内部算法与依赖边界
|
|
99
189
|
|
|
100
|
-
|
|
190
|
+
几何、剖分、布尔、CSG、IK、GIS 测地线和高精度运算均在仓库内实现为 TypeScript,核心包 **零运行时依赖**。十进制采用内部 BigInt 内核;椭球测地线采用内部 Karney 移植,保留对跖点能力与 MIT 来源声明。开发工具不进入核心发行包,Three.js 是可选的显示适配器,GPU 着色器使用 GLSL。
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// example:decimal
|
|
194
|
+
import { Decimal, HVec3 } from '@xort/cga';
|
|
195
|
+
const previous = { precision: Decimal.precision, rounding: Decimal.rounding };
|
|
196
|
+
try {
|
|
197
|
+
Decimal.set({ precision: 50, rounding: Decimal.ROUND_HALF_EVEN });
|
|
198
|
+
console.log(new Decimal(2).sqrt().toString());
|
|
199
|
+
console.log(new HVec3('0.1').add(new HVec3('0.2')).toJSON());
|
|
200
|
+
} finally { Decimal.set(previous); }
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
内部 Decimal 提供向量/CSG 所需算术、比较、开方和格式化;不宣称完整兼容 decimal.js 的三角函数、clone 或配置接口。构造时保留输入数字,运算按 1–1000 位有效数字舍入,默认 20 位;非有限值和超范围指数会报错。[实现、来源与迁移](docs/guide/internal-algorithms.md)。
|
|
204
|
+
|
|
205
|
+
## 能力边界与剩余工作
|
|
206
|
+
|
|
207
|
+
- 浮点查询按容差计算,迭代预算耗尽会明确报错;距离为 0 的实体交叠查询不提供通用接触流形或穿透深度。
|
|
208
|
+
- 带孔剖分采用可见桥和耳切法,最坏 O(n³)。多边形布尔的边交点阶段 O(E²),分类还需扫描原始边,适用于中小型轮廓。
|
|
209
|
+
- 平面布尔默认量化步长约为 `1e-6` 模型单位,可调整 `scale`;小于量化精度的特征可能合并。高精度向量不会自动把普通浮点布尔变为精确谓词算法。
|
|
210
|
+
- 圆角和圆端盖使用离散圆弧。对超大轮廓、极端长宽比和近重合边的性能与误差,还需要专门的基准与更强的数值谓词。
|
|
211
|
+
- 入口示例已覆盖,**方法级的独立演示仍需继续补充**,优先矩阵法线/投影、几何变换和缓冲属性;[方法清单](docs/guide/method-coverage.md)明确区分独立示例和共享查询。
|
|
212
|
+
- 约束 Delaunay、BVH、大型数据增量更新、更多曲线/曲面、GIS 瓦片协议扩展属于后续能力,见[复审与路线图](docs/guide/review-0.1.3.md)。
|
|
213
|
+
|
|
214
|
+
## 开发与验证
|
|
215
|
+
|
|
216
|
+
最低 Node.js **22.12**,建议使用 `.nvmrc` 指定的 **Node.js 26**。CI 同时验证 Linux / Windows 和 Node 22 / 24 / 26。
|
|
101
217
|
|
|
102
218
|
```sh
|
|
103
|
-
npm
|
|
219
|
+
npm ci
|
|
220
|
+
npx playwright install chromium # Windows 也可使用已安装的 Edge
|
|
221
|
+
npm run docs:dev # 本地文档与演示
|
|
222
|
+
npm run verify # 完整验证
|
|
223
|
+
npm run algorithms:check # 内部 TS、零运行时依赖、算法导入边界
|
|
224
|
+
npm run docs:screenshots # 从真实浏览器重新生成 14 组、28 张截图
|
|
225
|
+
npm run media:check # 截图哈希、尺寸、案例和源代码指纹
|
|
226
|
+
npm run api:check # 方法级示例登记
|
|
227
|
+
npm run readme:check # 执行 README 中的 Node.js 示例
|
|
104
228
|
npm run release:check -- --complete
|
|
105
229
|
```
|
|
106
230
|
|
|
107
|
-
|
|
231
|
+
源码目录与模块关系见[架构说明](docs/guide/architecture.md),截图参数和哈希保存在 `.release/screenshots.json`。新增公开入口须增加可操作案例;新功能与边界修复须提供相应的解析或独立参考验证。
|
|
232
|
+
|
|
233
|
+
每轮发布先规划版本并同步文档,再实现与验收,最后提交、推送、部署和发布 npm。版本末位每次加 1,满 100 进位:`0.1.99 → 0.2.0`、`0.99.99 → 1.0.0`。同一轮提交和授权重试保持相同版本。
|
|
234
|
+
|
|
235
|
+
[0.1.3 迁移](docs/guide/migration-0.1.3.md) · [缺口清单](docs/guide/gaps.md) · [贡献约定](CONTRIBUTING.md) · [发布记录](docs/release-status.md)
|
|
108
236
|
|
|
109
|
-
|
|
237
|
+
## 许可证
|
|
110
238
|
|
|
111
|
-
MIT License
|
|
239
|
+
MIT License。第三方组件与着色器声明见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|