summaryrefslogtreecommitdiffstats
path: root/src/math/line.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/line.ts')
-rw-r--r--src/math/line.ts24
1 files changed, 12 insertions, 12 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;
}