23 #include "../lout/msg.h" 30 Rectangle::Rectangle (
int x,
int y,
int width,
int height)
35 this->height = height;
43 const bool filled =
false;
46 x + this->x, y + this->y, this->width, this->height);
56 this->x < otherRect->
x + otherRect->
width &&
57 this->y < otherRect->
y + otherRect->
height &&
58 otherRect->
x < this->x + this->width &&
59 otherRect->
y < this->y + this->height;
65 otherRect->
x + otherRect->
width) - dest->
x;
67 otherRect->
y + otherRect->
height) - dest->
y;
83 x + width <= otherRect->
x + otherRect->
width &&
84 y + height <= otherRect->
y + otherRect->
height;
87 bool Rectangle::isPointWithin (
int x,
int y)
90 x >= this->x && y >= this->y &&
91 x < this->x + width && y < this->y + height;
96 Circle::Circle (
int x,
int y,
int radius)
100 this->radius = radius;
108 const bool filled =
false;
110 view->
drawArc(style->
color, core::style::Color::SHADING_NORMAL, filled,
111 x + this->x, y + this->y, 2 * this->radius, 2 * this->radius,
115 bool Circle::isPointWithin (
int x,
int y)
118 (x - this->x) * (x - this->x) + (y - this->y) * (y - this->y)
127 minx = miny = 0xffffff;
128 maxx = maxy = -0xffffff;
141 if (points->size()) {
143 const bool filled =
false, convex =
false;
144 Point *pointArray = (
Point *)malloc(points->size()*
sizeof(
struct Point));
146 for (i = 0; i < points->size(); i++) {
147 pointArray[i].
x = x + points->getRef(i)->x;
148 pointArray[i].
y = y + points->getRef(i)->y;
151 filled, convex, pointArray, i);
156 void Polygon::addPoint (
int x,
int y)
159 points->getRef(points->size () - 1)->x = x;
160 points->getRef(points->size () - 1)->y = y;
173 bool Polygon::linesCross0(
int ax1,
int ay1,
int ax2,
int ay2,
174 int bx1,
int by1,
int bx2,
int by2)
179 int z1 = zOfVectorProduct (ax1 - bx1, ay1 - by1, bx2 - bx1, by2 - by1);
180 int z2 = zOfVectorProduct (ax2 - bx1, ay2 - by1, bx2 - bx1, by2 - by1);
182 return (z1 <= 0 && z2 >= 0) || (z1 >= 0 && z2 <= 0);
189 bool Polygon::linesCross(
int ax1,
int ay1,
int ax2,
int ay2,
190 int bx1,
int by1,
int bx2,
int by2)
193 linesCross0 (ax1, ay1, ax2, ay2, bx1, by1, bx2, by2) &&
194 linesCross0 (bx1, by1, bx2, by2, ax1, ay1, ax2, ay2);
195 _MSG(
"(%d, %d) - (%d, %d) and (%d, %d) - (%d, %d) cross? %s.\n",
196 ax1, ay1, ax2, ay2, bx1, by1, bx2, by2, cross ?
"Yes" :
"No");
200 bool Polygon::isPointWithin (
int x,
int y)
202 if (points->size () < 3 ||
203 (x < minx || x > maxx || y < miny || y >= maxy))
207 for (
int i = 0; i < points->size () - 1; i++) {
208 if (linesCross (minx - 1, miny - 1, x, y,
209 points->getRef(i)->x, points->getRef(i)->y,
210 points->getRef(i + 1)->x, points->getRef(i + 1)->y))
213 if (linesCross (minx - 1, miny - 1, x, y,
214 points->getRef(points->size () - 1)->x,
215 points->getRef(points->size () - 1)->y,
216 points->getRef(0)->x, points->getRef(0)->y))
219 return numCrosses % 2 == 1;
230 delete rectangleList;
245 for (it = rectangleList->iterator (); it.
hasNext (); ) {
255 if (rectangleList->size() >= 16 ||
256 combinedWidth * combinedHeight <=
261 r->
width = combinedWidth;
262 r->
height = combinedHeight;
264 rectangleList->removeRef (ownRect);
268 rectangleList->append (r);