| | 1 | | // <copyright file="ObjVector4.cs" company="Jérémy Ansel"> |
| | 2 | | // Copyright (c) 2017, 2019 Jérémy Ansel |
| | 3 | | // </copyright> |
| | 4 | | // <license> |
| | 5 | | // Licensed under the MIT license. See LICENSE.txt |
| | 6 | | // </license> |
| | 7 | |
|
| | 8 | | namespace JeremyAnsel.Media.WavefrontObj |
| | 9 | | { |
| | 10 | | [System.Diagnostics.DebuggerDisplay("{X} {Y} {Z} {W}")] |
| | 11 | | public struct ObjVector4 : IEquatable<ObjVector4> |
| | 12 | | { |
| | 13 | | private float x; |
| | 14 | |
|
| | 15 | | private float y; |
| | 16 | |
|
| | 17 | | private float z; |
| | 18 | |
|
| | 19 | | private float w; |
| | 20 | |
|
| | 21 | | public ObjVector4(System.Numerics.Vector4 v) |
| | 22 | | { |
| 0 | 23 | | this.x = v.X; |
| 0 | 24 | | this.y = v.Y; |
| 0 | 25 | | this.z = v.Z; |
| 0 | 26 | | this.w = v.W; |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public ObjVector4(System.Numerics.Vector3 v, float w = 1.0f) |
| | 30 | | { |
| 0 | 31 | | this.x = v.X; |
| 0 | 32 | | this.y = v.Y; |
| 0 | 33 | | this.z = v.Z; |
| 0 | 34 | | this.w = w; |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | public ObjVector4(float x, float y, float z, float w) |
| | 38 | | { |
| 627 | 39 | | this.x = x; |
| 627 | 40 | | this.y = y; |
| 627 | 41 | | this.z = z; |
| 627 | 42 | | this.w = w; |
| 627 | 43 | | } |
| | 44 | |
|
| | 45 | | public ObjVector4(float x, float y, float z) |
| | 46 | | { |
| 3 | 47 | | this.x = x; |
| 3 | 48 | | this.y = y; |
| 3 | 49 | | this.z = z; |
| 3 | 50 | | this.w = 1.0f; |
| 3 | 51 | | } |
| | 52 | |
|
| | 53 | | public float X |
| | 54 | | { |
| 108 | 55 | | readonly get { return this.x; } |
| 6 | 56 | | set { this.x = value; } |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public float Y |
| | 60 | | { |
| 108 | 61 | | readonly get { return this.y; } |
| 6 | 62 | | set { this.y = value; } |
| | 63 | | } |
| | 64 | |
|
| | 65 | | public float Z |
| | 66 | | { |
| 108 | 67 | | readonly get { return this.z; } |
| 6 | 68 | | set { this.z = value; } |
| | 69 | | } |
| | 70 | |
|
| | 71 | | public float W |
| | 72 | | { |
| 108 | 73 | | readonly get { return this.w; } |
| 6 | 74 | | set { this.w = value; } |
| | 75 | | } |
| | 76 | |
|
| | 77 | | public readonly override bool Equals(object? obj) |
| | 78 | | { |
| 3 | 79 | | return obj is ObjVector4 vector && Equals(vector); |
| | 80 | | } |
| | 81 | |
|
| | 82 | | public readonly bool Equals(ObjVector4 other) |
| | 83 | | { |
| 24 | 84 | | return x == other.x && |
| 24 | 85 | | y == other.y && |
| 24 | 86 | | z == other.z && |
| 24 | 87 | | w == other.w; |
| | 88 | | } |
| | 89 | |
|
| | 90 | | public readonly override int GetHashCode() |
| | 91 | | { |
| 0 | 92 | | var hashCode = -1743314642; |
| 0 | 93 | | hashCode = hashCode * -1521134295 + x.GetHashCode(); |
| 0 | 94 | | hashCode = hashCode * -1521134295 + y.GetHashCode(); |
| 0 | 95 | | hashCode = hashCode * -1521134295 + z.GetHashCode(); |
| 0 | 96 | | hashCode = hashCode * -1521134295 + w.GetHashCode(); |
| 0 | 97 | | return hashCode; |
| | 98 | | } |
| | 99 | |
|
| | 100 | | public static bool operator ==(ObjVector4 left, ObjVector4 right) |
| | 101 | | { |
| 0 | 102 | | return left.Equals(right); |
| | 103 | | } |
| | 104 | |
|
| | 105 | | public static bool operator !=(ObjVector4 left, ObjVector4 right) |
| | 106 | | { |
| 0 | 107 | | return !(left == right); |
| | 108 | | } |
| | 109 | |
|
| | 110 | | public static implicit operator ObjVector4(System.Numerics.Vector4 v) |
| | 111 | | { |
| 0 | 112 | | return new ObjVector4(v); |
| | 113 | | } |
| | 114 | |
|
| | 115 | | public readonly void Deconstruct(out float @x, out float @y, out float @z, out float @w) |
| | 116 | | { |
| 0 | 117 | | @x = this.x; |
| 0 | 118 | | @y = this.y; |
| 0 | 119 | | @z = this.z; |
| 0 | 120 | | @w = this.w; |
| 0 | 121 | | } |
| | 122 | |
|
| | 123 | | public readonly System.Numerics.Vector4 ToVector3() |
| | 124 | | { |
| 0 | 125 | | return new System.Numerics.Vector4(x, y, z, w); |
| | 126 | | } |
| | 127 | | } |
| | 128 | | } |
| | 129 | |
|