@thi.ng/geom-trace-bitmap 0.1.10 → 0.2.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/CHANGELOG.md +8 -1
- package/extract.d.ts +26 -0
- package/extract.js +61 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-03-
|
|
3
|
+
- **Last updated**: 2023-03-25T17:04:52Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-trace-bitmap@0.2.0) (2023-03-25)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add pointcloud line extractions ([d65a9ae](https://github.com/thi-ng/umbrella/commit/d65a9ae))
|
|
17
|
+
- add extractSegmentsX/Y() functions
|
|
18
|
+
|
|
12
19
|
## [0.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom-trace-bitmap@0.1.0) (2022-12-29)
|
|
13
20
|
|
|
14
21
|
#### 🚀 Features
|
package/extract.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReadonlyVec, VecPair } from "@thi.ng/vectors";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts horizontal line segments (along X-axis) from given point cloud
|
|
4
|
+
* (assuming all points are aligned to a grid, e.g. pixel coords).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The given point array will be sorted (in-place!). Line segments will be as
|
|
8
|
+
* long as possible, depending on chosen `maxDist`, which defines max distance
|
|
9
|
+
* between consecutive points. If a point is further away than `maxDist` units
|
|
10
|
+
* from the previous point (or at a new X coord), the current line segment (if
|
|
11
|
+
* any) will be terminated and the new point is potentially becoming the start
|
|
12
|
+
* of the next segment.
|
|
13
|
+
*
|
|
14
|
+
* @param pts
|
|
15
|
+
* @param maxDist
|
|
16
|
+
*/
|
|
17
|
+
export declare const extractSegmentsX: (pts: ReadonlyVec[], maxD?: number) => VecPair[];
|
|
18
|
+
/**
|
|
19
|
+
* Similar to {@link extractSegmentsX}, but for extracting vertical line
|
|
20
|
+
* segments (along Y-axis).
|
|
21
|
+
*
|
|
22
|
+
* @param pts
|
|
23
|
+
* @param maxDist
|
|
24
|
+
*/
|
|
25
|
+
export declare const extractSegmentsY: (pts: ReadonlyVec[], maxDist?: number) => VecPair[];
|
|
26
|
+
//# sourceMappingURL=extract.d.ts.map
|
package/extract.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { comparator2 } from "@thi.ng/vectors/compare";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts horizontal line segments (along X-axis) from given point cloud
|
|
4
|
+
* (assuming all points are aligned to a grid, e.g. pixel coords).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The given point array will be sorted (in-place!). Line segments will be as
|
|
8
|
+
* long as possible, depending on chosen `maxDist`, which defines max distance
|
|
9
|
+
* between consecutive points. If a point is further away than `maxDist` units
|
|
10
|
+
* from the previous point (or at a new X coord), the current line segment (if
|
|
11
|
+
* any) will be terminated and the new point is potentially becoming the start
|
|
12
|
+
* of the next segment.
|
|
13
|
+
*
|
|
14
|
+
* @param pts
|
|
15
|
+
* @param maxDist
|
|
16
|
+
*/
|
|
17
|
+
export const extractSegmentsX = (pts, maxD = 5) => __extract(pts, maxD, 1);
|
|
18
|
+
/**
|
|
19
|
+
* Similar to {@link extractSegmentsX}, but for extracting vertical line
|
|
20
|
+
* segments (along Y-axis).
|
|
21
|
+
*
|
|
22
|
+
* @param pts
|
|
23
|
+
* @param maxDist
|
|
24
|
+
*/
|
|
25
|
+
export const extractSegmentsY = (pts, maxDist = 5) => __extract(pts, maxDist, 0);
|
|
26
|
+
/**
|
|
27
|
+
* Common implementation for both axis orders.
|
|
28
|
+
*
|
|
29
|
+
* @param pts
|
|
30
|
+
* @param maxD
|
|
31
|
+
* @param order
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
const __extract = (pts, maxD, order) => {
|
|
36
|
+
const $ = order ? (p) => [p[1], p[0]] : (p) => p;
|
|
37
|
+
pts = pts.sort(comparator2(order, order ^ 1));
|
|
38
|
+
const segments = [];
|
|
39
|
+
let [outer, inner] = $(pts[0]);
|
|
40
|
+
let last = 0;
|
|
41
|
+
for (let i = 1, n = pts.length - 1; i <= n; i++) {
|
|
42
|
+
const p = $(pts[i]);
|
|
43
|
+
if (p[0] === outer) {
|
|
44
|
+
if (i === n || p[1] - inner > maxD) {
|
|
45
|
+
if (i - last > 1) {
|
|
46
|
+
segments.push([pts[last], pts[i - 1]]);
|
|
47
|
+
}
|
|
48
|
+
last = i;
|
|
49
|
+
}
|
|
50
|
+
inner = p[1];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (i - last > 1) {
|
|
54
|
+
segments.push([pts[last], pts[i - 1]]);
|
|
55
|
+
}
|
|
56
|
+
last = i;
|
|
57
|
+
[outer, inner] = p;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return segments;
|
|
61
|
+
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom-trace-bitmap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Bitmap image to hairline vector and point cloud conversions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@thi.ng/api": "^8.7.4",
|
|
38
38
|
"@thi.ng/errors": "^2.2.13",
|
|
39
|
-
"@thi.ng/grid-iterators": "^3.0
|
|
40
|
-
"@thi.ng/matrices": "^2.1.
|
|
41
|
-
"@thi.ng/pixel": "^4.1.
|
|
42
|
-
"@thi.ng/vectors": "^7.6.
|
|
39
|
+
"@thi.ng/grid-iterators": "^3.1.0",
|
|
40
|
+
"@thi.ng/matrices": "^2.1.50",
|
|
41
|
+
"@thi.ng/pixel": "^4.1.10",
|
|
42
|
+
"@thi.ng/vectors": "^7.6.9"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@microsoft/api-extractor": "^7.34.4",
|
|
@@ -84,6 +84,9 @@
|
|
|
84
84
|
"./border": {
|
|
85
85
|
"default": "./border.js"
|
|
86
86
|
},
|
|
87
|
+
"./extract": {
|
|
88
|
+
"default": "./extract.js"
|
|
89
|
+
},
|
|
87
90
|
"./trace": {
|
|
88
91
|
"default": "./trace.js"
|
|
89
92
|
}
|
|
@@ -97,5 +100,5 @@
|
|
|
97
100
|
"status": "alpha",
|
|
98
101
|
"year": 2022
|
|
99
102
|
},
|
|
100
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "f5c562f74466d36a6df27ddd6957eeb280831fa9\n"
|
|
101
104
|
}
|