47 return ((left () >= right ()) || (top () <= bottom ()));
51 return bot_left == other.bot_left && top_right == other.top_right;
55 return top_right.y ();
76 return top_right.x ();
82 return (bot_left.x() + top_right.x()) / 2;
85 return (bot_left.y() + top_right.y()) / 2;
93 return ICOORD (top_right.x (), bot_left.y ());
97 return ICOORD (bot_left.x (), top_right.y ());
106 return top_right.y () - bot_left.y ();
113 return top_right.x () - bot_left.x ();
120 return width () * height ();
127 void pad(
int xpad,
int ypad) {
135 bot_left +=
ICOORD (0, y);
140 bot_left +=
ICOORD (x, 0);
145 top_right +=
ICOORD (x, 0);
150 top_right +=
ICOORD (0, y);
161 bot_left.set_x ((
inT16) floor (bot_left.x () + vec.
x ()));
163 bot_left.set_y ((
inT16) floor (bot_left.y () + vec.
y ()));
165 top_right.set_x ((
inT16) ceil (top_right.x () + vec.
x ()));
167 top_right.set_y ((
inT16) ceil (top_right.y () + vec.
y ()));
173 bot_left.set_x ((
inT16) floor (bot_left.x () * f));
174 bot_left.set_y ((
inT16) floor (bot_left.y () * f));
175 top_right.set_x ((
inT16) ceil (top_right.x () * f));
176 top_right.set_y ((
inT16) ceil (top_right.y () * f));
180 bot_left.set_x ((
inT16) floor (bot_left.x () * vec.
x ()));
181 bot_left.set_y ((
inT16) floor (bot_left.y () * vec.
y ()));
182 top_right.set_x ((
inT16) ceil (top_right.x () * vec.
x ()));
183 top_right.set_y ((
inT16) ceil (top_right.y () * vec.
y ()));
190 bot_left.rotate (vec);
191 top_right.rotate (vec);
192 *
this =
TBOX (bot_left, top_right);
197 void rotate_large(
const FCOORD& vec);
203 const TBOX &box)
const;
206 const TBOX &box)
const;
209 const TBOX &box)
const;
212 bool x_overlap(
const TBOX &box)
const;
218 return MAX(bot_left.x(), box.bot_left.
x()) -
219 MIN(top_right.x(), box.top_right.
x());
226 return MAX(bot_left.y(), box.bot_left.
y()) -
227 MIN(top_right.y(), box.top_right.
y());
232 bool major_x_overlap(
const TBOX &box)
const;
235 bool y_overlap(
const TBOX &box)
const;
239 bool major_y_overlap(
const TBOX &box)
const;
242 double overlap_fraction(
const TBOX &box)
const;
245 double x_overlap_fraction(
const TBOX& box)
const;
248 double y_overlap_fraction(
const TBOX& box)
const;
251 bool x_almost_equal(
const TBOX &box,
int tolerance)
const;
254 bool almost_equal(
const TBOX &box,
int tolerance)
const;
257 const TBOX &box)
const;
260 const TBOX &box)
const;
264 bot_left.set_x(x_min);
265 bot_left.set_y(y_min);
266 top_right.set_x(x_max);
267 top_right.set_y(y_max);
271 tprintf(
"Bounding box=(%d,%d)->(%d,%d)\n",
272 left(), bottom(), right(), top());
275 void print_to_str(
STRING *str)
const;
277 #ifndef GRAPHICS_DISABLED 280 fd->
Rectangle(bot_left.x (), bot_left.y (), top_right.x (),
290 bool Serialize(FILE* fp)
const;
293 bool DeSerialize(
bool swap, FILE* fp);
324 return ((pt.
x () >= bot_left.
x ()) &&
325 (pt.
x () <= top_right.
x ()) &&
326 (pt.
y () >= bot_left.
y ()) && (pt.
y () <= top_right.
y ()));
346 const TBOX &box)
const {
347 return ((box.bot_left.
x () <= top_right.
x ()) &&
348 (box.top_right.
x () >= bot_left.
x ()) &&
349 (box.bot_left.
y () <= top_right.
y ()) &&
350 (box.top_right.
y () >= bot_left.
y ()));
359 const TBOX &box)
const {
379 double fraction = 0.0;
392 return ((box.bot_left.
x() <= top_right.
x()) &&
393 (box.top_right.
x() >= bot_left.
x()));
419 return ((box.bot_left.
y() <= top_right.
y()) &&
420 (box.top_right.
y() >= bot_left.
y()));
434 if (this->
top() < box.
top()) {
453 if (other.
left() <= x && x <= other.
right())
458 return MAX(0, static_cast<double>(high - low) /
width);
475 if (other.
bottom() <= y && y <= other.
top())
480 return MAX(0, static_cast<double>(high - low) /
height);
bool operator==(const TBOX &other) const
void rotate(const FCOORD &vec)
bool y_overlap(const TBOX &box) const
void scale(const float f)
double x_overlap_fraction(const TBOX &box) const
bool overlap(const TBOX &box) const
const ICOORD & topright() const
void move(const FCOORD vec)
ICOORD & operator+=(ICOORD &op1, const ICOORD &op2)
void set_to_given_coords(int x_min, int y_min, int x_max, int y_max)
bool major_x_overlap(const TBOX &box) const
void move_top_edge(const inT16 y)
int y_gap(const TBOX &box) const
void move_right_edge(const inT16 x)
double y_overlap_fraction(const TBOX &box) const
bool x_overlap(const TBOX &box) const
void move(const ICOORD vec)
bool contains(const FCOORD pt) const
void move_left_edge(const inT16 x)
void plot(ScrollView *fd) const
inT16 x() const
access function
double overlap_fraction(const TBOX &box) const
TBOX & operator &=(TBOX &op1, const TBOX &op2)
int x_gap(const TBOX &box) const
void move_bottom_edge(const inT16 y)
void Rectangle(int x1, int y1, int x2, int y2)
void pad(int xpad, int ypad)
bool major_overlap(const TBOX &box) const
TBOX intersection(const TBOX &box) const
bool major_y_overlap(const TBOX &box) const
void scale(const FCOORD vec)
const ICOORD & botleft() const
inT16 y() const
access_function