Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBOX Class Reference

#include <rect.h>

Public Member Functions

 TBOX ()
 
 TBOX (const ICOORD pt1, const ICOORD pt2)
 
 TBOX (inT16 left, inT16 bottom, inT16 right, inT16 top)
 
 TBOX (const FCOORD pt)
 
bool null_box () const
 
bool operator== (const TBOX &other) const
 
inT16 top () const
 
void set_top (int y)
 
inT16 bottom () const
 
void set_bottom (int y)
 
inT16 left () const
 
void set_left (int x)
 
inT16 right () const
 
void set_right (int x)
 
const ICOORDbotleft () const
 
ICOORD botright () const
 
ICOORD topleft () const
 
const ICOORDtopright () const
 
inT16 height () const
 
inT16 width () const
 
inT32 area () const
 
void pad (int xpad, int ypad)
 
void move_bottom_edge (const inT16 y)
 
void move_left_edge (const inT16 x)
 
void move_right_edge (const inT16 x)
 
void move_top_edge (const inT16 y)
 
void move (const ICOORD vec)
 
void move (const FCOORD vec)
 
void scale (const float f)
 
void scale (const FCOORD vec)
 
void rotate (const FCOORD &vec)
 
void rotate_large (const FCOORD &vec)
 
bool contains (const FCOORD pt) const
 
bool contains (const TBOX &box) const
 
bool overlap (const TBOX &box) const
 
bool major_overlap (const TBOX &box) const
 
bool x_overlap (const TBOX &box) const
 
int x_gap (const TBOX &box) const
 
int y_gap (const TBOX &box) const
 
bool major_x_overlap (const TBOX &box) const
 
bool y_overlap (const TBOX &box) const
 
bool major_y_overlap (const TBOX &box) const
 
double overlap_fraction (const TBOX &box) const
 
double x_overlap_fraction (const TBOX &box) const
 
double y_overlap_fraction (const TBOX &box) const
 
bool x_almost_equal (const TBOX &box, int tolerance) const
 
bool almost_equal (const TBOX &box, int tolerance) const
 
TBOX intersection (const TBOX &box) const
 
TBOX bounding_union (const TBOX &box) const
 
void set_to_given_coords (int x_min, int y_min, int x_max, int y_max)
 
void print () const
 
void append_debug (STRING *str) const
 
void plot (ScrollView *fd) const
 
void plot (ScrollView *fd, ScrollView::Color fill_colour, ScrollView::Color border_colour) const
 
bool Serialize (FILE *fp) const
 
bool DeSerialize (bool swap, FILE *fp)
 

Friends

TBOXoperator+= (TBOX &, const TBOX &)
 
TBOXoperator&= (TBOX &, const TBOX &)
 

Detailed Description

Definition at line 29 of file rect.h.

Constructor & Destructor Documentation

TBOX::TBOX ( )
inline

Definition at line 31 of file rect.h.

31  : // empty constructor making a null box
32  bot_left (MAX_INT16, MAX_INT16), top_right (-MAX_INT16, -MAX_INT16) {
33  }
#define MAX_INT16
Definition: host.h:119
TBOX::TBOX ( const ICOORD  pt1,
const ICOORD  pt2 
)

Definition at line 33 of file rect.cpp.

36  {
37  if (pt1.x () <= pt2.x ()) {
38  if (pt1.y () <= pt2.y ()) {
39  bot_left = pt1;
40  top_right = pt2;
41  }
42  else {
43  bot_left = ICOORD (pt1.x (), pt2.y ());
44  top_right = ICOORD (pt2.x (), pt1.y ());
45  }
46  }
47  else {
48  if (pt1.y () <= pt2.y ()) {
49  bot_left = ICOORD (pt2.x (), pt1.y ());
50  top_right = ICOORD (pt1.x (), pt2.y ());
51  }
52  else {
53  bot_left = pt2;
54  top_right = pt1;
55  }
56  }
57 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
TBOX::TBOX ( inT16  left,
inT16  bottom,
inT16  right,
inT16  top 
)

Definition at line 65 of file rect.cpp.

67  : bot_left(left, bottom), top_right(right, top) {
68 }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
inT16 bottom() const
Definition: rect.h:60
TBOX::TBOX ( const FCOORD  pt)
inline

Definition at line 310 of file rect.h.

312  {
313  bot_left = ICOORD ((inT16) floor (pt.x ()), (inT16) floor (pt.y ()));
314  top_right = ICOORD ((inT16) ceil (pt.x ()), (inT16) ceil (pt.y ()));
315 }
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
float x() const
Definition: points.h:209

Member Function Documentation

bool TBOX::almost_equal ( const TBOX box,
int  tolerance 
) const

Definition at line 249 of file rect.cpp.

249  {
250  return (abs(left() - box.left()) <= tolerance &&
251  abs(right() - box.right()) <= tolerance &&
252  abs(top() - box.top()) <= tolerance &&
253  abs(bottom() - box.bottom()) <= tolerance);
254 }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
inT16 bottom() const
Definition: rect.h:60
void TBOX::append_debug ( STRING str) const
inline

Definition at line 270 of file rect.h.

270  {
271  char buffer[256];
272  sprintf(buffer, "Bounding box=(%d,%d)->(%d,%d)\n",
273  left(), bottom(), right(), top());
274  *str += buffer;
275  }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
inT16 bottom() const
Definition: rect.h:60
inT32 TBOX::area ( ) const
inline

Definition at line 111 of file rect.h.

111  { // what is the area?
112  if (!null_box ())
113  return width () * height ();
114  else
115  return 0;
116  }
bool null_box() const
Definition: rect.h:45
inT16 width() const
Definition: rect.h:104
inT16 height() const
Definition: rect.h:97
const ICOORD& TBOX::botleft ( ) const
inline

Definition at line 81 of file rect.h.

81  { // access function
82  return bot_left;
83  }
ICOORD TBOX::botright ( ) const
inline

Definition at line 85 of file rect.h.

85  { // ~ access function
86  return ICOORD (top_right.x (), bot_left.y ());
87  }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
inT16 TBOX::bottom ( ) const
inline

Definition at line 60 of file rect.h.

60  { // coord of bottom
61  return bot_left.y ();
62  }
inT16 y() const
access_function
Definition: points.h:56
TBOX TBOX::bounding_union ( const TBOX box) const

Definition at line 130 of file rect.cpp.

131  {
132  ICOORD bl; //bottom left
133  ICOORD tr; //top right
134 
135  if (box.bot_left.x () < bot_left.x ())
136  bl.set_x (box.bot_left.x ());
137  else
138  bl.set_x (bot_left.x ());
139 
140  if (box.top_right.x () > top_right.x ())
141  tr.set_x (box.top_right.x ());
142  else
143  tr.set_x (top_right.x ());
144 
145  if (box.bot_left.y () < bot_left.y ())
146  bl.set_y (box.bot_left.y ());
147  else
148  bl.set_y (bot_left.y ());
149 
150  if (box.top_right.y () > top_right.y ())
151  tr.set_y (box.top_right.y ());
152  else
153  tr.set_y (top_right.y ());
154  return TBOX (bl, tr);
155 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
TBOX()
Definition: rect.h:31
integer coordinate
Definition: points.h:30
bool TBOX::contains ( const FCOORD  pt) const
inline

Definition at line 323 of file rect.h.

323  {
324  return ((pt.x () >= bot_left.x ()) &&
325  (pt.x () <= top_right.x ()) &&
326  (pt.y () >= bot_left.y ()) && (pt.y () <= top_right.y ()));
327 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
bool TBOX::contains ( const TBOX box) const
inline

Definition at line 335 of file rect.h.

335  {
336  return (contains (box.bot_left) && contains (box.top_right));
337 }
bool contains(const FCOORD pt) const
Definition: rect.h:323
bool TBOX::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 183 of file rect.cpp.

183  {
184  if (!bot_left.DeSerialize(swap, fp)) return false;
185  if (!top_right.DeSerialize(swap, fp)) return false;
186  return true;
187 }
bool DeSerialize(bool swap, FILE *fp)
Definition: points.cpp:67
inT16 TBOX::height ( ) const
inline

Definition at line 97 of file rect.h.

97  { // how high is it?
98  if (!null_box ())
99  return top_right.y () - bot_left.y ();
100  else
101  return 0;
102  }
bool null_box() const
Definition: rect.h:45
inT16 y() const
access_function
Definition: points.h:56
TBOX TBOX::intersection ( const TBOX box) const

Definition at line 88 of file rect.cpp.

89  {
90  inT16 left;
91  inT16 bottom;
92  inT16 right;
93  inT16 top;
94  if (overlap (box)) {
95  if (box.bot_left.x () > bot_left.x ())
96  left = box.bot_left.x ();
97  else
98  left = bot_left.x ();
99 
100  if (box.top_right.x () < top_right.x ())
101  right = box.top_right.x ();
102  else
103  right = top_right.x ();
104 
105  if (box.bot_left.y () > bot_left.y ())
106  bottom = box.bot_left.y ();
107  else
108  bottom = bot_left.y ();
109 
110  if (box.top_right.y () < top_right.y ())
111  top = box.top_right.y ();
112  else
113  top = top_right.y ();
114  }
115  else {
116  left = MAX_INT16;
117  bottom = MAX_INT16;
118  top = -MAX_INT16;
119  right = -MAX_INT16;
120  }
121  return TBOX (left, bottom, right, top);
122 }
inT16 x() const
access function
Definition: points.h:52
bool overlap(const TBOX &box) const
Definition: rect.h:345
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 y() const
access_function
Definition: points.h:56
inT16 top() const
Definition: rect.h:53
short inT16
Definition: host.h:100
TBOX()
Definition: rect.h:31
#define MAX_INT16
Definition: host.h:119
inT16 bottom() const
Definition: rect.h:60
inT16 TBOX::left ( ) const
inline

Definition at line 67 of file rect.h.

67  { // coord of left
68  return bot_left.x ();
69  }
inT16 x() const
access function
Definition: points.h:52
bool TBOX::major_overlap ( const TBOX box) const
inline

Definition at line 358 of file rect.h.

359  {
360  int overlap = MIN(box.top_right.x(), top_right.x());
361  overlap -= MAX(box.bot_left.x(), bot_left.x());
362  overlap += overlap;
363  if (overlap < MIN(box.width(), width()))
364  return false;
365  overlap = MIN(box.top_right.y(), top_right.y());
366  overlap -= MAX(box.bot_left.y(), bot_left.y());
367  overlap += overlap;
368  if (overlap < MIN(box.height(), height()))
369  return false;
370  return true;
371 }
inT16 x() const
access function
Definition: points.h:52
bool overlap(const TBOX &box) const
Definition: rect.h:345
inT16 width() const
Definition: rect.h:104
inT16 y() const
access_function
Definition: points.h:56
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
inT16 height() const
Definition: rect.h:97
bool TBOX::major_x_overlap ( const TBOX box) const
inline

Definition at line 402 of file rect.h.

402  {
403  inT16 overlap = box.width();
404  if (this->left() > box.left()) {
405  overlap -= this->left() - box.left();
406  }
407  if (this->right() < box.right()) {
408  overlap -= box.right() - this->right();
409  }
410  return (overlap >= box.width() / 2 || overlap >= this->width() / 2);
411 }
bool overlap(const TBOX &box) const
Definition: rect.h:345
inT16 left() const
Definition: rect.h:67
inT16 width() const
Definition: rect.h:104
inT16 right() const
Definition: rect.h:74
short inT16
Definition: host.h:100
bool TBOX::major_y_overlap ( const TBOX box) const
inline

Definition at line 429 of file rect.h.

429  {
430  inT16 overlap = box.height();
431  if (this->bottom() > box.bottom()) {
432  overlap -= this->bottom() - box.bottom();
433  }
434  if (this->top() < box.top()) {
435  overlap -= box.top() - this->top();
436  }
437  return (overlap >= box.height() / 2 || overlap >= this->height() / 2);
438 }
bool overlap(const TBOX &box) const
Definition: rect.h:345
inT16 top() const
Definition: rect.h:53
short inT16
Definition: host.h:100
inT16 height() const
Definition: rect.h:97
inT16 bottom() const
Definition: rect.h:60
void TBOX::move ( const ICOORD  vec)
inline

Definition at line 146 of file rect.h.

147  { // by vector
148  bot_left += vec;
149  top_right += vec;
150  }
void TBOX::move ( const FCOORD  vec)
inline

Definition at line 152 of file rect.h.

153  { // by float vector
154  bot_left.set_x ((inT16) floor (bot_left.x () + vec.x ()));
155  // round left
156  bot_left.set_y ((inT16) floor (bot_left.y () + vec.y ()));
157  // round down
158  top_right.set_x ((inT16) ceil (top_right.x () + vec.x ()));
159  // round right
160  top_right.set_y ((inT16) ceil (top_right.y () + vec.y ()));
161  // round up
162  }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
short inT16
Definition: host.h:100
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
void TBOX::move_bottom_edge ( const inT16  y)
inline

Definition at line 126 of file rect.h.

127  { // by +/- y
128  bot_left += ICOORD (0, y);
129  }
integer coordinate
Definition: points.h:30
void TBOX::move_left_edge ( const inT16  x)
inline

Definition at line 131 of file rect.h.

132  { // by +/- x
133  bot_left += ICOORD (x, 0);
134  }
integer coordinate
Definition: points.h:30
void TBOX::move_right_edge ( const inT16  x)
inline

Definition at line 136 of file rect.h.

137  { // by +/- x
138  top_right += ICOORD (x, 0);
139  }
integer coordinate
Definition: points.h:30
void TBOX::move_top_edge ( const inT16  y)
inline

Definition at line 141 of file rect.h.

142  { // by +/- y
143  top_right += ICOORD (0, y);
144  }
integer coordinate
Definition: points.h:30
bool TBOX::null_box ( ) const
inline

Definition at line 45 of file rect.h.

45  { // Is box null
46  return ((left () >= right ()) || (top () <= bottom ()));
47  }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
inT16 bottom() const
Definition: rect.h:60
bool TBOX::operator== ( const TBOX other) const
inline

Definition at line 49 of file rect.h.

49  {
50  return bot_left == other.bot_left && top_right == other.top_right;
51  }
bool TBOX::overlap ( const TBOX box) const
inline

Definition at line 345 of file rect.h.

346  {
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 ()));
351 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
double TBOX::overlap_fraction ( const TBOX box) const
inline

Definition at line 378 of file rect.h.

378  {
379  double fraction = 0.0;
380  if (this->area()) {
381  fraction = this->intersection(box).area() * 1.0 / this->area();
382  }
383  return fraction;
384 }
inT32 area() const
Definition: rect.h:111
TBOX intersection(const TBOX &box) const
Definition: rect.cpp:88
void TBOX::pad ( int  xpad,
int  ypad 
)
inline

Definition at line 120 of file rect.h.

120  {
121  ICOORD pad(xpad, ypad);
122  bot_left -= pad;
123  top_right += pad;
124  }
integer coordinate
Definition: points.h:30
void pad(int xpad, int ypad)
Definition: rect.h:120
void TBOX::plot ( ScrollView fd) const
inline

Definition at line 278 of file rect.h.

279  { // where to paint
280  fd->Rectangle(bot_left.x (), bot_left.y (), top_right.x (),
281  top_right.y ());
282  }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:601
void TBOX::plot ( ScrollView fd,
ScrollView::Color  fill_colour,
ScrollView::Color  border_colour 
) const

Definition at line 164 of file rect.cpp.

168  {
169  fd->Brush(fill_colour);
170  fd->Pen(border_colour);
171  plot(fd);
172 }
void Pen(Color color)
Definition: scrollview.cpp:721
void Brush(Color color)
Definition: scrollview.cpp:727
void plot(ScrollView *fd) const
Definition: rect.h:278
void TBOX::print ( ) const
inline

Definition at line 263 of file rect.h.

263  { // print
264  tprintf("Bounding box=(%d,%d)->(%d,%d)\n",
265  left(), bottom(), right(), top());
266  }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
inT16 bottom() const
Definition: rect.h:60
inT16 TBOX::right ( ) const
inline

Definition at line 74 of file rect.h.

74  { // coord of right
75  return top_right.x ();
76  }
inT16 x() const
access function
Definition: points.h:52
void TBOX::rotate ( const FCOORD vec)
inline

Definition at line 182 of file rect.h.

182  { // by vector
183  bot_left.rotate (vec);
184  top_right.rotate (vec);
185  *this = TBOX (bot_left, top_right);
186  }
void rotate(const FCOORD &vec)
Definition: ipoints.h:241
TBOX()
Definition: rect.h:31
void TBOX::rotate_large ( const FCOORD vec)

Definition at line 73 of file rect.cpp.

73  {
74  ICOORD top_left(bot_left.x(), top_right.y());
75  ICOORD bottom_right(top_right.x(), bot_left.y());
76  top_left.rotate(vec);
77  bottom_right.rotate(vec);
78  rotate(vec);
79  TBOX box2(top_left, bottom_right);
80  *this += box2;
81 }
void rotate(const FCOORD &vec)
Definition: ipoints.h:241
inT16 x() const
access function
Definition: points.h:52
Definition: rect.h:29
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
void rotate(const FCOORD &vec)
Definition: rect.h:182
void TBOX::scale ( const float  f)
inline

Definition at line 164 of file rect.h.

165  { // by multiplier
166  bot_left.set_x ((inT16) floor (bot_left.x () * f)); // round left
167  bot_left.set_y ((inT16) floor (bot_left.y () * f)); // round down
168  top_right.set_x ((inT16) ceil (top_right.x () * f)); // round right
169  top_right.set_y ((inT16) ceil (top_right.y () * f)); // round up
170  }
inT16 x() const
access function
Definition: points.h:52
#define f(xc, yc)
Definition: imgscale.cpp:39
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
short inT16
Definition: host.h:100
void TBOX::scale ( const FCOORD  vec)
inline

Definition at line 171 of file rect.h.

172  { // by float vector
173  bot_left.set_x ((inT16) floor (bot_left.x () * vec.x ()));
174  bot_left.set_y ((inT16) floor (bot_left.y () * vec.y ()));
175  top_right.set_x ((inT16) ceil (top_right.x () * vec.x ()));
176  top_right.set_y ((inT16) ceil (top_right.y () * vec.y ()));
177  }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
short inT16
Definition: host.h:100
float y() const
Definition: points.h:212
float x() const
Definition: points.h:209
bool TBOX::Serialize ( FILE *  fp) const

Definition at line 176 of file rect.cpp.

176  {
177  if (!bot_left.Serialize(fp)) return false;
178  if (!top_right.Serialize(fp)) return false;
179  return true;
180 }
bool Serialize(FILE *fp) const
Definition: points.cpp:60
void TBOX::set_bottom ( int  y)
inline

Definition at line 63 of file rect.h.

63  {
64  bot_left.set_y(y);
65  }
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void TBOX::set_left ( int  x)
inline

Definition at line 70 of file rect.h.

70  {
71  bot_left.set_x(x);
72  }
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void TBOX::set_right ( int  x)
inline

Definition at line 77 of file rect.h.

77  {
78  top_right.set_x(x);
79  }
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void TBOX::set_to_given_coords ( int  x_min,
int  y_min,
int  x_max,
int  y_max 
)
inline

Definition at line 256 of file rect.h.

256  {
257  bot_left.set_x(x_min);
258  bot_left.set_y(y_min);
259  top_right.set_x(x_max);
260  top_right.set_y(y_max);
261  }
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void TBOX::set_top ( int  y)
inline

Definition at line 56 of file rect.h.

56  {
57  top_right.set_y(y);
58  }
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
inT16 TBOX::top ( ) const
inline

Definition at line 53 of file rect.h.

53  { // coord of top
54  return top_right.y ();
55  }
inT16 y() const
access_function
Definition: points.h:56
ICOORD TBOX::topleft ( ) const
inline

Definition at line 89 of file rect.h.

89  { // ~ access function
90  return ICOORD (bot_left.x (), top_right.y ());
91  }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
const ICOORD& TBOX::topright ( ) const
inline

Definition at line 93 of file rect.h.

93  { // access function
94  return top_right;
95  }
inT16 TBOX::width ( ) const
inline

Definition at line 104 of file rect.h.

104  { // how high is it?
105  if (!null_box ())
106  return top_right.x () - bot_left.x ();
107  else
108  return 0;
109  }
bool null_box() const
Definition: rect.h:45
inT16 x() const
access function
Definition: points.h:52
bool TBOX::x_almost_equal ( const TBOX box,
int  tolerance 
) const

Definition at line 244 of file rect.cpp.

244  {
245  return (abs(left() - box.left()) <= tolerance &&
246  abs(right() - box.right()) <= tolerance);
247 }
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
int TBOX::x_gap ( const TBOX box) const
inline

Definition at line 210 of file rect.h.

210  {
211  return MAX(bot_left.x(), box.bot_left.x()) -
212  MIN(top_right.x(), box.top_right.x());
213  }
inT16 x() const
access function
Definition: points.h:52
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
bool TBOX::x_overlap ( const TBOX box) const
inline

Definition at line 391 of file rect.h.

391  {
392  return ((box.bot_left.x() <= top_right.x()) &&
393  (box.top_right.x() >= bot_left.x()));
394 }
inT16 x() const
access function
Definition: points.h:52
double TBOX::x_overlap_fraction ( const TBOX box) const
inline

Definition at line 447 of file rect.h.

447  {
448  int low = MAX(left(), other.left());
449  int high = MIN(right(), other.right());
450  int width = right() - left();
451  if (width == 0) {
452  int x = left();
453  if (other.left() <= x && x <= other.right())
454  return 1.0;
455  else
456  return 0.0;
457  } else {
458  return MAX(0, static_cast<double>(high - low) / width);
459  }
460 }
inT16 left() const
Definition: rect.h:67
inT16 width() const
Definition: rect.h:104
inT16 right() const
Definition: rect.h:74
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
int TBOX::y_gap ( const TBOX box) const
inline

Definition at line 218 of file rect.h.

218  {
219  return MAX(bot_left.y(), box.bot_left.y()) -
220  MIN(top_right.y(), box.top_right.y());
221  }
inT16 y() const
access_function
Definition: points.h:56
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
bool TBOX::y_overlap ( const TBOX box) const
inline

Definition at line 418 of file rect.h.

418  {
419  return ((box.bot_left.y() <= top_right.y()) &&
420  (box.top_right.y() >= bot_left.y()));
421 }
inT16 y() const
access_function
Definition: points.h:56
double TBOX::y_overlap_fraction ( const TBOX box) const
inline

Definition at line 469 of file rect.h.

469  {
470  int low = MAX(bottom(), other.bottom());
471  int high = MIN(top(), other.top());
472  int height = top() - bottom();
473  if (height == 0) {
474  int y = bottom();
475  if (other.bottom() <= y && y <= other.top())
476  return 1.0;
477  else
478  return 0.0;
479  } else {
480  return MAX(0, static_cast<double>(high - low) / height);
481  }
482 }
inT16 top() const
Definition: rect.h:53
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
inT16 height() const
Definition: rect.h:97
inT16 bottom() const
Definition: rect.h:60

Friends And Related Function Documentation

TBOX& operator&= ( TBOX op1,
const TBOX op2 
)
friend

Definition at line 221 of file rect.cpp.

221  {
222  if (op1.overlap (op2)) {
223  if (op2.bot_left.x () > op1.bot_left.x ())
224  op1.bot_left.set_x (op2.bot_left.x ());
225 
226  if (op2.top_right.x () < op1.top_right.x ())
227  op1.top_right.set_x (op2.top_right.x ());
228 
229  if (op2.bot_left.y () > op1.bot_left.y ())
230  op1.bot_left.set_y (op2.bot_left.y ());
231 
232  if (op2.top_right.y () < op1.top_right.y ())
233  op1.top_right.set_y (op2.top_right.y ());
234  }
235  else {
236  op1.bot_left.set_x (MAX_INT16);
237  op1.bot_left.set_y (MAX_INT16);
238  op1.top_right.set_x (-MAX_INT16);
239  op1.top_right.set_y (-MAX_INT16);
240  }
241  return op1;
242 }
inT16 x() const
access function
Definition: points.h:52
bool overlap(const TBOX &box) const
Definition: rect.h:345
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
#define MAX_INT16
Definition: host.h:119
TBOX& operator+= ( TBOX op1,
const TBOX op2 
)
friend

Definition at line 196 of file rect.cpp.

198  {
199  if (op2.bot_left.x () < op1.bot_left.x ())
200  op1.bot_left.set_x (op2.bot_left.x ());
201 
202  if (op2.top_right.x () > op1.top_right.x ())
203  op1.top_right.set_x (op2.top_right.x ());
204 
205  if (op2.bot_left.y () < op1.bot_left.y ())
206  op1.bot_left.set_y (op2.bot_left.y ());
207 
208  if (op2.top_right.y () > op1.top_right.y ())
209  op1.top_right.set_y (op2.top_right.y ());
210 
211  return op1;
212 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61

The documentation for this class was generated from the following files: