< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Common.Components.Point3
Assembly: ReFlex.Core.Common
File(s): D:\a\reflex\reflex\library\src\Core\Common\Components\Point3.cs
Line coverage
100%
Covered lines: 55
Uncovered lines: 0
Coverable lines: 55
Total lines: 198
Line coverage: 100%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_X()100%11100%
get_Y()100%11100%
get_Z()100%11100%
get_IsValid()100%11100%
get_IsFiltered()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
Set(...)100%11100%
Copy()100%11100%
Set(...)100%11100%
Direction(...)100%11100%
Interpolate(...)100%11100%
op_Addition(...)100%11100%
op_Subtraction(...)100%11100%
op_Multiply(...)100%11100%
op_Division(...)75%44100%
Distance(...)100%11100%
Squared2DDistance(...)100%11100%
Equals(...)100%66100%
ToString()100%22100%

File(s)

D:\a\reflex\reflex\library\src\Core\Common\Components\Point3.cs

#LineLine coverage
 1using ReFlex.Core.Common.Interfaces;
 2
 3namespace ReFlex.Core.Common.Components
 4{
 5    /// <inheritdoc />
 6    /// <summary>
 7    /// A three dimensional point.
 8    /// @todo: checks and fallback values for null references for operators and methods
 9    /// </summary>
 10    /// <seealso cref="IBase3" />
 11    public class Point3 : IBase3
 12    {
 13        /// <inheritdoc />
 14        /// <summary>
 15        /// Gets or sets the x value.
 16        /// </summary>
 17        /// <value>
 18        /// The x value.
 19        /// </value>
 3472295120        public float X { get; set; }
 21
 22        /// <inheritdoc />
 23        /// <summary>
 24        /// Gets or sets the y value.
 25        /// </summary>
 26        /// <value>
 27        /// The y value.
 28        /// </value>
 3472139229        public float Y { get; set; }
 30
 31        /// <inheritdoc />
 32        /// <summary>
 33        /// Gets or sets the z value.
 34        /// </summary>
 35        /// <value>
 36        /// The z value.
 37        /// </value>
 3480673238        public float Z { get; set; }
 39
 40        /// <summary>
 41        /// Returns true if ... is valid.
 42        /// </summary>
 43        /// <value>
 44        ///   <c>true</c> if this instance is valid; otherwise, <c>false</c>.
 45        /// </value>
 1971151046        public bool IsValid { get; set; } = true;
 47
 48
 49        /// <summary>
 50        /// Returns true if the point is excluded by a filter.
 51        /// </summary>
 52        /// <value>
 53        ///   <c>true</c> if this instance is removed by a filtered, otherwise <c>false</c>.
 54        /// </value>
 1963015655        public bool IsFiltered { get; set; } = false;
 56
 57        /// <summary>
 58        /// Initializes a new instance of the <see cref="Point3"/> class.
 59        /// </summary>
 2152071260        public Point3() => Set(0, 0, 0);
 61
 62        /// <summary>
 63        /// Initializes a new instance of the <see cref="Point3"/> class.
 64        /// </summary>
 65        /// <param name="x">The x.</param>
 66        /// <param name="y">The y.</param>
 67        /// <param name="z">The z.</param>
 859123268        public Point3(float x, float y, float z) => Set(x, y, z);
 69
 70        /// <summary>
 71        /// Initializes a new instance of the <see cref="Point3"/> class.
 72        /// </summary>
 73        /// <param name="base3">The base3.</param>
 674        public Point3(IBase3 base3) => Set(base3);
 75
 76        /// <inheritdoc />
 77        /// <summary>
 78        /// Copies the values from the input to [this] instance.
 79        /// </summary>
 80        /// <param name="base3">The base3 input.</param>
 439670881        public void Set(IBase3 base3) => Set(base3.X, base3.Y, base3.Z);
 82
 83        /// <inheritdoc />
 84        /// <summary>
 85        /// Copies this instance.
 86        /// </summary>
 87        /// <returns>a copy of this instance</returns>
 288        public IBase3 Copy() => new Point3(this) { IsValid = IsValid, IsFiltered = IsFiltered };
 89
 90        /// <inheritdoc />
 91        /// <summary>
 92        /// Sets the x, y and z value.
 93        /// </summary>
 94        /// <param name="x">The x value.</param>
 95        /// <param name="y">The y value.</param>
 96        /// <param name="z">The z value.</param>
 97        public void Set(float x, float y, float z)
 1945268098        {
 1945268099            X = x;
 19452680100            Y = y;
 19452680101            Z = z;
 19452680102        }
 103
 104        /// <summary>
 105        /// Direction from start to end.
 106        /// </summary>
 107        /// <param name="start">The start.</param>
 108        /// <param name="end">The end.</param>
 109        /// <returns>A <see cref="Vector3"/> which points from start to end.</returns>
 110        public static Vector3 Direction(Point3 start, Point3 end) =>
 4111            new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z);
 112
 113        /// <summary>
 114        /// Interpolates between point1 and point2.
 115        /// </summary>
 116        /// <param name="point1">The point1.</param>
 117        /// <param name="point2">The point2.</param>
 118        /// <param name="weight">The weight.</param>
 119        /// <returns>Interpolated point.</returns>
 120        public static Point3 Interpolate(Point3 point1, Point3 point2, float weight)
 3121        {
 3122            var x = (1 - weight) * point1.X + weight * point2.X;
 3123            var y = (1 - weight) * point1.Y + weight * point2.Y;
 3124            var z = (1 - weight) * point1.Z + weight * point2.Z;
 3125            return new Point3(x, y, z);
 3126        }
 127
 128        public static Point3 operator +(Point3 a, Point3 b)
 1129        {
 1130            return new Point3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
 1131        }
 132
 133        public static Point3 operator -(Point3 a, Point3 b)
 1134        {
 1135            return new Point3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
 1136        }
 137
 138        public static Point3 operator *(Point3 a, float scalar)
 1139        {
 1140            return new Point3(a.X * scalar, a.Y * scalar, a.Z * scalar);
 1141        }
 142
 143        public static Point3 operator /(Point3 a, float scalar)
 2144        {
 2145            if (System.Math.Abs(scalar) <= float.Epsilon)
 1146                scalar = scalar >= 0 ? float.Epsilon : -float.Epsilon;
 147
 2148            var rez = 1f / scalar;
 2149            return new Point3(a.X * rez, a.Y * rez, a.Z * rez);
 2150        }
 151
 152        /// <summary>
 153        /// Calculates the distance between two points.
 154        /// </summary>
 155        /// <param name="point1">The point1.</param>
 156        /// <param name="point2">The point2.</param>
 157        /// <returns>The distance between two points.</returns>
 158        public static float Distance(Point3 point1, Point3 point2)
 1159        {
 1160            var lenX = point2.X - point1.X;
 1161            var lenY = point2.Y - point1.Y;
 1162            var lenZ = point2.Z - point1.Z;
 163
 1164            return (float)System.Math.Sqrt((lenX * lenX) + (lenY * lenY) + (lenZ * lenZ));
 1165        }
 166
 167        public static float Squared2DDistance(Point3 point1, Point3 point2)
 655168        {
 655169            var lenX = point2.X - point1.X;
 655170            var lenY = point2.Y - point1.Y;
 171
 655172            return System.Math.Abs(lenX) + System.Math.Abs(lenY);
 655173        }
 174
 175        /// <summary>
 176        /// Compares [this] instance with the input.
 177        /// </summary>
 178        /// <param name="base3">The base3 to compare with.</param>
 179        /// <returns>
 180        ///   <c>true</c> if the values of the input and [this] instance are equal.
 181        /// </returns>
 182        public bool Equals(IBase3 base3)
 21183        {
 21184            return base3 != null &&
 21185                   Equals(X, base3.X) &&
 21186                   Equals(Y, base3.Y) &&
 21187                   Equals(Z, base3.Z);
 21188        }
 189
 190        /// <summary>
 191        /// Returns a <see cref="string" /> that represents [this] instance.
 192        /// </summary>
 193        /// <returns>
 194        /// A <see cref="string" /> that represents [this] instance.
 195        /// </returns>
 4196        public override string ToString() => IsValid ? $"X: {X}; Y: {Y}; Z: {Z}" : "invalid";
 197    }
 198}