| | 1 | | // <copyright file="ObjVertex.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("Vertex Position:{Position} Color:{Color}")] |
| | 11 | | public struct ObjVertex : IEquatable<ObjVertex> |
| | 12 | | { |
| | 13 | | private ObjVector4 position; |
| | 14 | |
|
| | 15 | | private ObjVector4? color; |
| | 16 | |
|
| | 17 | | public ObjVertex(float x, float y, float z) |
| | 18 | | { |
| 66 | 19 | | this.position = new ObjVector4(x, y, z, 1.0f); |
| 66 | 20 | | this.color = null; |
| 66 | 21 | | } |
| | 22 | |
|
| | 23 | | public ObjVertex(float x, float y, float z, float w) |
| | 24 | | { |
| 15 | 25 | | this.position = new ObjVector4(x, y, z, w); |
| 15 | 26 | | this.color = null; |
| 15 | 27 | | } |
| | 28 | |
|
| | 29 | | public ObjVertex(float x, float y, float z, float r, float g, float b) |
| | 30 | | { |
| 3 | 31 | | this.position = new ObjVector4(x, y, z, 1.0f); |
| 3 | 32 | | this.color = new ObjVector4(r, g, b, 1.0f); |
| 3 | 33 | | } |
| | 34 | |
|
| | 35 | | public ObjVertex(float x, float y, float z, float r, float g, float b, float a) |
| | 36 | | { |
| 15 | 37 | | this.position = new ObjVector4(x, y, z, 1.0f); |
| 15 | 38 | | this.color = new ObjVector4(r, g, b, a); |
| 15 | 39 | | } |
| | 40 | |
|
| | 41 | | public ObjVector4 Position |
| | 42 | | { |
| 126 | 43 | | get { return this.position; } |
| 984 | 44 | | set { this.position = value; } |
| | 45 | | } |
| | 46 | |
|
| | 47 | | public ObjVector4? Color |
| | 48 | | { |
| 120 | 49 | | get { return this.color; } |
| 18 | 50 | | set { this.color = value; } |
| | 51 | | } |
| | 52 | |
|
| | 53 | | public override bool Equals(object? obj) |
| | 54 | | { |
| 0 | 55 | | return obj is ObjVertex vertex && Equals(vertex); |
| | 56 | | } |
| | 57 | |
|
| | 58 | | public bool Equals(ObjVertex other) |
| | 59 | | { |
| 12 | 60 | | return position.Equals(other.position) && |
| 12 | 61 | | EqualityComparer<ObjVector4?>.Default.Equals(color, other.color); |
| | 62 | | } |
| | 63 | |
|
| | 64 | | public override int GetHashCode() |
| | 65 | | { |
| 0 | 66 | | var hashCode = -2056440846; |
| 0 | 67 | | hashCode = hashCode * -1521134295 + EqualityComparer<ObjVector4>.Default.GetHashCode(position); |
| | 68 | |
|
| 0 | 69 | | if (color.HasValue) |
| | 70 | | { |
| 0 | 71 | | hashCode = hashCode * -1521134295 + EqualityComparer<ObjVector4>.Default.GetHashCode(color.Value); |
| | 72 | | } |
| | 73 | |
|
| 0 | 74 | | return hashCode; |
| | 75 | | } |
| | 76 | |
|
| | 77 | | public static bool operator ==(ObjVertex left, ObjVertex right) |
| | 78 | | { |
| 0 | 79 | | return left.Equals(right); |
| | 80 | | } |
| | 81 | |
|
| | 82 | | public static bool operator !=(ObjVertex left, ObjVertex right) |
| | 83 | | { |
| 0 | 84 | | return !(left == right); |
| | 85 | | } |
| | 86 | | } |
| | 87 | | } |
| | 88 | |
|