diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/math/line.ts | 24 | ||||
-rw-r--r-- | src/math/point.ts | 4 |
2 files changed, 14 insertions, 14 deletions
diff --git a/src/math/line.ts b/src/math/line.ts index 2e38f81..db99035 100644 --- a/src/math/line.ts +++ b/src/math/line.ts @@ -51,33 +51,33 @@ export class Movement { public readonly v: vec2; constructor( - public readonly p1: vec2, - public readonly p2: vec2, + public readonly src: vec2, + public readonly dest: vec2, ) { - this.v = vec2.sub(vec2.create(), p2, p1); + this.v = vec2.sub(vec2.create(), dest, src); } public intersectLine(out: vec2, l: Line): vec2 { - const vp = vec2.sub(vec2.create(), l.p, this.p1); + const vp = vec2.sub(vec2.create(), l.p, this.src); const d = crossz(vp, this.v); const d2 = d / crossz(this.v, l.v); return vec2.scaleAndAdd(out, l.p, l.v, d2); } public passes(p: vec2): boolean { - const vp = vec2.sub(vec2.create(), p, this.p1); + const vp = vec2.sub(vec2.create(), p, this.src); const d = vec2.dot(this.v, vp); return d >= 0 && d <= vec2.sqrLen(this.v); } public toLineSegment(): LineSegment { - return LineSegment.fromPoints(this.p1, this.p2); + return LineSegment.fromPoints(this.src, this.dest); } public translate(t: vec2): Movement { - const p1 = vec2.add(vec2.create(), this.p1, t); - const p2 = vec2.add(vec2.create(), this.p2, t); - return new Movement(p1, p2); + const src = vec2.add(vec2.create(), this.src, t); + const dest = vec2.add(vec2.create(), this.dest, t); + return new Movement(src, dest); } } @@ -108,7 +108,7 @@ export class LineSegment extends Line implements Collidable { } public collide(out: vec2, move: Movement, r: number): boolean { - if (this.distancePoint(move.p1) < 0) + if (this.distancePoint(move.src) < 0) return false; if (crossz(move.v, this.v) < 0) @@ -127,14 +127,14 @@ export class LineSegment extends Line implements Collidable { } private collideRef(out: vec2, move: Movement): boolean { - if (this.distancePoint(move.p2) >= 0) + if (this.distancePoint(move.dest) >= 0) return false; const x = move.intersectLine(vec2.create(), this); if (!this.containsPoint(x)) return false; - this.projectPoint(out, move.p2); + this.projectPoint(out, move.dest); return true; } diff --git a/src/math/point.ts b/src/math/point.ts index 23a0f84..0865b8f 100644 --- a/src/math/point.ts +++ b/src/math/point.ts @@ -26,13 +26,13 @@ export class Point implements Collidable { const refMove = move.translate(tr); - if (vec2.sqrDist(this.p, move.p1) > r * r && !refMove.passes(this.p)) + if (vec2.sqrDist(this.p, move.src) > r * r && !refMove.passes(this.p)) return false; normal(t, t); const tang = new Line(this.p, t); - tang.projectPoint(out, refMove.p2); + tang.projectPoint(out, refMove.dest); vec2.sub(out, out, tr); return true; |