forked from OpenDroneMap/Obj2Tiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSVec2.cs
47 lines (37 loc) · 996 Bytes
/
SVec2.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
using System;
using System.IO;
using System.Linq;
namespace SilentWave.Obj2Gltf
{
/// <summary>
/// 2-d point or vector
/// </summary>
public struct SVec2
{
public SVec2(float u, float v)
{
U = u;
V = v;
}
public readonly float U;
public readonly float V;
public override string ToString() => $"{U}, {V}";
public void WriteBytes(BinaryWriter sw)
{
sw.Write(U);
sw.Write(V);
}
public float[] ToArray() => new[] { U, V };
public float GetDistance(SVec2 p) => (float)Math.Sqrt((U - p.U) * (U - p.U) + (V - p.V) * (V - p.V));
public float GetLength() => (float)Math.Sqrt(U * U + V * V);
public SVec2 Normalize()
{
var len = GetLength();
return new SVec2(U / len, V / len);
}
public float Dot(SVec2 v)
{
return U * v.U + V * v.V;
}
}
}