-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
56 lines (49 loc) · 1.3 KB
/
helper.js
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
55
56
class Helper {
constructor() {
}
sortTwoPoints(x1, y1, x2, y2) { // mousePressedX, mousePressedY, mouseX, mouseY
var firstPoint = { x: 0, y: 0 };
var secondPoint = { x: 0, y: 0 };
var orient = 'down';
if (y1 == y2) {
if (x1 < x2) {
firstPoint = { x: x1, y: y1 };
secondPoint = { x: x2, y: y2 };
//console.log('straight to the right');
orient = 'down';
} else {
firstPoint = { x: x2, y: y2 };
secondPoint = { x: x1, y: y1 };
//console.log('straight to the left');
orient = 'up';
}
} else if (y1 < y2) {
firstPoint = { x: x1, y: y1 };
secondPoint = { x: x2, y: y2 };
//console.log('down');
orient = 'down';
} else {
firstPoint = { x: x2, y: y2 };
secondPoint = { x: x1, y: y1 };
//console.log('up');
orient = 'up';
}
return {
firstPoint: firstPoint,
secondPoint: secondPoint,
orient: orient
};
}
doBasicCalculations(firstPoint, secondPoint) {
var a = secondPoint.x - firstPoint.x;
var b = secondPoint.y - firstPoint.y;
return {
a: a,
b: b,
c: Math.sqrt(a * a + b * b),
x: (secondPoint.x + firstPoint.x) / 2,
y: (secondPoint.y + firstPoint.y) / 2,
angle: Math.atan2(b, a)
};
}
}