Exemple #1
0
        public static bool FindClosestRect(int needleWidth, int needleHeight, int needleValue, LogicIntArray2 haystack, LogicPoint2 start, LogicPoint2 closest)
        {
            Debugger.doAssert(haystack != null, "blit haystack null");
            Debugger.doAssert(start != null, "findClosest start null");
            Debugger.doAssert(closest != null, "blit closest null");

            int dWidth  = haystack.width - needleWidth;
            int dHeight = haystack.height - needleHeight;

            int distMin = int.MaxValue;

            for (int y = 0; y <= dHeight; ++y)
            {
                for (int x = 0; x <= dWidth; ++x)
                {
                    int dx   = x - start.x;
                    int dy   = y - start.y;
                    int dist = dx * dx + dy * dy;

                    if (dist < distMin)
                    {
                        bool equal = true;
                        for (int h = 0; h < needleHeight && equal; ++h)
                        {
                            for (int w = 0; w < needleWidth && equal; ++w)
                            {
                                equal = haystack.Get(x + w, y + h) == needleValue;
                            }
                        }

                        if (equal)
                        {
                            distMin   = dist;
                            closest.x = x;
                            closest.y = y;
                        }
                    }
                }
            }

            return(distMin < int.MaxValue);
        }
Exemple #2
0
 public LogicPoint2 Div(LogicPoint2 other)
 {
     return(new LogicPoint2(x / other.x, y / other.y));
 }
Exemple #3
0
 public LogicPoint2 Cross(LogicPoint2 other)
 {
     return(new LogicPoint2(x * other.y, y * other.x));
 }
Exemple #4
0
 public LogicPoint2 Mul(LogicPoint2 other)
 {
     return(new LogicPoint2(x * other.x, y * other.y));
 }
Exemple #5
0
 public LogicPoint2 Sub(LogicPoint2 other)
 {
     return(new LogicPoint2(x - other.x, y - other.y));
 }
Exemple #6
0
 public LogicPoint2 Add(LogicPoint2 other)
 {
     return(new LogicPoint2(x + other.x, y + other.y));
 }
Exemple #7
0
 public LogicPoint2(LogicPoint2 other)
 {
     x = other.x;
     y = other.y;
 }
Exemple #8
0
 public bool Equals(LogicPoint2 other)
 {
     return(other.x == x && other.y == y);
 }