Skip to content

Commit

Permalink
Do more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yzrmn committed Aug 25, 2024
1 parent 3271bee commit 6116af7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/redgeometry-app/src/utility/straight-skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class KineticVertex {
}

public getPositionAt(t: number): Point2 {
return this.orig.addMulV(this.vel, t - this.t0);
return this.orig.addVMulS(this.vel, t - this.t0);
}
}

Expand Down
20 changes: 10 additions & 10 deletions packages/redgeometry/src/internal/path-offset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function insertOuterJoin(

switch (join) {
case JoinType.Bevel: {
path.lineTo(p.addMulV(n1, d));
path.lineTo(p.addVMulS(n1, d));

break;
}
Expand All @@ -83,7 +83,7 @@ export function insertOuterJoin(
path.lineTo(p.addV(k));
}

path.lineTo(p.addMulV(n1, d));
path.lineTo(p.addVMulS(n1, d));

break;
}
Expand All @@ -92,16 +92,16 @@ export function insertOuterJoin(

k = k.mulS(2 * d).divS(k.lenSq());

const pp0 = p.addMulV(n0, d);
const pp2 = p.addMulV(n1, d);
const pp0 = p.addVMulS(n0, d);
const pp2 = p.addVMulS(n1, d);

if (k.lenSq() <= mld * mld) {
// Same as miter join
path.lineTo(p.addV(k));
} else if (n0.dot(n1) <= COS_ACUTE) {
// Join is too sharp ('k' is approaching infinity)
path.lineTo(pp0.addMulV(n0.normal(), -mld));
path.lineTo(pp2.addMulV(n1.normal(), mld));
path.lineTo(pp0.addVMulS(n0.normal(), -mld));
path.lineTo(pp2.addVMulS(n1.normal(), mld));
} else {
const kov = k.dot(p.sub(pp0));
const kok = k.dot(k);
Expand All @@ -122,8 +122,8 @@ export function insertOuterJoin(
break;
}
case JoinType.Round: {
const pp0 = p.addMulV(n0, d);
const pp2 = p.addMulV(n1, d);
const pp0 = p.addVMulS(n0, d);
const pp2 = p.addVMulS(n1, d);

if (n0.dot(n1) < 0) {
// Obtuse angle (2 segments)
Expand All @@ -134,7 +134,7 @@ export function insertOuterJoin(
k = k.mulS(2 * d).divS(k.lenSq());

const pc1 = p.addV(k);
const pp1 = p.addMulV(nm, d);
const pp1 = p.addVMulS(nm, d);
const pc2 = pc1.lerp(pp1, 2);

const w = BezierRCurve2.getWeightFromVectors(p, pc1, pp1);
Expand Down Expand Up @@ -167,5 +167,5 @@ export function insertInnerJoin(path: Path2, p: Point2, n1: Vector2, d: number):
path.lineTo(p);

// Bevel join
path.lineTo(p.addMulV(n1, d));
path.lineTo(p.addVMulS(n1, d));
}
8 changes: 4 additions & 4 deletions packages/redgeometry/src/primitives/bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class Bezier2Curve2 {
const v = pp.normal();
const f = pp.lenSq() / pp.cross(ppp);

return p.addMulV(v, f);
return p.addVMulS(v, f);
}

public getOffsetCuspParameter(rad: number): [number, number] {
Expand Down Expand Up @@ -712,15 +712,15 @@ export class Bezier3Curve2 {
const p = qa.mulS(t).add(qb).mulS(t).add(qc).mulS(t).addP(qd);
const pp = qa
.mulS(3 * t)
.addMul(qb, 2)
.addMulS(qb, 2)
.mulS(t)
.add(qc);
const ppp = qa.mulS(6 * t).addMul(qb, 2);
const ppp = qa.mulS(6 * t).addMulS(qb, 2);

const v = pp.normal();
const f = pp.lenSq() / pp.cross(ppp);

return p.addMulV(v, f);
return p.addVMulS(v, f);
}

public getInflectionParameter(): [number, number] {
Expand Down
29 changes: 12 additions & 17 deletions packages/redgeometry/src/primitives/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,17 @@ export class Point2 implements Point2Like {
}

/**
* Returns the sum of the current point and a vector `v` scaled by `f`.
* Returns the sum of the current point and a vector `v`.
*/
public addMulV(v: Vector2, f: number): Point2 {
const x = this.x + f * v.x;
const y = this.y + f * v.y;
return new Point2(x, y);
public addV(v: Vector2): Point2 {
return new Point2(this.x + v.x, this.y + v.y);
}

/**
* Returns the sum of the current point and a vector `v`.
* Returns the sum of the current point and a vector `v` multiplied by a scalar `s`.
*/
public addV(v: Vector2): Point2 {
return new Point2(this.x + v.x, this.y + v.y);
public addVMulS(v: Vector2, s: number): Point2 {
return new Point2(this.x + s * v.x, this.y + s * v.y);
}

public clone(): Point2 {
Expand Down Expand Up @@ -218,20 +216,17 @@ export class Point3 implements Point3Like {
}

/**
* Returns the sum of the current point and a vector `v` scaled by `f`.
* Returns the sum of the current point and a vector `v`.
*/
public addMulV(v: Vector3, f: number): Point3 {
const x = this.x + f * v.x;
const y = this.y + f * v.y;
const z = this.z + f * v.z;
return new Point3(x, y, z);
public addV(v: Vector3): Point3 {
return new Point3(this.x + v.x, this.y + v.y, this.z + v.z);
}

/**
* Returns the sum of the current point and a vector `v`.
* Returns the sum of the current point and a vector `v` multiplied by a scalar `s`.
*/
public addV(v: Vector3): Point3 {
return new Point3(this.x + v.x, this.y + v.y, this.z + v.z);
public addVMulS(v: Vector3, s: number): Point3 {
return new Point3(this.x + s * v.x, this.y + s * v.y, this.z + s * v.z);
}

public clone(): Point3 {
Expand Down
4 changes: 2 additions & 2 deletions packages/redgeometry/src/primitives/ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class Ray2 {
* Returns the parameterized point on the ray along its direction.
*/
public getValueAt(t: number): Point2 {
return this.p.addMulV(this.v, t);
return this.p.addVMulS(this.v, t);
}

public normal(): Ray2 {
Expand Down Expand Up @@ -196,7 +196,7 @@ export class Ray3 {
* Returns the parameterized point on the ray along its direction.
*/
public getValueAt(t: number): Point3 {
return this.p.addMulV(this.v, t);
return this.p.addVMulS(this.v, t);
}

public isFinite(): boolean {
Expand Down
35 changes: 13 additions & 22 deletions packages/redgeometry/src/primitives/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,17 @@ export class Vector2 implements Vector2Like {
}

/**
* Returns the sum of the current vector and a vector `v` scaled by `f`.
* Returns the sum of the current vector and a vector `v` multiplied by a scalar `s`.
*/
public addMul(v: Vector2, f: number): Vector2 {
const x = this.x + f * v.x;
const y = this.y + f * v.y;
return new Vector2(x, y);
public addMulS(v: Vector2, s: number): Vector2 {
return new Vector2(this.x + s * v.x, this.y + s * v.y);
}

/**
* Adds the current vector to a point `p`.
*/
public addP(p: Point2): Point2 {
return new Point2(p.x + this.x, p.y + this.y);
return p.addV(this);
}

/**
Expand Down Expand Up @@ -244,7 +242,7 @@ export class Vector2 implements Vector2Like {
* Substracts the current vector from a point `p`.
*/
public subP(p: Point2): Point2 {
return new Point2(p.x - this.x, p.y - this.y);
return p.subV(this);
}

public toArray(): [number, number] {
Expand Down Expand Up @@ -350,20 +348,17 @@ export class Vector3 implements Vector3Like {
}

/**
* Returns the sum of the current vector and a vector `v` scaled by `f`.
* Returns the sum of the current vector and a vector `v` multiplied by a scalar `s`.
*/
public addMul(v: Vector3, f: number): Vector3 {
const x = this.x + f * v.x;
const y = this.y + f * v.y;
const z = this.z + f * v.z;
return new Vector3(x, y, z);
public addMulS(v: Vector3, s: number): Vector3 {
return new Vector3(this.x + s * v.x, this.y + s * v.y, this.z + s * v.z);
}

/**
* Adds the current vector to a point `p`.
*/
public addP(p: Point3): Point3 {
return new Point3(p.x + this.x, p.y + this.y, p.z + this.z);
return p.addV(this);
}

/**
Expand Down Expand Up @@ -548,7 +543,7 @@ export class Vector3 implements Vector3Like {
* Substracts the current vector from a point `p`.
*/
public subP(p: Point3): Point3 {
return new Point3(p.x - this.x, p.y - this.y, p.z - this.z);
return p.subV(this);
}

public toArray(): [number, number, number] {
Expand Down Expand Up @@ -656,14 +651,10 @@ export class Vector4 implements Vector4Like {
}

/**
* Returns the sum of the current vector and a vector `v` scaled by `f`.
* Returns the sum of the current vector and a vector `v` multiplied by a scalar `s`.
*/
public addMul(v: Vector4, f: number): Vector4 {
const x = this.x + f * v.x;
const y = this.y + f * v.y;
const z = this.z + f * v.z;
const w = this.w + f * v.w;
return new Vector4(x, y, z, w);
public addMulS(v: Vector4, s: number): Vector4 {
return new Vector4(this.x + s * v.x, this.y + s * v.y, this.z + s * v.z, this.w + s * v.w);
}

public clamp(vmin: Vector4, vmax: Vector4): Vector4 {
Expand Down

0 comments on commit 6116af7

Please sign in to comment.