Beispiel #1
0
void PositionManager::updateRegion(Movable *movable, float oldX, float oldY, uint8_t oldLayer)
{
	Region oldRegion(oldX, oldY, oldLayer);
	Region newRegion(movable->x, movable->y, movable->layer);

	if(oldRegion == newRegion) {
		return;
	}

	movable->onRegionChange(&oldRegion, &newRegion);

	for(int32_t rx = oldRegion.rx - Region::VISIBILITY_RADIUS; rx <= oldRegion.rx + Region::VISIBILITY_RADIUS; rx++) {
		int32_t ryStart = oldRegion.ry - Region::VISIBILITY_RADIUS + ::abs(rx - oldRegion.rx);
		int32_t ryEnd = oldRegion.ry + Region::VISIBILITY_RADIUS - ::abs(rx - oldRegion.rx);

		for(int32_t ry = ryStart; ry <= ryEnd; ry++) {
			Region testRegion(rx, ry, oldRegion.layer);
			if(oldRegion.isVisibleRegion(testRegion) && !newRegion.isVisibleRegion(testRegion)) {
				//disappear in old region
				movable->onLeaveRegion(&testRegion);
			}
		}
	}

	for(int32_t rx = newRegion.rx - Region::VISIBILITY_RADIUS; rx <= newRegion.rx + Region::VISIBILITY_RADIUS; rx++) {
		int32_t ryStart = newRegion.ry - Region::VISIBILITY_RADIUS + ::abs(rx - newRegion.rx);
		int32_t ryEnd = newRegion.ry + Region::VISIBILITY_RADIUS - ::abs(rx - newRegion.rx);

		for(int32_t ry = ryStart; ry <= ryEnd; ry++) {
			Region testRegion(rx, ry, newRegion.layer);
			if(newRegion.isVisibleRegion(testRegion) && !oldRegion.isVisibleRegion(testRegion)) {
				//appear in new region
				movable->onEnterRegion(&testRegion);
			}
		}
	}
}
const SkMatrix kTestMatrix = testMatrix();
static SkPath testPath() {
    SkPath path;
    path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
                                  SkIntToScalar(2), SkIntToScalar(1)));
    return path;
}
const SkPath kTestPath = testPath();
static SkRegion testRegion() {
    SkRegion region;
    SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1);
    region.setRect(rect);
    return region;
}
const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
const SkRegion kTestRegion = testRegion();
const SkColor kTestColor = 0x01020304;
const SkPaint kTestPaint;
const SkPoint kTestPoints[3] = {
    {SkIntToScalar(0), SkIntToScalar(0)},
    {SkIntToScalar(2), SkIntToScalar(1)},
    {SkIntToScalar(0), SkIntToScalar(2)}
};
const size_t kTestPointCount = 3;
static SkBitmap testBitmap() {
    SkBitmap bitmap;
    createBitmap(&bitmap, SkBitmap::kARGB_8888_Config, 0x05060708);
    return bitmap;
}
SkBitmap kTestBitmap; // cannot be created during static init
SkString kTestText("Hello World");
Beispiel #3
0
int main()
{
//   srand(unsigned int(time(nullptr)));
// 
//   RandGreed();
//   PrintGreed();
// 
//   int stepx = 0;
//   int stepy = 0;
// 
//   float tMaxX = 0.0f;
//   float tMaxY = 0.0f;
// 
//   if(dirx < 0)
//   {
//     stepx = -1;
//     tMaxX = posx / (stepx * dirx + eps);
//   }
//   else
//   {
//     stepx = 1;
//     tMaxX = (cellSize - posx) / (dirx + eps);
//   }
//   if(diry < 0)
//   {
//     stepy = -1;
//     tMaxY = posy / (stepy * diry + eps);
//   }
//   else
//   {
//     stepy = 1;
//     tMaxY = (cellSize - posy) / (diry + eps);
//   }
// 
//   // ¬ычисл¤ем приращение по x и y дл¤ блока.
//   float tDeltaX = cellSize / (stepx * dirx + eps);
//   float tDeltaY = cellSize / (stepy * diry + eps);
// 
//   unsigned int greedPosx = greedCenter;
//   unsigned int greedPosy = greedCenter;
// 
//   while(greedPosx < greedSize && greedPosx >= 0 && 
//         greedPosy < greedSize && greedPosy >= 0)
//   {
//     if(tMaxX < tMaxY)
//     {
//       tMaxX += tDeltaX;
//       greedPosx += stepx;
//     }
//     else
//     {
//       tMaxY += tDeltaY;
//       greedPosy += stepy;
//     }
//     if(greed[greedPosy][greedPosx] == 1)
//     {
//       break;
//     }
//   };
// 

  TestRegion testRegion(5, 0);

  testRegion.SetRadius(4);

  testRegion.SetRadius(2);

  testRegion.Move(1, 1, 1);

  testRegion.SetRadius(3);

  testRegion.SetRadius(2);

  testRegion.Print();

  system("pause");

  return 0;
}