-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathVectorPoint.cs
More file actions
80 lines (66 loc) · 3.61 KB
/
VectorPoint.cs
File metadata and controls
80 lines (66 loc) · 3.61 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
74
75
76
77
78
79
80
[StructLayout(LayoutKind.Explicit, Size = 32)]
public struct PointZM
{
[FieldOffset(0)] private Vector256<double> vector;
public PointZM(double x, double y, double z, double m) : this() => vector = Vector256.Create(x, y, z, m);
public PointZM(double x, double y, double z) : this(x, y, z, double.NaN) { }
public double X
{
readonly get => vector[0];
set => vector = vector.WithElement(0, value);
}
public double Y
{
readonly get => vector[1];
set => vector = vector.WithElement(1, value);
}
public double Z
{
readonly get => vector[2];
set => vector = vector.WithElement(2, value);
}
public double M
{
readonly get => vector[3];
set => vector = vector.WithElement(3, value);
}
public static int Count => Vector256<double>.Count;
public static PointZM Zero => (PointZM)Vector256<double>.Zero;
public static double Dot2D(PointZM left, PointZM right) => Point.Dot2D((Point)left, (Point)right);
public override readonly int GetHashCode() => vector.GetHashCode();
public override readonly string ToString() => vector.ToString();
public static implicit operator Vector256<double>(PointZM p) => Unsafe.As<PointZM, Vector256<double>>(ref p);
public static explicit operator PointZM(Vector256<double> vector) => Unsafe.As<Vector256<double>, PointZM>(ref vector);
public static explicit operator Point(PointZM pointZM) => (Point)Vector256.GetLower<double>(pointZM);
public static PointZM operator +(PointZM left, PointZM right) => (PointZM)((Vector256<double>)left + right);
public static PointZM operator -(PointZM left, PointZM right) => (PointZM)((Vector256<double>)left - right);
public static PointZM operator *(PointZM left, PointZM right) => (PointZM)((Vector256<double>)left * right);
public static PointZM operator /(PointZM left, PointZM right) => (PointZM)((Vector256<double>)left / right);
}
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct Point
{
[FieldOffset(0)] private Vector128<double> vector;
public Point(double x, double y) : this() => vector = Vector128.Create(x, y);
public double X
{
readonly get => vector[0];
set => vector = vector.WithElement(0, value);
}
public double Y
{
readonly get => vector[1];
set => vector = vector.WithElement(1, value);
}
public static int Count => Vector128<double>.Count;
public static Point Zero => (Point)Vector128<double>.Zero;
public override readonly int GetHashCode() => vector.GetHashCode();
public override readonly string ToString() => vector.ToString();
public static implicit operator Vector128<double>(Point p) => Unsafe.As<Point, Vector128<double>>(ref p);
public static explicit operator Point(Vector128<double> vector) => Unsafe.As<Vector128<double>, Point>(ref vector);
public static Point operator +(Point left, Point right) => (Point)((Vector128<double>)left + right);
public static Point operator -(Point left, Point right) => (Point)((Vector128<double>)left - right);
public static Point operator *(Point left, Point right) => (Point)((Vector128<double>)left * right);
public static Point operator /(Point left, Point right) => (Point)((Vector128<double>)left / right);
public static double Dot2D(Point left, Point right) => Vector128.Dot<double>(left , right);
}