math: rename Movement.{p1,p2} to {src,dest}

This commit is contained in:
Matthias Schiffer 2018-11-08 21:39:05 +01:00
parent c87d044687
commit 40339947d1
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 14 additions and 14 deletions

View file

@ -51,33 +51,33 @@ export class Movement {
public readonly v: vec2; public readonly v: vec2;
constructor( constructor(
public readonly p1: vec2, public readonly src: vec2,
public readonly p2: 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 { 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 d = crossz(vp, this.v);
const d2 = d / crossz(this.v, l.v); const d2 = d / crossz(this.v, l.v);
return vec2.scaleAndAdd(out, l.p, l.v, d2); return vec2.scaleAndAdd(out, l.p, l.v, d2);
} }
public passes(p: vec2): boolean { 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); const d = vec2.dot(this.v, vp);
return d >= 0 && d <= vec2.sqrLen(this.v); return d >= 0 && d <= vec2.sqrLen(this.v);
} }
public toLineSegment(): LineSegment { public toLineSegment(): LineSegment {
return LineSegment.fromPoints(this.p1, this.p2); return LineSegment.fromPoints(this.src, this.dest);
} }
public translate(t: vec2): Movement { public translate(t: vec2): Movement {
const p1 = vec2.add(vec2.create(), this.p1, t); const src = vec2.add(vec2.create(), this.src, t);
const p2 = vec2.add(vec2.create(), this.p2, t); const dest = vec2.add(vec2.create(), this.dest, t);
return new Movement(p1, p2); 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 { public collide(out: vec2, move: Movement, r: number): boolean {
if (this.distancePoint(move.p1) < 0) if (this.distancePoint(move.src) < 0)
return false; return false;
if (crossz(move.v, this.v) < 0) 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 { private collideRef(out: vec2, move: Movement): boolean {
if (this.distancePoint(move.p2) >= 0) if (this.distancePoint(move.dest) >= 0)
return false; return false;
const x = move.intersectLine(vec2.create(), this); const x = move.intersectLine(vec2.create(), this);
if (!this.containsPoint(x)) if (!this.containsPoint(x))
return false; return false;
this.projectPoint(out, move.p2); this.projectPoint(out, move.dest);
return true; return true;
} }

View file

@ -26,13 +26,13 @@ export class Point implements Collidable {
const refMove = move.translate(tr); 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; return false;
normal(t, t); normal(t, t);
const tang = new Line(this.p, t); const tang = new Line(this.p, t);
tang.projectPoint(out, refMove.p2); tang.projectPoint(out, refMove.dest);
vec2.sub(out, out, tr); vec2.sub(out, out, tr);
return true; return true;