Пример #1
0
 public static HexFacing Apply(this HexFacing facing, HexRotation rot)
 {
     if (facing == HexFacing.bad)
     {
         return(HexFacing.bad);
     }
     else
     {
         return((HexFacing)NumUtil.WrapPos((int)facing - rot.CWcount, 6));
     }
 }
Пример #2
0
        public HexCoords Rotate(HexCoords center, HexRotation rot)
        {
            HexCoords d = this - center;

            switch (rot.CWcount)
            {
            default:
            case 0: return(center + d);                     //          x,  y,      z

            case 1: return(center + new HexCoords(-z, -x)); // -y

            case 2: return(center + new HexCoords(y, z));   //  x

            case 3: return(center + new HexCoords(-x, -y)); // -z

            case 4: return(center + new HexCoords(z, x));   //  y

            case 5: return(center + new HexCoords(-y, -z)); // -x
            }
        }
Пример #3
0
        public IEnumerable <HexCoords> Arc(uint radius, HexFacing begin, HexFacing end)
        {
            HexCoords cursor = this + (begin.ToOffset() * (int)radius);

            // Yielding the initial cursor position is unique to arcs,
            // and is why this code works at radius 0 while rings do not.
            yield return(cursor);

            // We need to track our travel facing.
            // When following a circle, we start at the southwest corner heading north.
            // Southwest to north is rotating CW twice.
            // Any corner you start at, your travel on that side will be CW twice.
            HexRotation turnIntoSide = new HexRotation(2);

            foreach (HexFacing facing in begin.Rotate(2).CompassTurnCW(end.Rotate(1)))
            {
                for (int idx = 0; idx < radius; idx++)
                {
                    cursor += facing;
                    yield return(cursor);
                }
            }
        }
Пример #4
0
 public static IEnumerable <HexFacing> CompassTurnCW(this HexFacing facing, HexRotation rot)
 {
     return(facing.CompassTurnCW(facing.Apply(rot)));
 }
Пример #5
0
 public HexCoords Rotate(HexRotation rot)
 {
     return(Rotate(HexCoords.O, rot));
 }