| | 1 | | using ReFlex.Core.Common.Interfaces; |
| | 2 | |
|
| | 3 | | namespace ReFlex.Core.Common.Components |
| | 4 | | { |
| | 5 | | /// <inheritdoc /> |
| | 6 | | /// <summary> |
| | 7 | | /// A threedimensional vector. |
| | 8 | | /// </summary> |
| | 9 | | /// <seealso cref="IBase3" /> |
| | 10 | | public class Vector3 : IBase3 |
| | 11 | | { |
| | 12 | | /// <inheritdoc /> |
| | 13 | | /// <summary> |
| | 14 | | /// Gets or sets the x value. |
| | 15 | | /// </summary> |
| | 16 | | /// <value> |
| | 17 | | /// The x value. |
| | 18 | | /// </value> |
| 8 | 19 | | public float X { get; set; } |
| | 20 | |
|
| | 21 | | /// <inheritdoc /> |
| | 22 | | /// <summary> |
| | 23 | | /// Gets or sets the y value. |
| | 24 | | /// </summary> |
| | 25 | | /// <value> |
| | 26 | | /// The y value. |
| | 27 | | /// </value> |
| 8 | 28 | | public float Y { get; set; } |
| | 29 | |
|
| | 30 | | /// <inheritdoc /> |
| | 31 | | /// <summary> |
| | 32 | | /// Gets or sets the z value. |
| | 33 | | /// </summary> |
| | 34 | | /// <value> |
| | 35 | | /// The z value. |
| | 36 | | /// </value> |
| 8 | 37 | | public float Z { get; set; } |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Returns true if the vector is valid. |
| | 41 | | /// </summary> |
| | 42 | | /// <value> |
| | 43 | | /// <c>true</c> if this vector is valid; otherwise, <c>false</c>. |
| | 44 | | /// </value> |
| | 45 | | /// <inheritdoc /> |
| 4 | 46 | | public bool IsValid { get; set; } = true; |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Returns true if this vector is filtered. |
| | 50 | | /// </summary> |
| | 51 | | /// <value> |
| | 52 | | /// <c>true</c> if this vector is filtered; otherwise, <c>false</c>. |
| | 53 | | /// </value> |
| | 54 | | /// <inheritdoc /> |
| 4 | 55 | | public bool IsFiltered { get; set; } = true; |
| | 56 | |
|
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Initializes a new instance of the <see cref="Vector3"/> class. |
| | 60 | | /// </summary> |
| 0 | 61 | | public Vector3() => Set(0, 0, 0); |
| | 62 | |
|
| | 63 | | /// <summary> |
| | 64 | | /// Initializes a new instance of the <see cref="Vector3"/> class. |
| | 65 | | /// </summary> |
| | 66 | | /// <param name="x">The x.</param> |
| | 67 | | /// <param name="y">The y.</param> |
| | 68 | | /// <param name="z">The z.</param> |
| 8 | 69 | | public Vector3(float x, float y, float z) => Set(x, y, z); |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Initializes a new instance of the <see cref="Vector3"/> class. |
| | 73 | | /// </summary> |
| | 74 | | /// <param name="base3">The base3.</param> |
| 0 | 75 | | public Vector3(IBase3 base3) => Set(base3); |
| | 76 | |
|
| | 77 | | /// <inheritdoc /> |
| | 78 | | /// <summary> |
| | 79 | | /// Copies the values from the input to [this] instance. |
| | 80 | | /// </summary> |
| | 81 | | /// <param name="base3">The base3 input.</param> |
| 0 | 82 | | public void Set(IBase3 base3) => Set(base3.X, base3.Y, base3.Z); |
| | 83 | |
|
| | 84 | | /// <inheritdoc /> |
| | 85 | | /// <summary> |
| | 86 | | /// Copies this instance. |
| | 87 | | /// </summary> |
| | 88 | | /// <returns></returns> |
| 0 | 89 | | public IBase3 Copy() => new Vector3(this); |
| | 90 | |
|
| | 91 | | /// <summary> |
| | 92 | | /// Gets the length. |
| | 93 | | /// </summary> |
| | 94 | | /// <value> |
| | 95 | | /// The length. |
| | 96 | | /// </value> |
| 0 | 97 | | public float Length => (float)System.Math.Sqrt(X * X + Y * Y + Z * Z); |
| | 98 | |
|
| | 99 | | /// <summary> |
| | 100 | | /// Gets the normalized copy. |
| | 101 | | /// </summary> |
| | 102 | | /// <value> |
| | 103 | | /// The normalized copy. |
| | 104 | | /// </value> |
| 0 | 105 | | public Vector3 NormalizedCopy => Length > 0 ? new Vector3(X / Length, Y / Length, Z / Length) : new Vector3(); |
| | 106 | |
|
| | 107 | | /// <inheritdoc /> |
| | 108 | | /// <summary> |
| | 109 | | /// Sets the x, y and z value. |
| | 110 | | /// </summary> |
| | 111 | | /// <param name="x">The x value.</param> |
| | 112 | | /// <param name="y">The y value.</param> |
| | 113 | | /// <param name="z">The z value.</param> |
| | 114 | | public void Set(float x, float y, float z) |
| 4 | 115 | | { |
| 4 | 116 | | X = x; |
| 4 | 117 | | Y = y; |
| 4 | 118 | | Z = z; |
| 4 | 119 | | } |
| | 120 | |
|
| | 121 | | /// <inheritdoc /> |
| | 122 | | /// <summary> |
| | 123 | | /// Compares [this] instance with the input. |
| | 124 | | /// </summary> |
| | 125 | | /// <param name="base3">The base3 to compare with.</param> |
| | 126 | | /// <returns> |
| | 127 | | /// <c>true</c> if the values of the input and [this] instance are equal. |
| | 128 | | /// </returns> |
| | 129 | | public bool Equals(IBase3 base3) |
| 0 | 130 | | { |
| 0 | 131 | | return base3 != null && |
| 0 | 132 | | Equals(X, base3.X) && |
| 0 | 133 | | Equals(Y, base3.Y) && |
| 0 | 134 | | Equals(Z, base3.Z); |
| 0 | 135 | | } |
| | 136 | |
|
| | 137 | | /// <summary> |
| | 138 | | /// Returns a <see cref="string" /> that represents [this] instance. |
| | 139 | | /// </summary> |
| | 140 | | /// <returns> |
| | 141 | | /// A <see cref="string" /> that represents [this] instance. |
| | 142 | | /// </returns> |
| 0 | 143 | | public override string ToString() => IsValid ? $"X: {X}; Y: {Y}; Z: {Z}" : "invalid"; |
| | 144 | | } |
| | 145 | | } |