-
Notifications
You must be signed in to change notification settings - Fork 72
/
class_HBVector.ahk
104 lines (102 loc) · 1.75 KB
/
class_HBVector.ahk
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
; Written By: Hellbent aka CivReborn
;Date Started: June 24th, 2018
;Date of last edit: June 24th, 2018
;Name: HB_Vector Class.ahk
;Last Paste:
Class HB_Vector
{
__New(x:=0,y:=0)
{
This.X:=x
This.Y:=y
}
Add(Other_HB_Vector)
{
This.X+=Other_HB_Vector.X
This.Y+=Other_HB_Vector.Y
}
Sub(Other_HB_Vector)
{
This.X-=Other_HB_Vector.X
This.Y-=Other_HB_Vector.Y
}
mag()
{
return Sqrt(This.X*This.X + This.Y*This.Y)
}
magsq()
{
return This.Mag()**2
}
setMag(in1)
{
m:=This.Mag()
This.X := This.X * in1/m
This.Y := This.Y * in1/m
return This
}
mult(in1,in2:="",in3:="",in4:="",in5:="")
{
if(IsObject(in1)&&in2="")
{
This.X*=In1.X
This.Y*=In1.Y
}
else if(!IsObject(In1)&&In2="")
{
This.X*=In1
This.Y*=In1
}
else if(!IsObject(In1)&&IsObject(In2))
{
This.X*=In1*In2.X
This.Y*=In1*In2.Y
}
else if(IsObject(In1)&&IsObject(In2))
{
This.X*=In1.X*In2.X
This.Y*=In1.Y*In2.Y
}
}
div(in1,in2:="",in3:="",in4:="",in5:="")
{
if(IsObject(in1)&&in2="")
{
This.X/=In1.X
This.Y/=In1.Y
}
else if(!IsObject(In1)&&In2="")
{
This.X/=In1
This.Y/=In1
}
else if(!IsObject(In1)&&IsObject(In2))
{
This.X/=In1/In2.X
This.Y/=In1/In2.Y
}
else if(IsObject(In1)&&IsObject(In2))
{
This.X/=In1.X/In2.X
This.Y/=In1.Y/In2.Y
}
}
dist(in1)
{
return Sqrt(((This.X-In1.X)**2) + ((This.Y-In1.Y)**2))
}
dot(in1)
{
return (This.X*in1.X)+(This.Y*In1.Y)
}
cross(in1)
{
return This.X*In1.Y-This.Y*In1.X
}
Norm()
{
m:=This.Mag()
This.X/=m
This.Y/=m
}
}