-
Notifications
You must be signed in to change notification settings - Fork 1
/
Point2.cs
104 lines (103 loc) · 3.32 KB
/
Point2.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
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
using System;
namespace BMAPI
{
public class Point2
{
public float X { get; set; }
public float Y { get; set; }
public Point2()
{
X = Y = 0;
}
public Point2(float V)
{
X = Y = V;
}
public Point2(float X, float Y)
{
this.X = X;
this.Y = Y;
}
public float Length
{
get
{
return (float)Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2));
}
}
public void Normalize()
{
float length = Length; //Cache for minor performance improvement
X = X / length;
Y = Y / length;
}
public float DistanceTo(Point2 P)
{
return (float)Math.Sqrt(Math.Pow(P.X - X, 2) + Math.Pow(P.Y - Y, 2));
}
public static Point2 operator -(float Left, Point2 Right)
{
return new Point2(Left - Right.X, Left - Right.Y);
}
public static Point2 operator -(Point2 Left, float Right)
{
return new Point2(Left.X - Right, Left.Y - Right);
}
public static Point2 operator -(Point2 Left, Point2 Right)
{
return new Point2(Left.X - Right.X, Left.Y - Right.Y);
}
public static Point2 operator +(float Left, Point2 Right)
{
return new Point2(Right.X + Left, Right.Y + Left);
}
public static Point2 operator +(Point2 Left, float Right)
{
return new Point2(Left.X + Right, Left.Y + Right);
}
public static Point2 operator +(Point2 Left, Point2 Right)
{
return new Point2(Left.X + Right.X, Left.Y + Right.Y);
}
public static Point2 operator *(float Left, Point2 Right)
{
return new Point2(Right.X * Left, Right.Y * Left);
}
public static Point2 operator *(Point2 Left, float Right)
{
return new Point2(Left.X * Right, Left.Y * Right);
}
public static Point2 operator *(Point2 Left, Point2 Right)
{
return new Point2(Left.X * Right.X, Left.Y * Right.Y);
}
public static Point2 operator /(float Left, Point2 Right)
{
return new Point2(Left / Right.X, Left / Right.Y);
}
public static Point2 operator /(Point2 Left, float Right)
{
return new Point2(Left.X / Right, Left.Y / Right);
}
public static Point2 operator /(Point2 Left, Point2 Right)
{
return new Point2(Left.X / Right.X, Left.Y / Right.Y);
}
public static bool operator ==(Point2 Left, Point2 Right)
{
return (Left.X.CompareTo(Right.X) == 0 && Left.Y.CompareTo(Right.Y) == 0);
}
public static bool operator !=(Point2 Left, Point2 Right)
{
return (Left.X.CompareTo(Right.X) != 0 || Left.Y.CompareTo(Right.Y) != 0);
}
public override bool Equals(object obj)
{
return this == (Point2)obj;
}
public override int GetHashCode()
{
return (int)Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2));
}
}
}