public static void Blit(LogicIntArray2 s, int sX, int sY, int width, int height, LogicIntArray2 d, int dX, int dY) { Debugger.doAssert(d != null, "blit Destination null"); Debugger.doAssert(s != null, "blit Source null"); switch (GetBlitMethod()) { case BlitMethod.Add: { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int value = s.Get(sX + x, sY + y) + d.Get(dX + x, dY + y); d.Set(dX + x, dY + y, value); } } } break; case BlitMethod.Multiply: { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int value = s.Get(sX + x, sY + y) * d.Get(dX + x, dY + y); d.Set(dX + x, dY + y, value); } } } break; case BlitMethod.Replace: default: { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int value = s.Get(sX + x, sY + y); d.Set(dX + x, dY + y, value); } } } break; } }
public static void DebugPrint(LogicIntArray2 a) { for (int y = 0; y < a.height; ++y) { string str = ""; for (int x = 0; x < a.width; ++x) { str += string.Format("{0},", a.Get(x, y)); } Debugger.print(str); } }
public static string ToString(LogicIntArray2 a) { string str = ""; for (int y = 0; y < a.height; ++y) { for (int x = 0; x < a.width; ++x) { str += string.Format("{0},", a.Get(x, y)); } str += "\n"; } return(str); }
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); }