37 bot_left (INT16_MAX, INT16_MAX), top_right (-INT16_MAX, -INT16_MAX) {
45 int16_t left, int16_t bottom, int16_t right, int16_t top);
50 bool null_box()
const {
51 return ((left () >= right ()) || (top () <= bottom ()));
55 return bot_left == other.bot_left && top_right == other.top_right;
59 return top_right.
y ();
65 int16_t bottom()
const {
68 void set_bottom(
int y) {
72 int16_t left()
const {
75 void set_left(
int x) {
79 int16_t right()
const {
80 return top_right.x ();
82 void set_right(
int x) {
85 int x_middle()
const {
86 return (bot_left.x() + top_right.x()) / 2;
88 int y_middle()
const {
89 return (bot_left.y() + top_right.y()) / 2;
92 const ICOORD &botleft()
const {
97 return ICOORD (top_right.x (), bot_left.y ());
101 return ICOORD (bot_left.x (), top_right.y ());
104 const ICOORD &topright()
const {
108 int16_t height()
const {
110 return top_right.
y () - bot_left.y ();
115 int16_t width()
const {
117 return top_right.x () - bot_left.x ();
122 int32_t area()
const {
124 return width () * height ();
131 void pad(
int xpad,
int ypad) {
137 void move_bottom_edge(
139 bot_left +=
ICOORD (0, y);
144 bot_left +=
ICOORD (x, 0);
147 void move_right_edge(
149 top_right +=
ICOORD (x, 0);
154 top_right +=
ICOORD (0, y);
165 bot_left.
set_x(static_cast<int16_t>(std::floor(bot_left.x() + vec.
x())));
167 bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() + vec.
y())));
169 top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() + vec.
x())));
171 top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() + vec.
y())));
178 bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * f)));
180 bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * f)));
182 top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * f)));
184 top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * f)));
188 bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * vec.
x())));
189 bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * vec.
y())));
190 top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * vec.
x())));
191 top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * vec.
y())));
197 void rotate(
const FCOORD& vec) {
198 bot_left.rotate (vec);
199 top_right.rotate (vec);
200 *
this =
TBOX (bot_left, top_right);
205 void rotate_large(
const FCOORD& vec);
211 const TBOX &box)
const;
214 const TBOX &box)
const;
217 const TBOX &box)
const;
220 bool x_overlap(
const TBOX &box)
const;
225 int x_gap(
const TBOX& box)
const {
226 return std::max(bot_left.x(), box.bot_left.
x()) -
227 std::min(top_right.x(), box.top_right.
x());
233 int y_gap(
const TBOX& box)
const {
234 return std::max(bot_left.y(), box.bot_left.
y()) -
235 std::min(top_right.y(), box.top_right.
y());
240 bool major_x_overlap(
const TBOX &box)
const;
243 bool y_overlap(
const TBOX &box)
const;
247 bool major_y_overlap(
const TBOX &box)
const;
250 double overlap_fraction(
const TBOX &box)
const;
253 double x_overlap_fraction(
const TBOX& box)
const;
256 double y_overlap_fraction(
const TBOX& box)
const;
259 bool x_almost_equal(
const TBOX &box,
int tolerance)
const;
262 bool almost_equal(
const TBOX &box,
int tolerance)
const;
265 const TBOX &box)
const;
268 const TBOX &box)
const;
271 void set_to_given_coords(
int x_min,
int y_min,
int x_max,
int y_max) {
272 bot_left.set_x(x_min);
273 bot_left.set_y(y_min);
274 top_right.set_x(x_max);
275 top_right.set_y(y_max);
279 tprintf(
"Bounding box=(%d,%d)->(%d,%d)\n",
280 left(), bottom(), right(), top());
283 void print_to_str(
STRING *str)
const;
285 #ifndef GRAPHICS_DISABLED
288 fd->
Rectangle(bot_left.x (), bot_left.y (), top_right.x (),
321 bot_left =
ICOORD(static_cast<int16_t>(std::floor(pt.
x())),
322 static_cast<int16_t>(std::floor(pt.
y())));
323 top_right =
ICOORD(static_cast<int16_t>(std::ceil(pt.
x())),
324 static_cast<int16_t>(std::ceil(pt.
y())));
334 return ((pt.
x () >= bot_left.
x ()) &&
335 (pt.
x () <= top_right.
x ()) &&
336 (pt.
y () >= bot_left.
y ()) && (pt.
y () <= top_right.
y ()));
356 const TBOX &box)
const {
357 return ((box.bot_left.
x () <= top_right.
x ()) &&
358 (box.top_right.
x () >= bot_left.
x ()) &&
359 (box.bot_left.
y () <= top_right.
y ()) &&
360 (box.top_right.
y () >= bot_left.
y ()));
369 const TBOX &box)
const {
370 int overlap = std::min(box.top_right.
x(), top_right.
x());
371 overlap -= std::max(box.bot_left.
x(), bot_left.
x());
375 overlap = std::min(box.top_right.
y(), top_right.
y());
376 overlap -= std::max(box.bot_left.
y(), bot_left.
y());
389 double fraction = 0.0;
402 return ((box.bot_left.
x() <= top_right.
x()) &&
403 (box.top_right.
x() >= bot_left.
x()));
429 return ((box.bot_left.
y() <= top_right.
y()) &&
430 (box.top_right.
y() >= bot_left.
y()));
444 if (this->
top() < box.
top()) {
458 int low = std::max(
left(), other.
left());
463 if (other.
left() <= x && x <= other.
right())
468 return std::max(0.0, static_cast<double>(high - low) /
width);
481 int high = std::min(
top(), other.
top());
485 if (other.
bottom() <= y && y <= other.
top())
490 return std::max(0.0, static_cast<double>(high - low) /
height);