-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.ts
54 lines (46 loc) · 938 Bytes
/
graphics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
export class Point2D {
x: number;
y: number;
constructor(x: number, y: number) {
this.x = x
this.y = y
}
static distance(p1: Point2D, p2: Point2D): number {
let d = Math.sqrt((p2.x - p1.x)**2 + (p2.y - p1.y)**2)
return d
}
}
export class Point3D {
x: number;
y: number;
z: number;
constructor(x: number, y: number, z: number) {
this.x = x
this.y = y
this.z = z
}
}
export class Rect {
pos: Point2D;
w: number;
h: number;
constructor(x = 0, y = 0, w = 0, h = 0) {
this.pos = new Point2D(x, y)
this.w = w
this.h = h
}
contains(point: Point2D): boolean {
return (
point.x >= this.pos.x &&
point.y >= this.pos.y &&
point.x <= this.pos.x + this.w &&
point.y <= this.pos.y + this.h
) ? true : false;
}
getCenter():Point2D {
return new Point2D(
this.pos.x + (this.w / 2),
this.pos.y + (this.h / 2)
);
}
}