diff --git a/packages/redgeometry/src/core/mesh.ts b/packages/redgeometry/src/core/mesh.ts index c00172e..8df7be5 100644 --- a/packages/redgeometry/src/core/mesh.ts +++ b/packages/redgeometry/src/core/mesh.ts @@ -1255,7 +1255,7 @@ export class Mesh2 { } } - if (p1.lt(p2)) { + if (p1.x !== p2.x ? p1.x < p2.x : p1.y < p2.y) { // log.infoDebug("{} -> Regular (Interior Above)", p1); this.monotoneDelete(status, e0, e1); this.monotoneInsert(status, e1); diff --git a/packages/redgeometry/src/core/snapround.ts b/packages/redgeometry/src/core/snapround.ts index 7472293..6d6bc71 100644 --- a/packages/redgeometry/src/core/snapround.ts +++ b/packages/redgeometry/src/core/snapround.ts @@ -347,18 +347,20 @@ export class SnapRound2 { for (let i = 0; i < segments.length; i++) { const s = segments[i]; + const p0 = s.p0; + const p1 = s.p1; - if (s.p0.eq(s.p1)) { + if (p0.eq(p1)) { // Ignore empty edges continue; } - if (s.p0.lt(s.p1)) { - events.push(new SnapRoundSweepEvent2(s.p0, s.p1, s, i, true)); - events.push(new SnapRoundSweepEvent2(s.p1, s.p0, s, i, false)); + if (p0.x !== p1.x ? p0.x < p1.x : p0.y < p1.y) { + events.push(new SnapRoundSweepEvent2(p0, p1, s, i, true)); + events.push(new SnapRoundSweepEvent2(p1, p0, s, i, false)); } else { - events.push(new SnapRoundSweepEvent2(s.p1, s.p0, s, i, true)); - events.push(new SnapRoundSweepEvent2(s.p0, s.p1, s, i, false)); + events.push(new SnapRoundSweepEvent2(p1, p0, s, i, true)); + events.push(new SnapRoundSweepEvent2(p0, p1, s, i, false)); } } diff --git a/packages/redgeometry/src/internal/path-sweep.ts b/packages/redgeometry/src/internal/path-sweep.ts index 47ae238..4bce7eb 100644 --- a/packages/redgeometry/src/internal/path-sweep.ts +++ b/packages/redgeometry/src/internal/path-sweep.ts @@ -89,16 +89,16 @@ export function createSweepEventQueue(snapRound: SnapRound2): PathSweepEvent2[] for (const seg of edgeSegments) { // Fetch points, weight becomes winding + const wind = seg.ref.weight; const p0 = seg.p0; const p1 = seg.p1; - const wind = seg.ref.weight; if (p0.eq(p1)) { // Ignore empty edges continue; } - if (p0.lt(p1)) { + if (p0.x !== p1.x ? p0.x < p1.x : p0.y < p1.y) { queue.push(new PathSweepEvent2(p0, p1, seg, wind, true)); queue.push(new PathSweepEvent2(p1, p0, seg, wind, false)); } else { diff --git a/packages/redgeometry/src/primitives/point.ts b/packages/redgeometry/src/primitives/point.ts index 3c9ac6c..b834148 100644 --- a/packages/redgeometry/src/primitives/point.ts +++ b/packages/redgeometry/src/primitives/point.ts @@ -123,14 +123,6 @@ export class Point2 implements Point2Like { return eqApproxRel(this.x, p.x, eps) && eqApproxRel(this.y, p.y, eps); } - public gt(p: Point2): boolean { - return this.x === p.x ? this.y > p.y : this.x > p.x; - } - - public gte(p: Point2): boolean { - return this.x === p.x ? this.y >= p.y : this.x > p.x; - } - public isFinite(): boolean { return Number.isFinite(this.x) && Number.isFinite(this.y); } @@ -145,14 +137,6 @@ export class Point2 implements Point2Like { return new Point2(x, y); } - public lt(p: Point2): boolean { - return this.x === p.x ? this.y < p.y : this.x < p.x; - } - - public lte(p: Point2): boolean { - return this.x === p.x ? this.y <= p.y : this.x < p.x; - } - public sub(p: Point2): Vector2 { return new Vector2(this.x - p.x, this.y - p.y); } diff --git a/packages/redgeometry/src/primitives/vector.ts b/packages/redgeometry/src/primitives/vector.ts index 171282e..b86ded8 100644 --- a/packages/redgeometry/src/primitives/vector.ts +++ b/packages/redgeometry/src/primitives/vector.ts @@ -13,10 +13,10 @@ export interface Vector3Like { } export interface Vector4Like { - w: number; x: number; y: number; z: number; + w: number; } export class Vector2 implements Vector2Like { @@ -157,9 +157,9 @@ export class Vector2 implements Vector2Like { } /** - * Returns the cross product of the current vector and `v` as a scalar value. + * Returns the 2D cross product of the current vector and `v` as a scalar value. * - * The 2D cross product is defined by z-value of the 3D cross product: \ + * The 2D cross product is defined by the magnitude of the 3D cross product: \ * `(x1, y1, 0) cross (x2, y2, 0) == (0, 0, x1 * y2 - y1 * x2)` * * Identity relating to the dot product: `v1 cross v2 === v1 dot normal(v2)` @@ -295,7 +295,12 @@ export class Vector2 implements Vector2Like { public unitOrZero(): Vector2 { const len = this.len(); - return len > 0 ? this.divS(len) : Vector2.createZero(); + + if (len === 0) { + return Vector2.createZero(); + } + + return this.divS(len); } } @@ -628,15 +633,20 @@ export class Vector3 implements Vector3Like { public unitOrZero(): Vector3 { const len = this.len(); - return len > 0 ? this.divS(len) : Vector3.createZero(); + + if (len === 0) { + return Vector3.createZero(); + } + + return this.divS(len); } } export class Vector4 implements Vector4Like { - public w: number; public x: number; public y: number; public z: number; + public w: number; public constructor(x: number, y: number, z: number, w: number) { this.x = x;