| | 1 | | // <copyright file="ObjTriplet.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 | | using System.Globalization; |
| | 9 | |
|
| | 10 | | namespace JeremyAnsel.Media.WavefrontObj |
| | 11 | | { |
| | 12 | | [System.Diagnostics.DebuggerDisplay("Vertex:{vertex} Texture:{texture} Normal:{normal}")] |
| | 13 | | public struct ObjTriplet : IEquatable<ObjTriplet> |
| | 14 | | { |
| | 15 | | private int vertex; |
| | 16 | |
|
| | 17 | | private int texture; |
| | 18 | |
|
| | 19 | | private int normal; |
| | 20 | |
|
| | 21 | | public ObjTriplet(int vertexIndex, int textureIndex, int normalIndex) |
| | 22 | | { |
| 354 | 23 | | this.vertex = vertexIndex; |
| 354 | 24 | | this.texture = textureIndex; |
| 354 | 25 | | this.normal = normalIndex; |
| 354 | 26 | | } |
| | 27 | |
|
| | 28 | | public int Vertex |
| | 29 | | { |
| 255 | 30 | | readonly get { return this.vertex; } |
| 6 | 31 | | set { this.vertex = value; } |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public int Texture |
| | 35 | | { |
| 153 | 36 | | readonly get { return this.texture; } |
| 6 | 37 | | set { this.texture = value; } |
| | 38 | | } |
| | 39 | |
|
| | 40 | | public int Normal |
| | 41 | | { |
| 153 | 42 | | readonly get { return this.normal; } |
| 6 | 43 | | set { this.normal = value; } |
| | 44 | | } |
| | 45 | |
|
| | 46 | | public readonly override bool Equals(object? obj) |
| | 47 | | { |
| 0 | 48 | | return obj is ObjTriplet triplet && Equals(triplet); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public readonly bool Equals(ObjTriplet other) |
| | 52 | | { |
| 0 | 53 | | return vertex == other.vertex && |
| 0 | 54 | | texture == other.texture && |
| 0 | 55 | | normal == other.normal; |
| | 56 | | } |
| | 57 | |
|
| | 58 | | public readonly override int GetHashCode() |
| | 59 | | { |
| 0 | 60 | | var hashCode = -683219715; |
| 0 | 61 | | hashCode = hashCode * -1521134295 + vertex.GetHashCode(); |
| 0 | 62 | | hashCode = hashCode * -1521134295 + texture.GetHashCode(); |
| 0 | 63 | | hashCode = hashCode * -1521134295 + normal.GetHashCode(); |
| 0 | 64 | | return hashCode; |
| | 65 | | } |
| | 66 | |
|
| | 67 | | public readonly override string ToString() |
| | 68 | | { |
| 129 | 69 | | if (this.Normal == 0) |
| | 70 | | { |
| 123 | 71 | | if (this.Texture == 0) |
| | 72 | | { |
| 120 | 73 | | return this.Vertex.ToString(CultureInfo.InvariantCulture); |
| | 74 | | } |
| | 75 | | else |
| | 76 | | { |
| 3 | 77 | | return string.Concat( |
| 3 | 78 | | this.Vertex.ToString(CultureInfo.InvariantCulture), |
| 3 | 79 | | "/", |
| 3 | 80 | | this.Texture.ToString(CultureInfo.InvariantCulture)); |
| | 81 | | } |
| | 82 | | } |
| | 83 | | else |
| | 84 | | { |
| 6 | 85 | | if (this.Texture == 0) |
| | 86 | | { |
| 3 | 87 | | return string.Concat( |
| 3 | 88 | | this.Vertex.ToString(CultureInfo.InvariantCulture), |
| 3 | 89 | | "//", |
| 3 | 90 | | this.Normal.ToString(CultureInfo.InvariantCulture)); |
| | 91 | | } |
| | 92 | | else |
| | 93 | | { |
| 3 | 94 | | return string.Concat( |
| 3 | 95 | | this.Vertex.ToString(CultureInfo.InvariantCulture), |
| 3 | 96 | | "/", |
| 3 | 97 | | this.Texture.ToString(CultureInfo.InvariantCulture), |
| 3 | 98 | | "/", |
| 3 | 99 | | this.Normal.ToString(CultureInfo.InvariantCulture)); |
| | 100 | | } |
| | 101 | | } |
| | 102 | | } |
| | 103 | |
|
| | 104 | | public static bool operator ==(ObjTriplet left, ObjTriplet right) |
| | 105 | | { |
| 0 | 106 | | return left.Equals(right); |
| | 107 | | } |
| | 108 | |
|
| | 109 | | public static bool operator !=(ObjTriplet left, ObjTriplet right) |
| | 110 | | { |
| 0 | 111 | | return !(left == right); |
| | 112 | | } |
| | 113 | | } |
| | 114 | | } |
| | 115 | |
|