Пример #1
0
bool Recti::clipBy(const Recti& other)
{
  int minX, minY, maxX, maxY;
  getBounds(minX, minY, maxX, maxY);

  int otherMinX, otherMinY, otherMaxX, otherMaxY;
  other.getBounds(otherMinX, otherMinY, otherMaxX, otherMaxY);

  if (minX > otherMaxX || maxX < otherMinX)
    return false;

  if (minY > otherMaxY || maxY < otherMinY)
    return false;

  if (minX < otherMinX)
    minX = otherMinX;
  if (minY < otherMinY)
    minY = otherMinY;
  if (maxX > otherMaxX)
    maxX = otherMaxX;
  if (maxY > otherMaxY)
    maxY = otherMaxY;

  setBounds(minX, minY, maxX, maxY);
  return true;
}
Пример #2
0
bool Recti::intersects(const Recti& other) const
{
  int minX, minY, maxX, maxY;
  getBounds(minX, minY, maxX, maxY);

  int otherMinX, otherMinY, otherMaxX, otherMaxY;
  other.getBounds(otherMinX, otherMinY, otherMaxX, otherMaxY);

  if (minX > otherMaxX || maxX < otherMinX)
    return false;

  if (minY > otherMaxY || maxY < otherMinY)
    return false;

  return true;
}
Пример #3
0
void Recti::envelop(const Recti& other)
{
  int minX, minY, maxX, maxY;
  getBounds(minX, minY, maxX, maxY);

  int otherMinX, otherMinY, otherMaxX, otherMaxY;
  other.getBounds(otherMinX, otherMinY, otherMaxX, otherMaxY);

  if (minX > otherMinX)
    minX = otherMinX;
  if (minY > otherMinY)
    minY = otherMinY;
  if (maxX < otherMaxX)
    maxX = otherMaxX;
  if (maxY < otherMaxY)
    maxY = otherMaxY;

  setBounds(minX, minY, maxX, maxY);
}