Ejemplo n.º 1
0
        static public List <HexCell> HexLinedraw(HexCell a, HexCell b)
        {
            int            N       = HexCell.Distance(a, b);
            FractionalHex  a_nudge = new FractionalHex(a.q + 0.000001, a.r + 0.000001, a.s - 0.000002);
            FractionalHex  b_nudge = new FractionalHex(b.q + 0.000001, b.r + 0.000001, b.s - 0.000002);
            List <HexCell> results = new List <HexCell> {
            };
            double step            = 1.0 / Math.Max(N, 1);

            for (int i = 0; i <= N; i++)
            {
                results.Add(FractionalHex.HexRound(FractionalHex.HexLerp(a_nudge, b_nudge, step * i)));
            }
            return(results);
        }
Ejemplo n.º 2
0
        static public HexCell HexRound(FractionalHex h)
        {
            int    q      = (int)(Math.Round(h.q));
            int    r      = (int)(Math.Round(h.r));
            int    s      = (int)(Math.Round(h.s));
            double q_diff = Math.Abs(q - h.q);
            double r_diff = Math.Abs(r - h.r);
            double s_diff = Math.Abs(s - h.s);

            if (q_diff > r_diff && q_diff > s_diff)
            {
                q = -r - s;
            }
            else
            if (r_diff > s_diff)
            {
                r = -q - s;
            }
            else
            {
                s = -q - r;
            }
            return(new HexCell(q, r, s));
        }
Ejemplo n.º 3
0
 static public FractionalHex HexLerp(FractionalHex a, FractionalHex b, double t)
 {
     return(new FractionalHex(a.q * (1 - t) + b.q * t, a.r * (1 - t) + b.r * t, a.s * (1 - t) + b.s * t));
 }