/
Vector.cs
73 lines (62 loc) · 1.95 KB
/
Vector.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
using System.Diagnostics.Contracts;
namespace Meadow.Foundation.Spatial
{
/// <summary>
/// Vector in three dimensional space.
/// </summary>
public struct Vector
{
/// <summary>
/// X component of the vector.
/// </summary>
public double X { get; set; }
/// <summary>
/// Y component of the vector.
/// </summary>
public double Y { get; set; }
/// <summary>
/// Z component of the vector.
/// </summary>
public double Z { get; set; }
/// <summary>
/// Create a new Vector object with the specified X, Y and Z components.
/// </summary>
/// <param name="x">X component of the vector.</param>
/// <param name="y">Y component of the vector.</param>
/// <param name="z">Z component of the vector.</param>
public Vector(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// Vector addition operator
/// </summary>
/// <param name="lvalue">left value</param>
/// <param name="rvalue">right value</param>
/// <returns></returns>
[Pure]
public static Vector operator +(Vector lvalue, Vector rvalue)
{
var x = lvalue.X + rvalue.X;
var y = lvalue.Y + rvalue.Y;
var z = lvalue.Z + rvalue.Z;
return new Vector(x, y, z);
}
/// <summary>
/// Vector subtraction operator
/// </summary>
/// <param name="lvalue">left value</param>
/// <param name="rvalue">right value</param>
/// <returns></returns>
[Pure]
public static Vector operator -(Vector lvalue, Vector rvalue)
{
var x = lvalue.X - rvalue.X;
var y = lvalue.Y - rvalue.Y;
var z = lvalue.Z - rvalue.Z;
return new Vector(x, y, z);
}
}
}