-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(geom-resample): add sampleUniformX/Y() fns
- update deps (add thi.ng/geom-isec) - update pkg
- Loading branch information
1 parent
5b2adf3
commit 88f9ec5
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { intersectRayPolyline } from "@thi.ng/geom-isec/ray-poly"; | ||
import type { ReadonlyVec } from "@thi.ng/vectors"; | ||
|
||
/** | ||
* Samples 2D polyline at uniform step distance in `[x1..x2]` interval along | ||
* X-axis. Returns array of sampled points. | ||
* | ||
* @remarks | ||
* The polyline is assumed to fully cover the given X interval, no gaps are | ||
* allowed (or checked for). Sampling is done via ray-line intersection with the | ||
* ray cast into Y+ direction, starting at given `startY`. | ||
* | ||
* Also see {@link sampleUniformY}. | ||
* | ||
* @example | ||
* ```ts | ||
* sampleUniformX([[0, 0], [3, 5], [5, 2]], 0, 5) | ||
* // [ | ||
* // [ 0, 0 ], | ||
* // [ 1, 1.666... ], | ||
* // [ 2, 3.333... ], | ||
* // [ 3, 5 ], | ||
* // [ 4, 3.5 ], | ||
* // [ 5, 2 ] | ||
* // ] | ||
* ``` | ||
* | ||
* @param pts | ||
* @param x1 | ||
* @param x2 | ||
* @param step | ||
* @param startY | ||
*/ | ||
export const sampleUniformX = ( | ||
pts: ReadonlyVec[], | ||
x1: number, | ||
x2: number, | ||
step = 1, | ||
startY = -1 | ||
) => { | ||
const res: ReadonlyVec[] = []; | ||
for (let x = x1; x <= x2; x += step) { | ||
res.push( | ||
<ReadonlyVec>( | ||
intersectRayPolyline([x, startY], [0, 1], pts, false).isec! | ||
) | ||
); | ||
} | ||
return res; | ||
}; | ||
|
||
/** | ||
* Similar to {@link sampleUniformX}, but samples 2D polyline at uniform step | ||
* distance in `[y1..y2]` interval along Y-axis. Returns array of sampled | ||
* points. | ||
* | ||
* @param pts | ||
* @param y1 | ||
* @param y2 | ||
* @param step | ||
* @param startX | ||
*/ | ||
export const sampleUniformY = ( | ||
pts: ReadonlyVec[], | ||
y1: number, | ||
y2: number, | ||
step = 1, | ||
startX = -1 | ||
) => { | ||
const res: ReadonlyVec[] = []; | ||
for (let y = y1; y <= y2; y += step) { | ||
res.push( | ||
<ReadonlyVec>( | ||
intersectRayPolyline([startX, y], [1, 0], pts, false).isec! | ||
) | ||
); | ||
} | ||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./axis.js"; | ||
export * from "./resample.js"; | ||
export * from "./sampler.js"; | ||
export * from "./simplify.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters