Add input handling
This commit is contained in:
parent
29c6b14440
commit
d5be727040
36 changed files with 417 additions and 113 deletions
7
frontend/src/scripts/math/line.ts
Normal file
7
frontend/src/scripts/math/line.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { Vec2 } from './vec2';
|
||||
|
||||
export interface Line {
|
||||
a: Vec2;
|
||||
b: Vec2;
|
||||
normal: Vec2;
|
||||
}
|
||||
27
frontend/src/scripts/math/vec2.ts
Normal file
27
frontend/src/scripts/math/vec2.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { Typed } from '../transport/serializable';
|
||||
|
||||
export class Vec2 extends Typed {
|
||||
public constructor(public x: number = 0.0, public y: number = null) {
|
||||
super();
|
||||
|
||||
if (this.y === null) {
|
||||
this.y = this.x;
|
||||
}
|
||||
}
|
||||
|
||||
public scale(scalar: number): Vec2 {
|
||||
return new Vec2(this.x * scalar, this.y * scalar);
|
||||
}
|
||||
|
||||
public add(other: Vec2): Vec2 {
|
||||
return new Vec2(this.x + other.x, this.y + other.y);
|
||||
}
|
||||
|
||||
public subtract(other: Vec2): Vec2 {
|
||||
return new Vec2(this.x - other.x, this.y - other.y);
|
||||
}
|
||||
|
||||
public get list(): [number, number] {
|
||||
return [this.x, this.y];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue