public T ManhattanDistance(GenericPosition2D <T> p = new GenericPosition2D <T>())
 {
     return(Extensions.Add(
                Extensions.Abs(Extensions.Subtract(x, p.x)),
                Extensions.Abs(Extensions.Subtract(y, p.y))
                ));
 }
        public static GenericPosition2D <T> operator +(GenericPosition2D <T> p1, GenericPosition2D <T> p2)
        {
            GenericPosition2D <T> p = new GenericPosition2D <T>(p1);

            p.x = Extensions.Add(p.x, p2.x);
            p.y = Extensions.Add(p.y, p2.y);
            return(p);
        }
        public static GenericPosition2D <T> operator /(GenericPosition2D <T> p1, T k)
        {
            GenericPosition2D <T> p = new GenericPosition2D <T>(p1);

            p.x = Extensions.Divide(p.x, k);
            p.y = Extensions.Divide(p.y, k);
            return(p);
        }
        public static GenericPosition2D <T> operator *(GenericPosition2D <T> p1, T k)
        {
            GenericPosition2D <T> p = new GenericPosition2D <T>(p1);

            p.x = Extensions.Multiply(p.x, k);
            p.y = Extensions.Multiply(p.y, k);
            return(p);
        }
        public static GenericPosition2D <T> operator -(GenericPosition2D <T> p1, T k)
        {
            GenericPosition2D <T> p = new GenericPosition2D <T>(p1);

            p.x = Extensions.Subtract(p.x, k);
            p.y = Extensions.Subtract(p.y, k);
            return(p);
        }
 public char this[GenericPosition2D <int> p]
 {
     get
     {
         return(data[p.x, p.y]);
     }
     set
     {
         data[p.x, p.y] = value;
     }
 }
 public Map(int w, int h, GenericPosition2D <int> p, char fill = '\0')
 {
     width  = w;
     height = h;
     pos    = p;
     data   = new char[w, h];
     for (int i = 0; i < w * h; i++)
     {
         data[i % w, i / w] = fill;
     }
 }
 public int CompareTo(GenericPosition2D <T> p)    // Reading order
 {
     if (!EqualityComparer <T> .Default.Equals(y, p.y))
     {
         return(Comparer <T> .Default.Compare(y, p.y));
     }
     else
     {
         return(Comparer <T> .Default.Compare(x, p.x));
     }
 }
 public Map(Map m)
 {
     width  = m.width;
     height = m.height;
     pos    = m.pos;
     data   = new char[width, height];
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             data[x, y] = m.data[x, y];
         }
     }
 }
Esempio n. 10
0
        public void Expand(int top, int right, int bottom, int left, char fill)
        {
            int w = left + right + width;
            int h = top + bottom + height;
            GenericPosition2D <int> s = new GenericPosition2D <int>(pos.x + left, pos.y + top);
            Map m = new Map(w, h, s, fill);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    m.data[x + left, y + top] = data[x, y];
                }
            }
            width  = m.width;
            height = m.height;
            pos    = m.pos;
            data   = m.data;
        }
Esempio n. 11
0
        // Rotates pos n steps clock-wize around center
        public static GenericPosition2D <T> Rotate4Steps(GenericPosition2D <T> pos, int n, GenericPosition2D <T> center = new GenericPosition2D <T>())
        {
            GenericPosition2D <T> p = new GenericPosition2D <T>(pos - center);
            GenericPosition2D <T> r = new GenericPosition2D <T>(p);

            n = Utils.Modulo(n, 4);
            if (n == 1)
            {
                r.x = p.y;
                r.y = Extensions.Subtract(default(T), p.x);
            }
            else if (n == 2)
            {
                r.x = Extensions.Subtract(default(T), p.x);
                r.y = Extensions.Subtract(default(T), p.y);
            }
            else if (n == 3)
            {
                r.x = Extensions.Subtract(default(T), p.y);
                r.y = p.x;
            }
            return(r + center);
        }
Esempio n. 12
0
 public bool Equals(GenericPosition2D <T> p)
 {
     return(EqualityComparer <T> .Default.Equals(x, p.x) && EqualityComparer <T> .Default.Equals(y, p.y));
 }
Esempio n. 13
0
 public bool HasPosition(GenericPosition2D <int> p)
 {
     return(p.x >= 0 && p.x < width && p.y >= 0 && p.y < height);
 }
Esempio n. 14
0
 public GenericPosition2D(GenericPosition2D <T> p)
 {
     x = p.x;
     y = p.y;
 }