Exemple #1
0
void TestPolygon()
{
	Point point[7] = {
		{ 100, 100 },
		{ 100, 600 },
		{ 200, 600 },
		//{ 200, 350 },
		{ 500, 350 },
		{ 500, 600 },
		{ 600, 600 },
		{ 600, 100 },
	};

	Polygon* polygon = CreatePolygon(7, point);
	PrintPolygon(polygon);

/*
	for (int i = 0; i < 50; ++i)
	{
		Point point = { (rand() % (800 * 10000) / 10000.f), (rand() % (640 * 10000) / 10000.f) };
		printf("circle(%f, %f, %f, \"%s\");\n", point.x, point.y, 5.f, PointInPolygon(&polygon, &point) ? "red" : "yellow");
	}*/

	Circle circle[200] = { 0 };
	for (int i = 0; i < 200; ++i)
	{
		float x = (rand() % (800 * 10000) / 10000.f);
		float y = (rand() % (640 * 10000) / 10000.f);
		float r = 20.f;
		circle[i].c.x = x;
		circle[i].c.y = y;
		circle[i].r = r;
	}

	for (int i = 0; i < 200; ++i)
	{
		PrintCircle(circle[i], IsCircleIntersectPolygon(&circle[i], polygon));
	}

	DeletePolygon(&polygon);
}
Exemple #2
0
VOID DeleteDuplicatePolygons(LEVEL_DATA *pLevel)
{
  INT i, j, k, n1, n2, offset, num_deleted_polygons;
  POLYGON huge *p1;
  POLYGON huge *p2;

  num_deleted_polygons = 0;

  for(i = 0; i < pLevel->nPolygons - 1; ++i)
  {
    p1 = pLevel->pPolygonData + i;
    n1 = (p1->flags & 7) + 3;

    for(j = i + 1; j < pLevel->nPolygons; ++j)
    {
      p2 = pLevel->pPolygonData + j;
      n2 = (p2->flags & 7) + 3;

      if (n1 == n2)
      {
        for(offset = 0; offset < n1; ++offset)
        {
          for(k = 0; k < n1; ++k)
          {
            if (p1->vertices[k] != p2->vertices[(k + offset) % n1])
            {
              break;					// no match
            }
          }

          if (k == n1)
          {
            break;						// found a match!
          }
        }

        if (offset < n1)
        {
          ++num_deleted_polygons;
          ReplacePolygon(pLevel, j, i);
          DeletePolygon(pLevel, j);
          pLevel->bRebuildZone = TRUE;
          break;
        }
      }
    }
  }

  if (num_deleted_polygons == 1)
  {
    MsgBox( hwndMDIClient,
            MB_ICONINFORMATION,
            "1 duplicate polygon has been deleted" );
  }
  else if (num_deleted_polygons > 1)
  {
    MsgBox( hwndMDIClient,
            MB_ICONINFORMATION,
            "%d duplicate polygons have been deleted",
            num_deleted_polygons );
  }

  return;

} // DeleteDuplicatePolygons
Exemple #3
0
INT ReplaceVertex(LEVEL_DATA *pLevel, INT nOld, INT nNew)
{
  INT i, j, k, n, num_deleted_polygons;
  BOOL bCheckPolygon;
  POLYGON huge *p;

  if (nOld == nNew)
  {
    return 0;
  }

  p = pLevel->pPolygonData;

  i = 0;
  num_deleted_polygons = 0;
  
  while(i < pLevel->nPolygons)
  {
    bCheckPolygon = FALSE;

    n = (p->flags & 7) + 3;

    for(j = 0; j < n; ++j)
    {
      if (p->vertices[j] == nOld)
      {
        bCheckPolygon = TRUE;
        p->vertices[j] = nNew;
      }
    }

    //
    //  If any polygon vertices have been merged, delete the polygon.
    //

    if (bCheckPolygon)
    {
      j = 0;

      while(j < n - 1)
      {
        for(k = j + 1; k < n; ++k)
        {
          if (p->vertices[j] == p->vertices[k])
          {
            break;
          }
        }

        if (k < n)
        {
          DeletePolygon(pLevel, i);
          ++num_deleted_polygons;
          break;
        }

        ++j;
      }

      if (j < n - 1)
      {
        continue;
      }
    }

    ++i;
    ++p;
  }

  return num_deleted_polygons;

} // ReplaceVertex
Exemple #4
0
VOID DeleteSelections(LEVEL_DATA *pLevel)
{
  INT i, j, n;
  POLYGON huge *p;
  HCURSOR hcurSave;

  hcurSave = SetCursor(LoadCursor(NULL, IDC_WAIT));

  //
  //  If any polygon uses a selected vertex then select it also.
  //

  p = pLevel->pPolygonData;

  for(i = 0; i < pLevel->nPolygons; ++i)
  {
    if ((p->flags & PF_SELECTED) == 0)
    {
      n = (p->flags & 7) + 3;

      for(j = 0; j < n; ++j)
      {
        if ((pLevel->pVertexData + p->vertices[j])->flags & VF_SELECTED)
        {
          p->flags |= PF_SELECTED;
          break;
        }
      }
    }

    ++p;
  }

  //
  //  Unlink any polygon that is linked to a selected polygon.
  //

  p = pLevel->pPolygonData;

  for(i = 0; i < pLevel->nPolygons; ++i)
  {
    if (p->flags & PF_LINKED)
    {
      if ((pLevel->pPolygonData + p->polygon_link)->flags & PF_SELECTED)
      {
        p->flags &= ~PF_LINKED;
      }
    }

    ++p;
  }

  //
  //  Delete selected polygons.
  //

  for(i = pLevel->nPolygons - 1; i >= 0; --i)
  {
    if ((pLevel->pPolygonData + i)->flags & PF_SELECTED)
    {
      DeletePolygon(pLevel, i);
    }
  }

  //
  //  Delete the selected vertices.
  //

  for(i = pLevel->nVertices - 1; i >= 0; --i)
  {
    if ((pLevel->pVertexData + i)->flags & VF_SELECTED)
    {
      DeleteVertex(pLevel, i);
    }
  }

  SetCursor(hcurSave);

  return;

} // DeleteSelections