-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVector2f.cs
More file actions
58 lines (49 loc) · 1.05 KB
/
Vector2f.cs
File metadata and controls
58 lines (49 loc) · 1.05 KB
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;
using System.Collections.Generic;
using System.Text;
namespace las.datamanager.structures
{
[Serializable]
public struct Vector2f
{
public float x;
public float y;
public Vector2f(float x, float y)
{
this.x = x;
this.y = y;
}
public static Vector2f operator +(Vector2f v1, Vector2f v2)
{
return new Vector2f(v1.x + v2.x, v1.y + v2.y);
}
public static Vector2f operator -(Vector2f v1, Vector2f v2)
{
return new Vector2f(v1.x - v2.x, v1.y - v2.y);
}
public static Vector2f operator -(Vector2f v)
{
return new Vector2f(-v.x, -v.y);
}
public void Normalize()
{
double length = Math.Sqrt(x * x + y * y);
x = (float)(x / length);
y = (float)(y / length);
}
public float Length
{
get
{
return (float)Math.Sqrt(x * x + y * y);
}
private set
{
}
}
public static Vector2f operator *(Vector2f v, float n)
{
return new Vector2f(v.x * n, v.y * n);
}
}
}