-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlatVector.cs
80 lines (65 loc) · 2.09 KB
/
FlatVector.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
using System;
namespace FlatPhysics
{
public readonly struct FlatVector
{
public readonly float X;
public readonly float Y;
public static readonly FlatVector Zero = new FlatVector(0f, 0f);
public FlatVector(float x, float y)
{
this.X = x;
this.Y = y;
}
public static FlatVector operator +(FlatVector a, FlatVector b)
{
return new FlatVector(a.X + b.X, a.Y + b.Y);
}
public static FlatVector operator -(FlatVector a, FlatVector b)
{
return new FlatVector(a.X - b.X, a.Y - b.Y);
}
public static FlatVector operator -(FlatVector v)
{
return new FlatVector(-v.X, -v.Y);
}
public static FlatVector operator *(FlatVector v, float s)
{
return new FlatVector(v.X * s, v.Y * s);
}
public static FlatVector operator *(float s, FlatVector v)
{
return new FlatVector(v.X * s, v.Y * s);
}
public static FlatVector operator /(FlatVector v, float s)
{
return new FlatVector(v.X / s, v.Y / s);
}
internal static FlatVector Transform(FlatVector v, FlatTransform transform)
{
return new FlatVector(
transform.Cos * v.X - transform.Sin * v.Y + transform.PositionX,
transform.Sin * v.X + transform.Cos * v.Y + transform.PositionY);
}
public bool Equals(FlatVector other)
{
return this.X == other.X && this.Y == other.Y;
}
public override bool Equals(object obj)
{
if (obj is FlatVector other)
{
return this.Equals(other);
}
return false;
}
public override int GetHashCode()
{
return new { this.X, this.Y }.GetHashCode();
}
public override string ToString()
{
return $"X: {this.X}, Y: {this.Y}";
}
}
}