summaryrefslogtreecommitdiffstats
path: root/src/renderer/runtime/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/runtime/math')
-rw-r--r--src/renderer/runtime/math/line.ts39
-rw-r--r--src/renderer/runtime/math/point.ts9
2 files changed, 14 insertions, 34 deletions
diff --git a/src/renderer/runtime/math/line.ts b/src/renderer/runtime/math/line.ts
index db99035..43bb6eb 100644
--- a/src/renderer/runtime/math/line.ts
+++ b/src/renderer/runtime/math/line.ts
@@ -1,10 +1,7 @@
import { mat2, vec2 } from 'gl-matrix';
import { Collidable } from './collision';
-const rot90 = mat2.fromValues(
- 0, 1,
- -1, 0,
-);
+const rot90 = mat2.fromValues(0, 1, -1, 0);
export function normal(out: vec2, a: vec2): vec2 {
return vec2.transformMat2(out, a, rot90);
@@ -15,10 +12,7 @@ export function crossz(a: vec2, b: vec2): number {
}
export class Line {
- constructor(
- public readonly p: vec2,
- public readonly v: vec2,
- ) {}
+ constructor(public readonly p: vec2, public readonly v: vec2) {}
public getNormal(out: vec2): vec2 {
return normal(out, this.v);
@@ -50,10 +44,7 @@ export class Line {
export class Movement {
public readonly v: vec2;
- constructor(
- public readonly src: vec2,
- public readonly dest: vec2,
- ) {
+ constructor(public readonly src: vec2, public readonly dest: vec2) {
this.v = vec2.sub(vec2.create(), dest, src);
}
@@ -71,6 +62,7 @@ export class Movement {
}
public toLineSegment(): LineSegment {
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
return LineSegment.fromPoints(this.src, this.dest);
}
@@ -90,11 +82,7 @@ export class LineSegment extends Line implements Collidable {
return new LineSegment(p1, v, d);
}
- constructor(
- p: vec2,
- v: vec2,
- public readonly l: number,
- ) {
+ constructor(p: vec2, v: vec2, public readonly l: number) {
super(p, v);
}
@@ -104,35 +92,30 @@ export class LineSegment extends Line implements Collidable {
public containsPoint(p2: vec2): boolean {
const d = this.projectPointDistance(p2);
- return (d >= 0 && d <= this.l);
+ return d >= 0 && d <= this.l;
}
public collide(out: vec2, move: Movement, r: number): boolean {
- if (this.distancePoint(move.src) < 0)
- return false;
+ if (this.distancePoint(move.src) < 0) return false;
- if (crossz(move.v, this.v) < 0)
- return false;
+ if (crossz(move.v, this.v) < 0) return false;
const t = this.getNormal(vec2.create());
vec2.scale(t, t, -r);
const refMove = move.translate(t);
- if (!this.collideRef(out, refMove))
- return false;
+ if (!this.collideRef(out, refMove)) return false;
vec2.sub(out, out, t);
return true;
}
private collideRef(out: vec2, move: Movement): boolean {
- if (this.distancePoint(move.dest) >= 0)
- return false;
+ if (this.distancePoint(move.dest) >= 0) return false;
const x = move.intersectLine(vec2.create(), this);
- if (!this.containsPoint(x))
- return false;
+ if (!this.containsPoint(x)) return false;
this.projectPoint(out, move.dest);
diff --git a/src/renderer/runtime/math/point.ts b/src/renderer/runtime/math/point.ts
index 0865b8f..a00cb0c 100644
--- a/src/renderer/runtime/math/point.ts
+++ b/src/renderer/runtime/math/point.ts
@@ -9,12 +9,10 @@ export class Point implements Collidable {
public collide(out: vec2, move: Movement, r: number): boolean {
const moveLine = move.toLineSegment();
- if (moveLine.projectPointDistance(this.p) < 0)
- return false;
+ if (moveLine.projectPointDistance(this.p) < 0) return false;
const d = moveLine.distancePoint(this.p) / r;
- if (Math.abs(d) >= 1)
- return false;
+ if (Math.abs(d) >= 1) return false;
const e = Math.sqrt(1 - d * d);
@@ -26,8 +24,7 @@ export class Point implements Collidable {
const refMove = move.translate(tr);
- if (vec2.sqrDist(this.p, move.src) > r * r && !refMove.passes(this.p))
- return false;
+ if (vec2.sqrDist(this.p, move.src) > r * r && !refMove.passes(this.p)) return false;
normal(t, t);