Ejemplo n.º 1
0
        public void TestAddition()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 9)
            };

            var vectorB = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.D, 7),
                SecondaryComponent = new HexVectorComponent(HexAxis.E, 3),
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 2)
            };

            var result = _utilityLibrary.AddVectors(vectorA, vectorB);

            result.Should().NotBeNull("Result must be valid.");

            result.PrimaryComponent.Direction.Should().Be(HexAxis.F);
            result.PrimaryComponent.Magnitude.Should().Be(2);

            result.SecondaryComponent.Direction.Should().Be(HexAxis.E);
            result.SecondaryComponent.Magnitude.Should().Be(1);

            result.VerticalComponent.Direction.Should().Be(HexAxis.Up);
            result.VerticalComponent.Magnitude.Should().Be(2);
        }
Ejemplo n.º 2
0
        public void TestSubstraction()
        {
            // Test creating crossing vector. As per example in the rulebook.
            var myVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.F, 9),
                SecondaryComponent = new HexVectorComponent(HexAxis.E, 5)
            };

            var tartgetVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.C, 6),
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 4)
            };

            var result = _utilityLibrary.SubstractVectors(tartgetVelocity, myVelocity);

            result.Should().NotBeNull("Result must be valid.");

            result.PrimaryComponent.Direction.Should().Be(HexAxis.C);
            result.PrimaryComponent.Magnitude.Should().Be(15);

            result.SecondaryComponent.Direction.Should().Be(HexAxis.B);
            result.SecondaryComponent.Magnitude.Should().Be(5);

            result.VerticalComponent.Direction.Should().Be(HexAxis.Up);
            result.VerticalComponent.Magnitude.Should().Be(4);
        }
Ejemplo n.º 3
0
        public void RangeAltitudeTableTest()
        {
            var rAlt = ServiceFactory.Library.RangeAltitudeTable;

            var hexVectorA = new HexVector(HexAxis.A, 12, HexAxis.B, 0, HexAxis.Up, 0);
            rAlt.GetDistance(hexVectorA).Should().Be(12);
            rAlt.GetRing(hexVectorA).Should().Be(AvidRing.Ember);

            var hexVectorB = new HexVector(HexAxis.A, 12, HexAxis.B, 0, HexAxis.Up, 4);
            rAlt.GetDistance(hexVectorB).Should().Be(12);
            rAlt.GetRing(hexVectorB).Should().Be(AvidRing.Blue);

            var hexVectorC = new HexVector(HexAxis.A, 12, HexAxis.B, 0, HexAxis.Up, 18);
            rAlt.GetDistance(hexVectorC).Should().Be(21);
            rAlt.GetRing(hexVectorC).Should().Be(AvidRing.Green);

            var hexVectorD = new HexVector(HexAxis.A, 4, HexAxis.B, 0, HexAxis.Up, 23);
            rAlt.GetDistance(hexVectorD).Should().Be(23);
            rAlt.GetRing(hexVectorD).Should().Be(AvidRing.Magenta);

            var hexVectorE = new HexVector(HexAxis.A, 48, HexAxis.B, 0, HexAxis.Up, 10);
            rAlt.GetDistance(hexVectorE).Should().Be(49);
            rAlt.GetRing(hexVectorE).Should().Be(AvidRing.Ember);

            var hexVectorF = new HexVector(HexAxis.A, 48, HexAxis.B, 0, HexAxis.Up, 13);
            rAlt.GetDistance(hexVectorF).Should().Be(49);
            rAlt.GetRing(hexVectorF).Should().Be(AvidRing.Blue);

            var hexVectorG = new HexVector(HexAxis.A, 35, HexAxis.B, 0, HexAxis.Up, 36);
            rAlt.GetDistance(hexVectorG).Should().Be(50);
            rAlt.GetRing(hexVectorG).Should().Be(AvidRing.Green);
        }
        public void TestVectorEquality()
        {
            var vectorA = new HexVector(HexAxis.A, 2, HexAxis.B, 3, HexAxis.Up, 1);
            var vectorB = new HexVector(HexAxis.A, 2, HexAxis.D, 3, HexAxis.Down, 2);
            var vectorC = new HexVector(HexAxis.A, 2, HexAxis.B, 3, HexAxis.Up, 1);

            vectorA.Equals(vectorB).Should().BeFalse();
            (vectorA == vectorC).Should().BeFalse();
            vectorA.Equals(vectorC).Should().BeTrue();
            vectorA.Equals(HexVector.Zero).Should().BeFalse();
            HexVector.Zero.Equals(null).Should().BeTrue();
        }
Ejemplo n.º 5
0
        public void EdgeFacingConversion()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 12),
                SecondaryComponent = new HexVectorComponent(HexAxis.F, 2)
            };

            var result = ServiceFactory.Library.AvidCalculator.ProjectVectorToAvid(vectorA);

            result.Should().NotBeNull();
            result.AbovePlane.Should().BeTrue();
            result.Ring.Should().Be(AvidRing.Ember);
            result.Direction.Should().Be(AvidDirection.A);
            result.Magnitude.Should().Be(14);
        }
Ejemplo n.º 6
0
        public void GreenRingFacingConversion()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 7),
                SecondaryComponent = new HexVectorComponent(HexAxis.F, 5),
                VerticalComponent = new HexVectorComponent(HexAxis.Down, 18)
            };

            var result = ServiceFactory.Library.AvidCalculator.ProjectVectorToAvid(vectorA);

            result.Should().NotBeNull();
            result.AbovePlane.Should().BeFalse();
            result.Ring.Should().Be(AvidRing.Green);
            result.Direction.Should().Be(AvidDirection.FA);
            result.Magnitude.Should().Be(21);
        }
Ejemplo n.º 7
0
        public AvidVector ProjectVectorToAvid(HexVector vector)
        {
            var result = new AvidVector
            {
                Magnitude = _rangeAltitudeTable.GetDistance(vector)
            };

            if (result.Magnitude == 0)
            {
                return result;
            }

            result.Ring = _rangeAltitudeTable.GetRing(vector);
            result.AbovePlane = result.Ring == AvidRing.Ember || vector.VerticalComponent.Direction == HexAxis.Up;
            result.Direction = CalculateDirection(vector, result.Ring);

            return result;
        }
Ejemplo n.º 8
0
        public AvidRing GetRing(HexVector vector)
        {
            int horizontalDistance = vector.PlanarProjection;
            int verticalDistance = vector.VerticalComponent.Magnitude;
            if (horizontalDistance >= 4 * verticalDistance)
            {
                return AvidRing.Ember;
            }

            if (horizontalDistance >= verticalDistance)
            {
                return AvidRing.Blue;
            }

            if (4 * horizontalDistance <= verticalDistance)
            {
                return AvidRing.Magenta;
            }

            return AvidRing.Green;
        }
Ejemplo n.º 9
0
        private AvidDirection CalculateDirection(HexVector vector, AvidRing ring)
        {
            if (ring == AvidRing.Magenta)
            {
                return AvidDirection.Undefined;
            }

            if (vector.PlanarProjection == 0)
            {
                throw new ArithmeticException("The ring is not magenta, but planar projection is zero.");
            }

            if (vector.PrimaryComponent.Direction == vector.SecondaryComponent.Direction && vector.SecondaryComponent.Magnitude != 0)
            {
                throw new ArithmeticException("Primary and secondary vectors are both positive but are in the same direction.");
            }

            int primaryMagnitude = vector.PrimaryComponent.Magnitude;
            int secondaryMagnitude = vector.SecondaryComponent.Magnitude;

            if (primaryMagnitude < secondaryMagnitude)
            {
                throw new ArithmeticException("Secondary vector component should not be greater than the primary.");
            }

            if (IsSeeingThroughHexEdge(primaryMagnitude, secondaryMagnitude))
            {
                return (AvidDirection)(((byte)vector.PrimaryComponent.Direction) * 2 - 1);
            }

            if ((vector.PrimaryComponent.Direction == HexAxis.A && vector.SecondaryComponent.Direction == HexAxis.F) ||
                (vector.PrimaryComponent.Direction == HexAxis.F && vector.SecondaryComponent.Direction == HexAxis.A))
            {
                return AvidDirection.FA;
            }

            return (AvidDirection)(((byte)vector.PrimaryComponent.Direction) + ((byte)vector.SecondaryComponent.Direction) - 1);
        }
Ejemplo n.º 10
0
        public void TestConsolidation()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.C, 5),
                SecondaryComponent = new HexVectorComponent(HexAxis.E, 9)
            };
            _utilityLibrary.ConsolidateVector(vectorA);
            TestChecksUtility.CheckComponent(vectorA.PrimaryComponent, HexAxis.D, 5);
            TestChecksUtility.CheckComponent(vectorA.SecondaryComponent, HexAxis.E, 4);

            var vectorB = new RawHexVector();
            vectorB.AddComponent(HexAxis.A, 1);
            vectorB.AddComponent(HexAxis.B, 4);
            vectorB.AddComponent(HexAxis.C, 3);
            vectorB.AddComponent(HexAxis.E, 7);
            vectorB.AddComponent(HexAxis.Up, 2);
            vectorB.AddComponent(HexAxis.Up, 3);
            vectorB.AddComponent(HexAxis.Down, 5);
            var resultB = _utilityLibrary.ConsolidateAndCopyVector(vectorB);
            TestChecksUtility.CheckComponent(resultB.PrimaryComponent, HexAxis.D, 2);
            resultB.SecondaryComponent.Should().Be(HexVectorComponent.Zero);
            resultB.VerticalComponent.Should().Be(HexVectorComponent.Zero);
        }
Ejemplo n.º 11
0
        public void TopFacingConversion()
        {
            var vectorA = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 3),
                SecondaryComponent = new HexVectorComponent(HexAxis.B, 2),
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 27)
            };

            var result = ServiceFactory.Library.AvidCalculator.ProjectVectorToAvid(vectorA);

            result.Should().NotBeNull();
            result.AbovePlane.Should().BeTrue();
            result.Ring.Should().Be(AvidRing.Magenta);
            result.Direction.Should().Be(AvidDirection.Undefined);
            result.Magnitude.Should().Be(27);
        }
Ejemplo n.º 12
0
        public void CheckBacktracking4()
        {
            var observerVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 1),
                SecondaryComponent = HexVectorComponent.Zero,
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 3)
            };

            var observedVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.B, 1),
                SecondaryComponent = HexVectorComponent.Zero,
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 14)
            };
            var window = _calculator.GetVectorFromBacktracking(observerVelocity, observedVelocity);
            TestChecksUtility.CheckAvidWindow(window, AvidDirection.Undefined, AvidRing.Magenta, false);
        }
Ejemplo n.º 13
0
        public void CheckBacktracking3()
        {
            var observerVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 5),
                SecondaryComponent = new HexVectorComponent(HexAxis.B, 2),
                VerticalComponent = new HexVectorComponent(HexAxis.Down, 1)
            };

            var observedVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 4),
                SecondaryComponent = new HexVectorComponent(HexAxis.C, 2),
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 5)
            };
            var window = _calculator.GetVectorFromBacktracking(observerVelocity, observedVelocity);
            TestChecksUtility.CheckAvidWindow(window, AvidDirection.A, AvidRing.Green, false);
        }
Ejemplo n.º 14
0
        public void CheckBacktracking2()
        {
            var observerVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 6),
                SecondaryComponent = new HexVectorComponent(HexAxis.B, 5),
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 7)
            };

            var observedVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.C, 6),
                SecondaryComponent = new HexVectorComponent(HexAxis.B, 4),
                VerticalComponent = new HexVectorComponent(HexAxis.Up, 1)
            };
            var window = _calculator.GetVectorFromBacktracking(observerVelocity, observedVelocity);
            TestChecksUtility.CheckAvidWindow(window, AvidDirection.FA, AvidRing.Blue, true);
        }
Ejemplo n.º 15
0
        public void CheckBacktracking1()
        {
            var observerVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.A, 6),
                SecondaryComponent = HexVectorComponent.Zero,
                VerticalComponent = HexVectorComponent.Zero
            };

            var observedVelocity = new HexVector
            {
                PrimaryComponent = new HexVectorComponent(HexAxis.B, 5),
                SecondaryComponent = HexVectorComponent.Zero,
                VerticalComponent = HexVectorComponent.Zero
            };
            var window = _calculator.GetVectorFromBacktracking(observerVelocity, observedVelocity);
            TestChecksUtility.CheckAvidWindow(window, AvidDirection.F, AvidRing.Ember, true);
        }
Ejemplo n.º 16
0
 public int GetDistance(HexVector vector)
 {
     return (int)Math.Floor(Math.Sqrt(Math.Pow(vector.PlanarProjection, 2) + Math.Pow(vector.VerticalComponent.Magnitude, 2)));
 }
Ejemplo n.º 17
0
        private void CheckVector(HexAxis primaryAxis, int primaryMag, HexAxis secondaryAxis, int secondaryMag, HexAxis verticalAxis, int verticalMag)
        {
            var vectorA = new HexVector(primaryAxis, primaryMag, secondaryAxis, secondaryMag, verticalAxis, verticalMag);

            var result = ServiceFactory.Library.AvidCalculator.ProjectVectorToAvid(vectorA);

            result.Should().NotBeNull();
            result.AbovePlane.Should().BeTrue();
            result.Ring.Should().Be(AvidRing.Magenta);
            result.Direction.Should().Be(AvidDirection.Undefined);
            result.Magnitude.Should().Be(27);
        }