Skip to content

Commit

Permalink
feat(geom): update warpPoints() args, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 28, 2022
1 parent 620121d commit 50cb467
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/geom/src/warp-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@ import { mapPoint } from "./map-point.js";
import { rectFromMinMax } from "./rect.js";
import { unmapPoint } from "./unmap-point.js";

export const warpPoints = (pts: ReadonlyVec[], dest: IShape, src: IShape) => {
const res: Vec[] = [];
/**
* Transfers/remaps points (in world space) given in relation to `src` shape to
* be relative to the space of `dest` shape. Writes results to `out` (or creates
* new array).
*
* @remarks
* The type of `src` must be supported by {@link mapPoint}. The type of `dest`
* must be supported by {@link unmapPoint}.
*
* @param pts
* @param dest
* @param src
* @param out
*/
export const warpPoints = (
pts: ReadonlyVec[],
dest: IShape,
src: IShape,
out: Vec[] = []
) => {
for (let n = pts.length, i = 0; i < n; i++) {
res.push(unmapPoint(dest, mapPoint(src, pts[i])));
out.push(unmapPoint(dest, mapPoint(src, pts[i])));
}
return res;
return out;
};

export const warpPointsBPatch = (
Expand Down

0 comments on commit 50cb467

Please sign in to comment.