Ejemplo n.º 1
0
        static public void TestHexRound()
        {
            FractionalHex a = new FractionalHex(0.0, 0.0, 0.0);
            FractionalHex b = new FractionalHex(1.0, -1.0, 0.0);
            FractionalHex c = new FractionalHex(0.0, -1.0, 1.0);

            Tests.EqualHex("hex_round 1", new Hex(5, -10, 5), new FractionalHex(0.0, 0.0, 0.0).HexLerp(new FractionalHex(10.0, -20.0, 10.0), 0.5).HexRound());
            Tests.EqualHex("hex_round 2", a.HexRound(), a.HexLerp(b, 0.499).HexRound());
            Tests.EqualHex("hex_round 3", b.HexRound(), a.HexLerp(b, 0.501).HexRound());
            Tests.EqualHex("hex_round 4", a.HexRound(), new FractionalHex(a.q * 0.4 + b.q * 0.3 + c.q * 0.3, a.r * 0.4 + b.r * 0.3 + c.r * 0.3, a.s * 0.4 + b.s * 0.3 + c.s * 0.3).HexRound());
            Tests.EqualHex("hex_round 5", c.HexRound(), new FractionalHex(a.q * 0.3 + b.q * 0.3 + c.q * 0.4, a.r * 0.3 + b.r * 0.3 + c.r * 0.4, a.s * 0.3 + b.s * 0.3 + c.s * 0.4).HexRound());
        }
Ejemplo n.º 2
0
        static public List <Hex> HexLinedraw(Hex a, Hex b)
        {
            int           N       = a.Distance(b);
            FractionalHex a_nudge = new FractionalHex(a.q + 1e-06, a.r + 1e-06, a.s - 2e-06);
            FractionalHex b_nudge = new FractionalHex(b.q + 1e-06, b.r + 1e-06, b.s - 2e-06);
            List <Hex>    results = new List <Hex> {
            };
            double step           = 1.0 / Math.Max(N, 1);

            for (int i = 0; i <= N; i++)
            {
                results.Add(a_nudge.HexLerp(b_nudge, step * i).HexRound());
            }
            return(results);
        }
Ejemplo n.º 3
0
 static public void TestHexLinedraw()
 {
     Tests.EqualHexArray("hex_linedraw", new List <Hex> {
         new Hex(0, 0, 0), new Hex(0, -1, 1), new Hex(0, -2, 2), new Hex(1, -3, 2), new Hex(1, -4, 3), new Hex(1, -5, 4)
     }, FractionalHex.HexLinedraw(new Hex(0, 0, 0), new Hex(1, -5, 4)));
 }
Ejemplo n.º 4
0
 public FractionalHex HexLerp(FractionalHex b, double t)
 {
     return(new FractionalHex(q * (1.0 - t) + b.q * t, r * (1.0 - t) + b.r * t, s * (1.0 - t) + b.s * t));
 }