< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Common.Components.Vector2
Assembly: ReFlex.Core.Common
File(s): D:\a\reflex\reflex\library\src\Core\Common\Components\Vector2.cs
Line coverage
33%
Covered lines: 8
Uncovered lines: 16
Coverable lines: 24
Total lines: 147
Line coverage: 33.3%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
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_IsValid()100%11100%
.ctor()100%210%
.ctor(...)100%11100%
.ctor(...)100%210%
Set(...)100%210%
Copy()100%210%
get_Length()100%210%
get_NormalizedCopy()0%620%
Add(...)100%210%
Multiply(...)100%210%
Multiply(...)100%210%
AngleBetween(...)100%210%
Set(...)100%11100%
Equals(...)0%2040%
ToString()0%620%

File(s)

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

#LineLine coverage
 1using ReFlex.Core.Common.Interfaces;
 2
 3namespace ReFlex.Core.Common.Components
 4{
 5    /// <inheritdoc />
 6    /// <summary>
 7    /// A twodimensional vector.
 8    /// </summary>
 9    /// <seealso cref="IBase2" />
 10    public class Vector2 : IBase2
 11    {
 12        /// <inheritdoc />
 13        /// <summary>
 14        /// Gets or sets the x value.
 15        /// </summary>
 16        /// <value>
 17        /// The x value.
 18        /// </value>
 619        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>
 628        public float Y { get; set; }
 29
 30        /// <inheritdoc />
 31        /// <summary>
 32        /// Returns true if ... is valid.
 33        /// </summary>
 34        /// <value>
 35        ///   <c>true</c> if this point is valid; otherwise, <c>false</c>.
 36        /// </value>
 337        public bool IsValid { get; set; } = true;
 38
 39        /// <summary>
 40        /// Initializes a new instance of the <see cref="Vector2"/> class.
 41        /// </summary>
 042        public Vector2() => Set(0, 0);
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="Vector2"/> class.
 46        /// </summary>
 47        /// <param name="x">The x.</param>
 48        /// <param name="y">The y.</param>
 649        public Vector2(float x, float y) => Set(x, y);
 50
 51        /// <summary>
 52        /// Initializes a new instance of the <see cref="Vector2"/> class.
 53        /// </summary>
 54        /// <param name="base2">The base2.</param>
 055        public Vector2(IBase2 base2) => Set(base2);
 56
 57        /// <inheritdoc />
 58        /// <summary>
 59        /// Copies the values from the input to [this] instance.
 60        /// </summary>
 61        /// <param name="base2">The base2.</param>
 062        public void Set(IBase2 base2) => Set(base2.X, base2.Y);
 63
 64        /// <inheritdoc />
 65        /// <summary>
 66        /// Creates a copy of [this].
 67        /// </summary>
 68        /// <returns></returns>
 069        public IBase2 Copy() => new Vector2(this);
 70
 71        /// <summary>
 72        /// Gets the length.
 73        /// </summary>
 74        /// <value>
 75        /// The length.
 76        /// </value>
 077        public float Length => (float)System.Math.Sqrt(X * X + Y * Y);
 78
 79        /// <summary>
 80        /// Gets the normalized copy.
 81        /// </summary>
 82        /// <value>
 83        /// The normalized copy.
 84        /// </value>
 085        public Vector2 NormalizedCopy => Length > 0 ? new Vector2(X / Length, Y / Length) : new Vector2();
 86
 87        /// <summary>
 88        /// Adds the specified vector.
 89        /// </summary>
 90        /// <param name="vector">The vector.</param>
 91        /// <returns></returns>
 092        public Vector2 Add(Vector2 vector) => new Vector2(X + vector.X, Y + vector.Y);
 93
 94        /// <summary>
 95        /// Multiplies this vector with the specified vector.
 96        /// </summary>
 97        /// <param name="vector">The vector.</param>
 98        /// <returns></returns>
 099        public float Multiply(Vector2 vector) => X * vector.X + Y * vector.Y;
 100
 101        /// <summary>
 102        /// Multiplies the specified value to this vector.
 103        /// </summary>
 104        /// <param name="value">The value.</param>
 105        public Vector2 Multiply(float value)
 0106        {
 0107            X *= value;
 0108            Y *= value;
 0109            return this;
 0110        }
 111
 112        /// <summary>
 113        /// Calculates the angle between this vector and a specified vector.
 114        /// </summary>
 115        /// <param name="vector">The vector.</param>
 116        /// <returns></returns>
 0117        public float AngleBetween(Vector2 vector) => Multiply(vector) / (Length * vector.Length);
 118
 119        /// <inheritdoc />
 120        /// <summary>
 121        /// Sets the x and y value.
 122        /// </summary>
 123        /// <param name="x">The x value.</param>
 124        /// <param name="y">The y value.</param>
 125        public void Set(float x, float y)
 3126        {
 3127            X = x;
 3128            Y = y;
 3129        }
 130
 131        /// <inheritdoc />
 132        /// <summary>
 133        /// Equalses the specified base2.
 134        /// </summary>
 135        /// <param name="base2">The base2.</param>
 136        /// <returns></returns>
 0137        public bool Equals(IBase2 base2) => base2 != null && Equals(X, base2.X) && Equals(Y, base2.Y);
 138
 139        /// <summary>
 140        /// Returns a <see cref="string" /> that represents [this] instance.
 141        /// </summary>
 142        /// <returns>
 143        /// A <see cref="string" /> that represents [this] instance.
 144        /// </returns>
 0145        public override string ToString() => IsValid ? $"X: {X}; Y: {Y}" : "invalid";
 146    }
 147}