29 #include "scrollview.h" 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);
51 return ((left () >= right ()) || (top () <= bottom ()));
59 return top_right.y ();
80 return top_right.x ();
86 return (bot_left.x() + top_right.x()) / 2;
89 return (bot_left.y() + top_right.y()) / 2;
97 return ICOORD (top_right.x (), bot_left.y ());
101 return ICOORD (bot_left.x (), top_right.y ());
110 return top_right.y () - bot_left.y ();
117 return top_right.x () - bot_left.x ();
124 return width () * height ();
131 void pad(
int xpad,
int ypad) {
139 bot_left +=
ICOORD (0, y);
144 bot_left +=
ICOORD (x, 0);
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())));
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;
226 return std::max(bot_left.x(), box.
bot_left.
x()) -
234 return std::max(bot_left.y(), box.
bot_left.
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;
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 (),
298 bool Serialize(FILE* fp)
const;
301 bool DeSerialize(
bool swap, FILE* fp);
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 ()) &&
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());
373 if (overlap < std::min(box.
width(), width()))
375 overlap = std::min(box.
top_right.
y(), top_right.y());
376 overlap -= std::max(box.
bot_left.
y(), bot_left.y());
378 if (overlap < std::min(box.
height(), height()))
389 double fraction = 0.0;
391 fraction = this->intersection(box).area() * 1.0 / this->area();
402 return ((box.
bot_left.
x() <= top_right.x()) &&
413 int16_t overlap = box.
width();
414 if (this->left() > box.
left()) {
415 overlap -= this->left() - box.
left();
417 if (this->right() < box.
right()) {
418 overlap -= box.
right() - this->right();
420 return (overlap >= box.
width() / 2 || overlap >= this->width() / 2);
429 return ((box.
bot_left.
y() <= top_right.y()) &&
440 int16_t overlap = box.
height();
441 if (this->bottom() > box.
bottom()) {
442 overlap -= this->bottom() - box.
bottom();
444 if (this->top() < box.
top()) {
445 overlap -= box.
top() - this->top();
447 return (overlap >= box.
height() / 2 || overlap >= this->height() / 2);
458 int low = std::max(left(), other.
left());
459 int high = std::min(right(), other.
right());
460 int width = right() - left();
463 if (other.
left() <= x && x <= other.
right())
468 return std::max(0.0, static_cast<double>(high - low) / width);
480 int low = std::max(bottom(), other.
bottom());
481 int high = std::min(top(), other.
top());
482 int height = top() - bottom();
485 if (other.
bottom() <= y && y <= other.
top())
490 return std::max(0.0, static_cast<double>(high - low) / height);
double overlap_fraction(const TBOX &box) const
Definition: rect.h:388
TBOX()
Definition: rect.h:36
int32_t area() const
Definition: rect.h:122
void move_bottom_edge(const int16_t y)
Definition: rect.h:137
void set_right(int x)
Definition: rect.h:82
int16_t right() const
Definition: rect.h:79
int x_middle() const
Definition: rect.h:85
int16_t x() const
access function
Definition: points.h:53
float y() const
Definition: points.h:211
void plot(ScrollView *fd) const
Definition: rect.h:286
bool y_overlap(const TBOX &box) const
Definition: rect.h:428
bool major_y_overlap(const TBOX &box) const
Definition: rect.h:439
void set_left(int x)
Definition: rect.h:75
void move(const FCOORD vec)
Definition: rect.h:163
ICOORD top_right
Definition: rect.h:310
ICOORD botright() const
Definition: rect.h:96
void move(const ICOORD vec)
Definition: rect.h:157
bool x_overlap(const TBOX &box) const
Definition: rect.h:401
void scale(const float f)
Definition: rect.h:175
bool overlap(const TBOX &box) const
Definition: rect.h:355
int y_gap(const TBOX &box) const
Definition: rect.h:233
int16_t bottom() const
Definition: rect.h:65
void print() const
Definition: rect.h:278
bool contains(const FCOORD pt) const
Definition: rect.h:333
float x() const
Definition: points.h:208
ICOORD topleft() const
Definition: rect.h:100
const ICOORD & topright() const
Definition: rect.h:104
void move_right_edge(const int16_t x)
Definition: rect.h:147
bool operator==(const TBOX &other) const
Definition: rect.h:54
void rotate(const FCOORD &vec)
Definition: rect.h:197
ICOORD bot_left
Definition: rect.h:309
int16_t y() const
access_function
Definition: points.h:57
double y_overlap_fraction(const TBOX &box) const
Definition: rect.h:479
bool major_x_overlap(const TBOX &box) const
Definition: rect.h:412
bool null_box() const
Definition: rect.h:50
void scale(const FCOORD vec)
Definition: rect.h:186
int x_gap(const TBOX &box) const
Definition: rect.h:225
int y_middle() const
Definition: rect.h:88
void set_top(int y)
Definition: rect.h:61
integer coordinate
Definition: points.h:32
int16_t top() const
Definition: rect.h:58
double x_overlap_fraction(const TBOX &box) const
Definition: rect.h:457
void pad(int xpad, int ypad)
Definition: rect.h:131
const ICOORD & botleft() const
Definition: rect.h:92
int16_t left() const
Definition: rect.h:72
int16_t height() const
Definition: rect.h:108
int16_t width() const
Definition: rect.h:115
void set_to_given_coords(int x_min, int y_min, int x_max, int y_max)
Definition: rect.h:271
void move_left_edge(const int16_t x)
Definition: rect.h:142
void move_top_edge(const int16_t y)
Definition: rect.h:152
void set_bottom(int y)
Definition: rect.h:68
bool major_overlap(const TBOX &box) const
Definition: rect.h:368