41 bot_left(INT16_MAX, INT16_MAX)
42 , top_right(-INT16_MAX, -INT16_MAX) {}
55 : bot_left(left, bottom), top_right(right, top) {}
61 return ((left() >= right()) || (top() <= bottom()));
65 return bot_left == other.bot_left && top_right == other.top_right;
96 return (bot_left.x() + top_right.x()) / 2;
99 return (bot_left.y() + top_right.y()) / 2;
107 return ICOORD(top_right.x(), bot_left.y());
111 return ICOORD(bot_left.x(), top_right.y());
120 return top_right.y() - bot_left.y();
128 return top_right.x() - bot_left.x();
136 return width() * height();
144 void pad(
int xpad,
int ypad) {
178 bot_left.set_x(
static_cast<TDimension>(std::floor(bot_left.x() + vec.
x())));
180 bot_left.set_y(
static_cast<TDimension>(std::floor(bot_left.y() + vec.
y())));
182 top_right.set_x(
static_cast<TDimension>(std::ceil(top_right.x() + vec.
x())));
184 top_right.set_y(
static_cast<TDimension>(std::ceil(top_right.y() + vec.
y())));
191 bot_left.set_x(
static_cast<TDimension>(std::floor(bot_left.x() * f)));
193 bot_left.set_y(
static_cast<TDimension>(std::floor(bot_left.y() * f)));
195 top_right.set_x(
static_cast<TDimension>(std::ceil(top_right.x() * f)));
197 top_right.set_y(
static_cast<TDimension>(std::ceil(top_right.y() * f)));
201 bot_left.set_x(
static_cast<TDimension>(std::floor(bot_left.x() * vec.
x())));
202 bot_left.set_y(
static_cast<TDimension>(std::floor(bot_left.y() * vec.
y())));
203 top_right.set_x(
static_cast<TDimension>(std::ceil(top_right.x() * vec.
x())));
204 top_right.set_y(
static_cast<TDimension>(std::ceil(top_right.y() * vec.
y())));
211 bot_left.rotate(vec);
212 top_right.rotate(vec);
213 *
this =
TBOX(bot_left, top_right);
218 void rotate_large(
const FCOORD &vec);
224 const TBOX &box)
const;
227 const TBOX &box)
const;
230 const TBOX &box)
const;
233 bool x_overlap(
const TBOX &box)
const;
239 return std::max(bot_left.x(), box.bot_left.
x()) - std::min(top_right.x(), box.top_right.
x());
246 return std::max(bot_left.y(), box.bot_left.
y()) - std::min(top_right.y(), box.top_right.
y());
251 bool major_x_overlap(
const TBOX &box)
const;
254 bool y_overlap(
const TBOX &box)
const;
258 bool major_y_overlap(
const TBOX &box)
const;
261 double overlap_fraction(
const TBOX &box)
const;
264 double x_overlap_fraction(
const TBOX &box)
const;
267 double y_overlap_fraction(
const TBOX &box)
const;
270 bool x_almost_equal(
const TBOX &box,
int tolerance)
const;
273 bool almost_equal(
const TBOX &box,
int tolerance)
const;
276 const TBOX &box)
const;
279 const TBOX &box)
const;
283 bot_left.set_x(x_min);
284 bot_left.set_y(y_min);
285 top_right.set_x(x_max);
286 top_right.set_y(y_max);
290 tprintf(
"Bounding box=(%d,%d)->(%d,%d)\n", left(), bottom(), right(), top());
293 void print_to_str(std::string &str)
const;
295#ifndef GRAPHICS_DISABLED
298 fd->
Rectangle(bot_left.x(), bot_left.y(), top_right.x(), top_right.y());
345 return ((pt.
x() >= bot_left.
x()) && (pt.
x() <= top_right.
x()) && (pt.
y() >= bot_left.
y()) &&
346 (pt.
y() <= top_right.
y()));
364 const TBOX &box)
const {
365 return ((box.bot_left.
x() <= top_right.
x()) && (box.top_right.
x() >= bot_left.
x()) &&
366 (box.bot_left.
y() <= top_right.
y()) && (box.top_right.
y() >= bot_left.
y()));
375 const TBOX &box)
const {
376 int overlap = std::min(box.top_right.
x(), top_right.
x());
377 overlap -= std::max(box.bot_left.
x(), bot_left.
x());
382 overlap = std::min(box.top_right.
y(), top_right.
y());
383 overlap -= std::max(box.bot_left.
y(), bot_left.
y());
397 double fraction = 0.0;
410 return ((box.bot_left.
x() <= top_right.
x()) && (box.top_right.
x() >= bot_left.
x()));
427 return (overlap >= box.
width() / 2 ||
overlap >= this->width() / 2);
436 return ((box.bot_left.
y() <= top_right.
y()) && (box.top_right.
y() >= bot_left.
y()));
450 if (this->
top() < box.
top()) {
453 return (overlap >= box.
height() / 2 ||
overlap >= this->height() / 2);
464 int low = std::max(
left(), other.
left());
475 return std::max(0.0,
static_cast<double>(high - low) /
width);
488 int high = std::min(
top(), other.
top());
498 return std::max(0.0,
static_cast<double>(high - low) /
height);
ICOORD & operator+=(ICOORD &op1, const ICOORD &op2)
TBOX & operator&=(TBOX &op1, const TBOX &op2)
void tprintf(const char *format,...)
bool DeSerialize(bool swap, FILE *fp, std::vector< T > &data)
bool Serialize(FILE *fp, const std::vector< T > &data)
bool contains(const std::vector< T > &data, const T &value)
TDimension y() const
access_function
TDimension x() const
access function
bool major_y_overlap(const TBOX &box) const
void move_right_edge(const TDimension x)
int y_gap(const TBOX &box) const
TDimension height() const
void move(const ICOORD vec)
double y_overlap_fraction(const TBOX &box) const
void scale(const float f)
void scale(const FCOORD vec)
void move(const FCOORD vec)
void move_top_edge(const TDimension y)
bool operator==(const TBOX &other) const
void move_bottom_edge(const TDimension y)
void move_left_edge(const TDimension x)
TBOX(TDimension left, TDimension bottom, TDimension right, TDimension top)
double x_overlap_fraction(const TBOX &box) const
void set_to_given_coords(int x_min, int y_min, int x_max, int y_max)
void rotate(const FCOORD &vec)
const ICOORD & botleft() const
int x_gap(const TBOX &box) const
TBOX intersection(const TBOX &box) const
bool major_x_overlap(const TBOX &box) const
const ICOORD & topright() const
bool overlap(const TBOX &box) const
TDimension bottom() const
void pad(int xpad, int ypad)
bool contains(const FCOORD pt) const
bool y_overlap(const TBOX &box) const
bool major_overlap(const TBOX &box) const
bool x_overlap(const TBOX &box) const
void plot(ScrollView *fd) const
double overlap_fraction(const TBOX &box) const
void Rectangle(int x1, int y1, int x2, int y2)