Skip to content

Commit

Permalink
Use distanceTo where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
yzrmn committed Aug 23, 2024
1 parent 4de8a5f commit 2e2a6c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions packages/redgeometry/src/internal/bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ export function getArcLengthConic(c: BezierRCurve2): number {
}

export function getParameterAtArcLengthQuadratic(c: Bezier2Curve2, d: number): number {
const d1 = c.p1.sub(c.p0).len();
const d2 = c.p2.sub(c.p1).len();
const d1 = c.p1.distanceTo(c.p0);
const d2 = c.p2.distanceTo(c.p1);

const r = solveQuadratic(d2 - d1, d1, -d);

Expand All @@ -231,9 +231,9 @@ export function getParameterAtArcLengthQuadratic(c: Bezier2Curve2, d: number): n
}

export function getParameterAtArcLengthCubic(c: Bezier3Curve2, d: number): number {
const d1 = c.p1.sub(c.p0).len();
const d2 = c.p2.sub(c.p1).len();
const d3 = c.p2.sub(c.p1).len();
const d1 = c.p1.distanceTo(c.p0);
const d2 = c.p2.distanceTo(c.p1);
const d3 = c.p2.distanceTo(c.p1);

const r = solveCubic(d3 - 2 * d2 + d1, d2 - d1, d1, -d);

Expand All @@ -245,8 +245,8 @@ export function getParameterAtArcLengthCubic(c: Bezier3Curve2, d: number): numbe
}

export function getParameterAtArcLengthConic(c: BezierRCurve2, d: number): number {
const d1 = c.p1.sub(c.p0).len();
const d2 = c.p2.sub(c.p1).len();
const d1 = c.p1.distanceTo(c.p0);
const d2 = c.p2.distanceTo(c.p1);
const dw = c.w * d1;

const r = solveQuadratic(d2 - 2 * dw - d1, dw, -d);
Expand Down
2 changes: 1 addition & 1 deletion packages/redgeometry/src/internal/path-dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function getDashStart(dashArray: number[], dashOffset: number): [number,
}

export function getDashArcLengthLinear(c: Bezier1Curve2): number {
return c.p1.sub(c.p0).len();
return c.p1.distanceTo(c.p0);
}

export function getDashParameterLinear(c: Bezier1Curve2, length: number): number {
Expand Down
4 changes: 2 additions & 2 deletions packages/redgeometry/src/primitives/bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,8 @@ export class BezierRCurve2 {

public static fromCenterPoint(p0: Point2, p1: Point2, p2: Point2, pc: Point2): BezierRCurve2 {
const pm = p0.lerp(p2, 0.5);
const dm = pm.sub(pc).len();
const d1 = p1.sub(pc).len();
const dm = pm.distanceTo(pc);
const d1 = p1.distanceTo(pc);
const w = Math.sqrt(dm / d1);
return new BezierRCurve2(p0, p1, p2, w);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/redgeometry/src/primitives/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Edge2 {
const p0 = e1.getValueAt(t);
const p1 = e2.getValueAt(u);

return p0.sub(p1).len();
return p0.distanceTo(p1);
}

public static getClosestParameter(e1: Edge2, e2: Edge2): [number, number] {
Expand Down Expand Up @@ -299,7 +299,7 @@ export class Edge2 {
}

public getClosestPointDistance(p: Point2): number {
return this.getClosestPoint(p).sub(p).len();
return this.getClosestPoint(p).distanceTo(p);
}

/**
Expand Down Expand Up @@ -453,7 +453,7 @@ export class Edge3 {
}

public getClosestPointDistance(p: Point3): number {
return this.getClosestPoint(p).sub(p).len();
return this.getClosestPoint(p).distanceTo(p);
}

/**
Expand Down

0 comments on commit 2e2a6c5

Please sign in to comment.