Пример #1
0
                public void CanTransformZero()
                {
                    Layout layout = Layout.Pointy(new Vector2(100f), Vector2.Zero);
                    var    hexF   = new HexF(0f, 0f, 0f);

                    Assert.That(layout.HexToScreen(hexF), Is.EqualTo(Vector2.Zero));
                }
Пример #2
0
            public void CanBeAddedToHexF()
            {
                var hexF        = new HexF(0.5f, 0f, -0.5f);
                var anotherHexF = new HexF(-1f, -2f, 3f);
                var result      = new HexF(-0.5f, -2f, 2.5f);

                Assert.That(hexF + anotherHexF == result);
            }
Пример #3
0
            public void CanBeReverseAddedToHex()
            {
                var hex    = new Hex(-1, -2, 3);
                var hexF   = new HexF(0.5f, 0f, -0.5f);
                var result = new HexF(-0.5f, -2f, 2.5f);

                Assert.That(hex + hexF == result);
            }
Пример #4
0
            public void DoesNotEqualAnotherHexWithDifferentCoords()
            {
                var hexF        = new HexF(1, 2, -3);
                var anotherHexF = new HexF(1, 1, -2);

                Assert.That(hexF != anotherHexF);
                Assert.That(!hexF.Equals(anotherHexF));
            }
Пример #5
0
            public void HasCoords()
            {
                var hexF = new HexF(1.4, 2.3, -3.7);

                Assert.That(hexF.Q, Is.EqualTo(1.4).Within(Tolerance));
                Assert.That(hexF.R, Is.EqualTo(2.3).Within(Tolerance));
                Assert.That(hexF.S, Is.EqualTo(-3.7).Within(Tolerance));
            }
Пример #6
0
            public void CanBeInitializedByTwoCoords()
            {
                var hexF = new HexF(-1.4, -2.3);

                Assert.That(hexF.Q, Is.EqualTo(-1.4).Within(Tolerance));
                Assert.That(hexF.R, Is.EqualTo(-2.3).Within(Tolerance));
                Assert.That(hexF.S, Is.EqualTo(3.7).Within(Tolerance));
            }
Пример #7
0
            public void EqualsToAnotherHexWithSameCoords()
            {
                var hexF        = new HexF(1, 2, -3);
                var anotherHexF = new HexF(1, 2, -3);

                Assert.That(hexF == anotherHexF);
                Assert.That(hexF.Equals(anotherHexF));
            }
Пример #8
0
            public void HasValidCornerOffset(int dir, float resultQ, float resultR, float resultS)
            {
                HexF offset = Hex.CornerOffset(dir);

                Assert.That(offset.Q, Is.EqualTo(resultQ).Within(0.001f));
                Assert.That(offset.R, Is.EqualTo(resultR).Within(0.001f));
                Assert.That(offset.S, Is.EqualTo(resultS).Within(0.001f));
            }
Пример #9
0
            public void CanTransformFlatHex(float x, float y, int resultQ, int resultR, int resultS)
            {
                Layout layout = Layout.Flat(new Vector2(100f), Vector2.Zero);
                HexF   hex    = layout.ScreenToHex(new Vector2(x, y));

                Assert.That(hex.Q, Is.EqualTo(resultQ).Within(0.001f));
                Assert.That(hex.R, Is.EqualTo(resultR).Within(0.001f));
                Assert.That(hex.S, Is.EqualTo(resultS).Within(0.001f));
            }
Пример #10
0
            public void CanBeIterated()
            {
                var hexF = new HexF(1, 2, -3);
                var list = new List <float> {
                    1, 2, -3
                };

                Assert.That(hexF.ToList().SequenceEqual(list));
            }
Пример #11
0
            public void CanBeInitializedFromHexF()
            {
                var hexF = new HexF(-1.5f, 4.5f);
                Hex hex  = Hex.FromHexF(hexF);

                Assert.That(hex.Q, Is.EqualTo(-2));
                Assert.That(hex.R, Is.EqualTo(4));
                Assert.That(hex.S, Is.EqualTo(-2));
            }
Пример #12
0
            public void CanBeInitializedByVector2()
            {
                var vector = new Vector2(-1.4f, -2.3f);
                var hexF   = new HexF(vector);

                Assert.That(hexF.Q, Is.EqualTo(-1.4f).Within(Tolerance));
                Assert.That(hexF.R, Is.EqualTo(-2.3f).Within(Tolerance));
                Assert.That(hexF.S, Is.EqualTo(3.7f).Within(Tolerance));
            }
Пример #13
0
            public void CanBeBracketsAccessed()
            {
                var hexF = new HexF(1, 2, -3);

                Assert.That(hexF[0], Is.EqualTo(1f).Within(Tolerance));
                Assert.That(hexF[1], Is.EqualTo(2f).Within(Tolerance));
                Assert.That(hexF[2], Is.EqualTo(-3f).Within(Tolerance));
                Assert.That(hexF.Length == 3);
            }
Пример #14
0
            public void CanBeInitializedFromHex()
            {
                var hex  = new Hex(-1, -2);
                var hexF = new HexF(hex);

                Assert.That(hexF.Q, Is.EqualTo(-1f).Within(Tolerance));
                Assert.That(hexF.R, Is.EqualTo(-2f).Within(Tolerance));
                Assert.That(hexF.S, Is.EqualTo(3f).Within(Tolerance));
            }
Пример #15
0
            public void HasValidCorner(int q, int r, int s, int dir, float resultQ, float resultR,
                                       float resultS)
            {
                var  hex    = new Hex(q, r, s);
                HexF corner = hex.Corner(dir);

                Assert.That(corner.Q, Is.EqualTo(resultQ).Within(0.001f));
                Assert.That(corner.R, Is.EqualTo(resultR).Within(0.001f));
                Assert.That(corner.S, Is.EqualTo(resultS).Within(0.001f));
            }
Пример #16
0
                public void CanTransformWithSize(float sizeX, float sizeY, float resultX,
                                                 float resultY)
                {
                    Layout  layout       = Layout.Pointy(new Vector2(sizeX, sizeY), Vector2.Zero);
                    var     hexF         = new HexF(1.1f, 0.9f, -2f);
                    Vector2 screenVector = layout.HexToScreen(hexF);

                    Assert.That(screenVector.X, Is.EqualTo(resultX).Within(0.001f));
                    Assert.That(screenVector.Y, Is.EqualTo(resultY).Within(0.001f));
                }
Пример #17
0
            public void CanBeHashed()
            {
                var dict = new Dictionary <HexF, int>
                {
                    [new HexF(1, 1, -2)] = 1
                };
                var hexF = new HexF(1, 1, -2);

                Assert.That(dict[hexF] == 1);
            }
Пример #18
0
                public void CanTransformFlatHex(float q, float r, float s, float resultX, float
                                                resultY)
                {
                    Layout  layout       = Layout.Flat(Vector2.One, Vector2.Zero);
                    var     hexF         = new HexF(q, r, s);
                    Vector2 screenVector = layout.HexToScreen(hexF);

                    Assert.That(screenVector.X, Is.EqualTo(resultX).Within(0.001f));
                    Assert.That(screenVector.Y, Is.EqualTo(resultY).Within(0.001f));
                }
Пример #19
0
                public void CanTransformWithOffset(float offsetX, float offsetY, float resultX,
                                                   float resultY)
                {
                    Layout layout =
                        Layout.Pointy(new Vector2(100f, 100f), new Vector2(offsetX, offsetY));
                    var     hexF         = new HexF(1.1f, 0.9f, -2f);
                    Vector2 screenVector = layout.HexToScreen(hexF);

                    Assert.That(screenVector.X, Is.EqualTo(resultX).Within(0.001f));
                    Assert.That(screenVector.Y, Is.EqualTo(resultY).Within(0.001f));
                }
Пример #20
0
            public void CanTransformWithSize(float sizeX, float sizeY, float resultQ, float resultR,
                                             float resultS)
            {
                Layout layout = Layout.Pointy(new Vector2(sizeX, sizeY), Vector2.Zero);
                var    vector = new Vector2(10, -20);
                HexF   hex    = layout.ScreenToHex(vector);

                Assert.That(hex.Q, Is.EqualTo(resultQ).Within(0.001f));
                Assert.That(hex.R, Is.EqualTo(resultR).Within(0.001f));
                Assert.That(hex.S, Is.EqualTo(resultS).Within(0.001f));
            }
Пример #21
0
            public void CanTransformWithOffset(float offsetX, float offsetY, float resultQ,
                                               float resultR,
                                               float resultS)
            {
                Layout layout =
                    Layout.Pointy(new Vector2(0.1f, 0.1f), new Vector2(offsetX, offsetY));
                var  vector = new Vector2(10, -20);
                HexF hex    = layout.ScreenToHex(vector);

                Assert.That(hex.Q, Is.EqualTo(resultQ).Within(0.001f));
                Assert.That(hex.R, Is.EqualTo(resultR).Within(0.001f));
                Assert.That(hex.S, Is.EqualTo(resultS).Within(0.001f));
            }
Пример #22
0
            public void HasStringRepresentation()
            {
                var hexF = new HexF(1, 2, -3);

                Assert.That(hexF.ToString(), Is.EqualTo("Hex(1, 2, -3)"));
            }