forked from Nivekk/KOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cs
More file actions
73 lines (61 loc) · 1.83 KB
/
Vector.cs
File metadata and controls
73 lines (61 loc) · 1.83 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace kOS
{
public class Vector : SpecialValue
{
float x;
float y;
float z;
public Vector(Vector3d init)
{
x = (float)init.x;
y = (float)init.y;
z = (float)init.z;
}
public Vector(double x, double y, double z)
{
this.x = (float)x;
this.y = (float)y;
this.z = (float)z;
}
public Vector(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
public Direction ToDirection()
{
return new Direction(ToVector3D(), false);
}
public override object GetSuffix(string suffixName)
{
if (suffixName == "X") return x;
if (suffixName == "Y") return y;
if (suffixName == "Z") return z;
return base.GetSuffix(suffixName);
}
public Vector3d ToVector3D()
{
return new Vector3d(x,y,z);
}
public override string ToString()
{
return "V(" + x + ", " + y + ", " + z + ")";
}
public static implicit operator Vector3d(Vector d)
{
return d.ToVector3D();
}
public static explicit operator Direction(Vector d)
{
return new Direction(d.ToVector3D(), false);
}
public static Vector operator *(Vector a, Vector b) { return new Vector(a.x * b.x, a.y * b.y, a.z * b.z); }
public static Vector operator +(Vector a, Vector b) { return new Vector(a.ToVector3D() + b.ToVector3D()); }
public static Vector operator -(Vector a, Vector b) { return new Vector(a.ToVector3D() - b.ToVector3D()); }
}
}