-
Notifications
You must be signed in to change notification settings - Fork 1
/
DoublePoint.cs
58 lines (49 loc) · 1.12 KB
/
DoublePoint.cs
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
using System;
namespace MinionsOfDeath
{
public class DoublePoint
{
private double _x, _y;
public DoublePoint(double x, double y)
{
_x = x;
_y = y;
}
public double X
{
get { return _x; }
set { _x = value; }
}
public double Y
{
get { return _y; }
set { _y = value; }
}
public void Add(DoublePoint point)
{
_x += point._x;
_y += point._y;
}
public double GetMag()
{
return Math.Sqrt((_x * _x) + (_y * _y));
}
public void Set(DoublePoint point)
{
_x = point._x;
_y = point._y;
}
public bool SetToLessOrEqualMag(double mag)
{
double m = GetMag();
if (m <= mag) return true;
_x *= mag/m;
_y *= mag/m;
return false;
}
public static DoublePoint GetAverage(DoublePoint a, DoublePoint b)
{
return new DoublePoint ((a._x / 2) + (b._x / 2), (a._y / 2) + (b._y / 2));
}
}
}