Skip to content

Commit

Permalink
refactor(geom-resample): update destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 14, 2020
1 parent 5a4ad57 commit e0dd721
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/geom-resample/src/sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ export class Sampler {
}

closestT(p: ReadonlyVec) {
const pts = this.points;
const idx = this.index;
const { index, points } = this;
const tmp: Vec = [];
const closest: Vec = [];
let minD = Infinity;
let minI = -1;
for (let i = 0, n = idx.length - 1; i < n; i++) {
if (closestPointSegment(p, pts[i], pts[i + 1], tmp)) {
for (let i = 0, n = index.length - 1; i < n; i++) {
if (closestPointSegment(p, points[i], points[i + 1], tmp)) {
const d = distSq(p, tmp);
if (d < minD) {
minD = d;
Expand All @@ -85,9 +84,9 @@ export class Sampler {
}
return minI >= 0
? fit01(
closestT(p, pts[minI], pts[minI + 1]) || 0,
idx[minI],
idx[minI + 1]
closestT(p, points[minI], points[minI + 1]) || 0,
index[minI],
index[minI + 1]
) / this.totalLength()
: undefined;
}
Expand Down Expand Up @@ -151,8 +150,7 @@ export class Sampler {
}

sampleUniform(dist: number, includeLast = false, result: Vec[] = []) {
const index = this.index;
const pts = this.points;
const { index, points } = this;
const total = this.totalLength();
const delta = dist / total;
const n = index.length;
Expand All @@ -164,11 +162,11 @@ export class Sampler {
if (i >= n) break;
const p = index[i - 1];
result.push(
mixN([], pts[i - 1], pts[i], (ct - p) / (index[i] - p))
mixN([], points[i - 1], points[i], (ct - p) / (index[i] - p))
);
}
if (includeLast) {
result.push(set([], pts[pts.length - 1]));
result.push(set([], points[points.length - 1]));
}
return result;
}
Expand Down

0 comments on commit e0dd721

Please sign in to comment.