| | 1 | | // <copyright file="ObjVector3.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}")] |
| | 11 | | public struct ObjVector3 : IEquatable<ObjVector3> |
| | 12 | | { |
| | 13 | | private float x; |
| | 14 | |
|
| | 15 | | private float y; |
| | 16 | |
|
| | 17 | | private float z; |
| | 18 | |
|
| | 19 | | public ObjVector3(System.Numerics.Vector3 v) |
| | 20 | | { |
| 0 | 21 | | this.x = v.X; |
| 0 | 22 | | this.y = v.Y; |
| 0 | 23 | | this.z = v.Z; |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public ObjVector3(System.Numerics.Vector2 v, float z = 1.0f) |
| | 27 | | { |
| 0 | 28 | | this.x = v.X; |
| 0 | 29 | | this.y = v.Y; |
| 0 | 30 | | this.z = z; |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public ObjVector3(float x, float y, float z) |
| | 34 | | { |
| 1368 | 35 | | this.x = x; |
| 1368 | 36 | | this.y = y; |
| 1368 | 37 | | this.z = z; |
| 1368 | 38 | | } |
| | 39 | |
|
| | 40 | | public ObjVector3(float x, float y) |
| | 41 | | { |
| 3 | 42 | | this.x = x; |
| 3 | 43 | | this.y = y; |
| 3 | 44 | | this.z = 1.0f; |
| 3 | 45 | | } |
| | 46 | |
|
| | 47 | | public ObjVector3(float x) |
| | 48 | | { |
| 3 | 49 | | this.x = x; |
| 3 | 50 | | this.y = 0.0f; |
| 3 | 51 | | this.z = 1.0f; |
| 3 | 52 | | } |
| | 53 | |
|
| | 54 | | public float X |
| | 55 | | { |
| 528 | 56 | | readonly get { return this.x; } |
| 750 | 57 | | set { this.x = value; } |
| | 58 | | } |
| | 59 | |
|
| | 60 | | public float Y |
| | 61 | | { |
| 462 | 62 | | readonly get { return this.y; } |
| 642 | 63 | | set { this.y = value; } |
| | 64 | | } |
| | 65 | |
|
| | 66 | | public float Z |
| | 67 | | { |
| 474 | 68 | | readonly get { return this.z; } |
| 624 | 69 | | set { this.z = value; } |
| | 70 | | } |
| | 71 | |
|
| | 72 | | public readonly override bool Equals(object? obj) |
| | 73 | | { |
| 0 | 74 | | return obj is ObjVector3 vector && Equals(vector); |
| | 75 | | } |
| | 76 | |
|
| | 77 | | public readonly bool Equals(ObjVector3 other) |
| | 78 | | { |
| 30 | 79 | | return x == other.x && |
| 30 | 80 | | y == other.y && |
| 30 | 81 | | z == other.z; |
| | 82 | | } |
| | 83 | |
|
| | 84 | | public readonly override int GetHashCode() |
| | 85 | | { |
| 0 | 86 | | var hashCode = 373119288; |
| 0 | 87 | | hashCode = hashCode * -1521134295 + x.GetHashCode(); |
| 0 | 88 | | hashCode = hashCode * -1521134295 + y.GetHashCode(); |
| 0 | 89 | | hashCode = hashCode * -1521134295 + z.GetHashCode(); |
| 0 | 90 | | return hashCode; |
| | 91 | | } |
| | 92 | |
|
| | 93 | | public static bool operator ==(ObjVector3 left, ObjVector3 right) |
| | 94 | | { |
| 0 | 95 | | return left.Equals(right); |
| | 96 | | } |
| | 97 | |
|
| | 98 | | public static bool operator !=(ObjVector3 left, ObjVector3 right) |
| | 99 | | { |
| 0 | 100 | | return !(left == right); |
| | 101 | | } |
| | 102 | |
|
| | 103 | | public static implicit operator ObjVector3(System.Numerics.Vector3 v) |
| | 104 | | { |
| 0 | 105 | | return new ObjVector3(v); |
| | 106 | | } |
| | 107 | |
|
| | 108 | | public readonly void Deconstruct(out float @x, out float @y, out float @z) |
| | 109 | | { |
| 0 | 110 | | @x = this.x; |
| 0 | 111 | | @y = this.y; |
| 0 | 112 | | @z = this.z; |
| 0 | 113 | | } |
| | 114 | |
|
| | 115 | | public readonly System.Numerics.Vector3 ToVector3() |
| | 116 | | { |
| 0 | 117 | | return new System.Numerics.Vector3(x, y, z); |
| | 118 | | } |
| | 119 | | } |
| | 120 | | } |
| | 121 | |
|