tesseract  4.0.0-beta.1-59-g2cc4
TBOX Class Reference

#include <rect.h>

Public Member Functions

 TBOX ()
 
 TBOX (const ICOORD pt1, const ICOORD pt2)
 
 TBOX (int16_t left, int16_t bottom, int16_t right, int16_t top)
 
 TBOX (const FCOORD pt)
 
bool null_box () const
 
bool operator== (const TBOX &other) const
 
int16_t top () const
 
void set_top (int y)
 
int16_t bottom () const
 
void set_bottom (int y)
 
int16_t left () const
 
void set_left (int x)
 
int16_t right () const
 
void set_right (int x)
 
int x_middle () const
 
int y_middle () const
 
const ICOORDbotleft () const
 
ICOORD botright () const
 
ICOORD topleft () const
 
const ICOORDtopright () const
 
int16_t height () const
 
int16_t width () const
 
int32_t area () const
 
void pad (int xpad, int ypad)
 
void move_bottom_edge (const int16_t y)
 
void move_left_edge (const int16_t x)
 
void move_right_edge (const int16_t x)
 
void move_top_edge (const int16_t 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 print_to_str (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 30 of file rect.h.

Constructor & Destructor Documentation

◆ TBOX() [1/4]

TBOX::TBOX ( )
inline

Definition at line 32 of file rect.h.

32  : // empty constructor making a null box
33  bot_left (INT16_MAX, INT16_MAX), top_right (-INT16_MAX, -INT16_MAX) {
34  }

◆ TBOX() [2/4]

TBOX::TBOX ( const ICOORD  pt1,
const ICOORD  pt2 
)

Definition at line 32 of file rect.cpp.

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

◆ TBOX() [3/4]

TBOX::TBOX ( int16_t  left,
int16_t  bottom,
int16_t  right,
int16_t  top 
)

Definition at line 64 of file rect.cpp.

66  : bot_left(left, bottom), top_right(right, top) {
67 }
int16_t left() const
Definition: rect.h:68
int16_t top() const
Definition: rect.h:54
int16_t right() const
Definition: rect.h:75
int16_t bottom() const
Definition: rect.h:61

◆ TBOX() [4/4]

TBOX::TBOX ( const FCOORD  pt)
inline

Definition at line 310 of file rect.h.

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

Member Function Documentation

◆ almost_equal()

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

Definition at line 258 of file rect.cpp.

258  {
259  return (abs(left() - box.left()) <= tolerance &&
260  abs(right() - box.right()) <= tolerance &&
261  abs(top() - box.top()) <= tolerance &&
262  abs(bottom() - box.bottom()) <= tolerance);
263 }
int16_t left() const
Definition: rect.h:68
int16_t top() const
Definition: rect.h:54
int16_t right() const
Definition: rect.h:75
int16_t bottom() const
Definition: rect.h:61

◆ area()

int32_t TBOX::area ( ) const
inline

Definition at line 118 of file rect.h.

118  { // what is the area?
119  if (!null_box ())
120  return width () * height ();
121  else
122  return 0;
123  }
int16_t width() const
Definition: rect.h:111
bool null_box() const
Definition: rect.h:46
int16_t height() const
Definition: rect.h:104

◆ botleft()

const ICOORD& TBOX::botleft ( ) const
inline

Definition at line 88 of file rect.h.

88  { // access function
89  return bot_left;
90  }

◆ botright()

ICOORD TBOX::botright ( ) const
inline

Definition at line 92 of file rect.h.

92  { // ~ access function
93  return ICOORD (top_right.x (), bot_left.y ());
94  }
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
integer coordinate
Definition: points.h:30

◆ bottom()

int16_t TBOX::bottom ( ) const
inline

Definition at line 61 of file rect.h.

61  { // coord of bottom
62  return bot_left.y ();
63  }
int16_t y() const
access_function
Definition: points.h:56

◆ bounding_union()

TBOX TBOX::bounding_union ( const TBOX box) const

Definition at line 129 of file rect.cpp.

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

◆ contains() [1/2]

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 }
float x() const
Definition: points.h:209
float y() const
Definition: points.h:212
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52

◆ contains() [2/2]

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

◆ DeSerialize()

bool TBOX::DeSerialize ( bool  swap,
FILE *  fp 
)

Definition at line 192 of file rect.cpp.

192  {
193  if (!bot_left.DeSerialize(swap, fp)) return false;
194  if (!top_right.DeSerialize(swap, fp)) return false;
195  return true;
196 }
bool DeSerialize(bool swap, FILE *fp)
Definition: points.cpp:70

◆ height()

int16_t TBOX::height ( ) const
inline

Definition at line 104 of file rect.h.

104  { // how high is it?
105  if (!null_box ())
106  return top_right.y () - bot_left.y ();
107  else
108  return 0;
109  }
int16_t y() const
access_function
Definition: points.h:56
bool null_box() const
Definition: rect.h:46

◆ intersection()

TBOX TBOX::intersection ( const TBOX box) const

Definition at line 87 of file rect.cpp.

88  {
89  int16_t left;
90  int16_t bottom;
91  int16_t right;
92  int16_t top;
93  if (overlap (box)) {
94  if (box.bot_left.x () > bot_left.x ())
95  left = box.bot_left.x ();
96  else
97  left = bot_left.x ();
98 
99  if (box.top_right.x () < top_right.x ())
100  right = box.top_right.x ();
101  else
102  right = top_right.x ();
103 
104  if (box.bot_left.y () > bot_left.y ())
105  bottom = box.bot_left.y ();
106  else
107  bottom = bot_left.y ();
108 
109  if (box.top_right.y () < top_right.y ())
110  top = box.top_right.y ();
111  else
112  top = top_right.y ();
113  }
114  else {
115  left = INT16_MAX;
116  bottom = INT16_MAX;
117  top = -INT16_MAX;
118  right = -INT16_MAX;
119  }
120  return TBOX (left, bottom, right, top);
121 }
int16_t left() const
Definition: rect.h:68
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
TBOX()
Definition: rect.h:32
int16_t top() const
Definition: rect.h:54
int16_t right() const
Definition: rect.h:75
int16_t bottom() const
Definition: rect.h:61
bool overlap(const TBOX &box) const
Definition: rect.h:345

◆ left()

int16_t TBOX::left ( ) const
inline

Definition at line 68 of file rect.h.

68  { // coord of left
69  return bot_left.x ();
70  }
int16_t x() const
access function
Definition: points.h:52

◆ major_overlap()

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_t width() const
Definition: rect.h:111
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
#define MAX(x, y)
Definition: ndminx.h:24
int16_t height() const
Definition: rect.h:104
bool overlap(const TBOX &box) const
Definition: rect.h:345
#define MIN(x, y)
Definition: ndminx.h:28

◆ major_x_overlap()

bool TBOX::major_x_overlap ( const TBOX box) const
inline

Definition at line 402 of file rect.h.

402  {
403  int16_t 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 }
int16_t width() const
Definition: rect.h:111
int16_t left() const
Definition: rect.h:68
int16_t right() const
Definition: rect.h:75
bool overlap(const TBOX &box) const
Definition: rect.h:345

◆ major_y_overlap()

bool TBOX::major_y_overlap ( const TBOX box) const
inline

Definition at line 429 of file rect.h.

429  {
430  int16_t 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 }
int16_t top() const
Definition: rect.h:54
int16_t bottom() const
Definition: rect.h:61
int16_t height() const
Definition: rect.h:104
bool overlap(const TBOX &box) const
Definition: rect.h:345

◆ move() [1/2]

void TBOX::move ( const ICOORD  vec)
inline

Definition at line 153 of file rect.h.

154  { // by vector
155  bot_left += vec;
156  top_right += vec;
157  }

◆ move() [2/2]

void TBOX::move ( const FCOORD  vec)
inline

Definition at line 159 of file rect.h.

160  { // by float vector
161  bot_left.set_x ((int16_t) floor (bot_left.x () + vec.x ()));
162  // round left
163  bot_left.set_y ((int16_t) floor (bot_left.y () + vec.y ()));
164  // round down
165  top_right.set_x ((int16_t) ceil (top_right.x () + vec.x ()));
166  // round right
167  top_right.set_y ((int16_t) ceil (top_right.y () + vec.y ()));
168  // round up
169  }
float x() const
Definition: points.h:209
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
float y() const
Definition: points.h:212
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

◆ move_bottom_edge()

void TBOX::move_bottom_edge ( const int16_t  y)
inline

Definition at line 133 of file rect.h.

134  { // by +/- y
135  bot_left += ICOORD (0, y);
136  }
integer coordinate
Definition: points.h:30

◆ move_left_edge()

void TBOX::move_left_edge ( const int16_t  x)
inline

Definition at line 138 of file rect.h.

139  { // by +/- x
140  bot_left += ICOORD (x, 0);
141  }
integer coordinate
Definition: points.h:30

◆ move_right_edge()

void TBOX::move_right_edge ( const int16_t  x)
inline

Definition at line 143 of file rect.h.

144  { // by +/- x
145  top_right += ICOORD (x, 0);
146  }
integer coordinate
Definition: points.h:30

◆ move_top_edge()

void TBOX::move_top_edge ( const int16_t  y)
inline

Definition at line 148 of file rect.h.

149  { // by +/- y
150  top_right += ICOORD (0, y);
151  }
integer coordinate
Definition: points.h:30

◆ null_box()

bool TBOX::null_box ( ) const
inline

Definition at line 46 of file rect.h.

46  { // Is box null
47  return ((left () >= right ()) || (top () <= bottom ()));
48  }
int16_t left() const
Definition: rect.h:68
int16_t top() const
Definition: rect.h:54
int16_t right() const
Definition: rect.h:75
int16_t bottom() const
Definition: rect.h:61

◆ operator==()

bool TBOX::operator== ( const TBOX other) const
inline

Definition at line 50 of file rect.h.

50  {
51  return bot_left == other.bot_left && top_right == other.top_right;
52  }

◆ overlap()

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_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52

◆ overlap_fraction()

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_t area() const
Definition: rect.h:118
TBOX intersection(const TBOX &box) const
Definition: rect.cpp:87

◆ pad()

void TBOX::pad ( int  xpad,
int  ypad 
)
inline

Definition at line 127 of file rect.h.

127  {
128  ICOORD pad(xpad, ypad);
129  bot_left -= pad;
130  top_right += pad;
131  }
integer coordinate
Definition: points.h:30
void pad(int xpad, int ypad)
Definition: rect.h:127

◆ plot() [1/2]

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_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:605

◆ plot() [2/2]

void TBOX::plot ( ScrollView fd,
ScrollView::Color  fill_colour,
ScrollView::Color  border_colour 
) const

Definition at line 163 of file rect.cpp.

167  {
168  fd->Brush(fill_colour);
169  fd->Pen(border_colour);
170  plot(fd);
171 }
void Brush(Color color)
Definition: scrollview.cpp:731
void plot(ScrollView *fd) const
Definition: rect.h:278
void Pen(Color color)
Definition: scrollview.cpp:725

◆ print()

void TBOX::print ( ) const
inline

Definition at line 270 of file rect.h.

270  { // print
271  tprintf("Bounding box=(%d,%d)->(%d,%d)\n",
272  left(), bottom(), right(), top());
273  }
int16_t left() const
Definition: rect.h:68
#define tprintf(...)
Definition: tprintf.h:31
int16_t top() const
Definition: rect.h:54
int16_t right() const
Definition: rect.h:75
int16_t bottom() const
Definition: rect.h:61

◆ print_to_str()

void TBOX::print_to_str ( STRING str) const

Definition at line 175 of file rect.cpp.

175  {
176  // "(%d,%d)->(%d,%d)", left(), bottom(), right(), top()
177  str->add_str_int("(", left());
178  str->add_str_int(",", bottom());
179  str->add_str_int(")->(", right());
180  str->add_str_int(",", top());
181  *str += ')';
182 }
int16_t left() const
Definition: rect.h:68
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
int16_t top() const
Definition: rect.h:54
int16_t right() const
Definition: rect.h:75
int16_t bottom() const
Definition: rect.h:61

◆ right()

int16_t TBOX::right ( ) const
inline

Definition at line 75 of file rect.h.

75  { // coord of right
76  return top_right.x ();
77  }
int16_t x() const
access function
Definition: points.h:52

◆ rotate()

void TBOX::rotate ( const FCOORD vec)
inline

Definition at line 189 of file rect.h.

189  { // by vector
190  bot_left.rotate (vec);
191  top_right.rotate (vec);
192  *this = TBOX (bot_left, top_right);
193  }
void rotate(const FCOORD &vec)
Definition: ipoints.h:241
TBOX()
Definition: rect.h:32

◆ rotate_large()

void TBOX::rotate_large ( const FCOORD vec)

Definition at line 72 of file rect.cpp.

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

◆ scale() [1/2]

void TBOX::scale ( const float  f)
inline

Definition at line 171 of file rect.h.

172  { // by multiplier
173  bot_left.set_x ((int16_t) floor (bot_left.x () * f)); // round left
174  bot_left.set_y ((int16_t) floor (bot_left.y () * f)); // round down
175  top_right.set_x ((int16_t) ceil (top_right.x () * f)); // round right
176  top_right.set_y ((int16_t) ceil (top_right.y () * f)); // round up
177  }
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

◆ scale() [2/2]

void TBOX::scale ( const FCOORD  vec)
inline

Definition at line 178 of file rect.h.

179  { // by float vector
180  bot_left.set_x ((int16_t) floor (bot_left.x () * vec.x ()));
181  bot_left.set_y ((int16_t) floor (bot_left.y () * vec.y ()));
182  top_right.set_x ((int16_t) ceil (top_right.x () * vec.x ()));
183  top_right.set_y ((int16_t) ceil (top_right.y () * vec.y ()));
184  }
float x() const
Definition: points.h:209
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
float y() const
Definition: points.h:212
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

◆ Serialize()

bool TBOX::Serialize ( FILE *  fp) const

Definition at line 185 of file rect.cpp.

185  {
186  if (!bot_left.Serialize(fp)) return false;
187  if (!top_right.Serialize(fp)) return false;
188  return true;
189 }
bool Serialize(FILE *fp) const
Definition: points.cpp:63

◆ set_bottom()

void TBOX::set_bottom ( int  y)
inline

Definition at line 64 of file rect.h.

64  {
65  bot_left.set_y(y);
66  }
void set_y(int16_t yin)
rewrite function
Definition: points.h:65

◆ set_left()

void TBOX::set_left ( int  x)
inline

Definition at line 71 of file rect.h.

71  {
72  bot_left.set_x(x);
73  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

◆ set_right()

void TBOX::set_right ( int  x)
inline

Definition at line 78 of file rect.h.

78  {
79  top_right.set_x(x);
80  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

◆ set_to_given_coords()

void TBOX::set_to_given_coords ( int  x_min,
int  y_min,
int  x_max,
int  y_max 
)
inline

Definition at line 263 of file rect.h.

263  {
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);
268  }
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

◆ set_top()

void TBOX::set_top ( int  y)
inline

Definition at line 57 of file rect.h.

57  {
58  top_right.set_y(y);
59  }
void set_y(int16_t yin)
rewrite function
Definition: points.h:65

◆ top()

int16_t TBOX::top ( ) const
inline

Definition at line 54 of file rect.h.

54  { // coord of top
55  return top_right.y ();
56  }
int16_t y() const
access_function
Definition: points.h:56

◆ topleft()

ICOORD TBOX::topleft ( ) const
inline

Definition at line 96 of file rect.h.

96  { // ~ access function
97  return ICOORD (bot_left.x (), top_right.y ());
98  }
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
integer coordinate
Definition: points.h:30

◆ topright()

const ICOORD& TBOX::topright ( ) const
inline

Definition at line 100 of file rect.h.

100  { // access function
101  return top_right;
102  }

◆ width()

int16_t TBOX::width ( ) const
inline

Definition at line 111 of file rect.h.

111  { // how high is it?
112  if (!null_box ())
113  return top_right.x () - bot_left.x ();
114  else
115  return 0;
116  }
int16_t x() const
access function
Definition: points.h:52
bool null_box() const
Definition: rect.h:46

◆ x_almost_equal()

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

Definition at line 253 of file rect.cpp.

253  {
254  return (abs(left() - box.left()) <= tolerance &&
255  abs(right() - box.right()) <= tolerance);
256 }
int16_t left() const
Definition: rect.h:68
int16_t right() const
Definition: rect.h:75

◆ x_gap()

int TBOX::x_gap ( const TBOX box) const
inline

Definition at line 217 of file rect.h.

217  {
218  return MAX(bot_left.x(), box.bot_left.x()) -
219  MIN(top_right.x(), box.top_right.x());
220  }
int16_t x() const
access function
Definition: points.h:52
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28

◆ x_middle()

int TBOX::x_middle ( ) const
inline

Definition at line 81 of file rect.h.

81  {
82  return (bot_left.x() + top_right.x()) / 2;
83  }
int16_t x() const
access function
Definition: points.h:52

◆ x_overlap()

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_t x() const
access function
Definition: points.h:52

◆ x_overlap_fraction()

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_t width() const
Definition: rect.h:111
int16_t left() const
Definition: rect.h:68
#define MAX(x, y)
Definition: ndminx.h:24
int16_t right() const
Definition: rect.h:75
#define MIN(x, y)
Definition: ndminx.h:28

◆ y_gap()

int TBOX::y_gap ( const TBOX box) const
inline

Definition at line 225 of file rect.h.

225  {
226  return MAX(bot_left.y(), box.bot_left.y()) -
227  MIN(top_right.y(), box.top_right.y());
228  }
int16_t y() const
access_function
Definition: points.h:56
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28

◆ y_middle()

int TBOX::y_middle ( ) const
inline

Definition at line 84 of file rect.h.

84  {
85  return (bot_left.y() + top_right.y()) / 2;
86  }
int16_t y() const
access_function
Definition: points.h:56

◆ y_overlap()

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_t y() const
access_function
Definition: points.h:56

◆ y_overlap_fraction()

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 }
#define MAX(x, y)
Definition: ndminx.h:24
int16_t top() const
Definition: rect.h:54
int16_t bottom() const
Definition: rect.h:61
int16_t height() const
Definition: rect.h:104
#define MIN(x, y)
Definition: ndminx.h:28

Friends And Related Function Documentation

◆ operator &=

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

Definition at line 230 of file rect.cpp.

230  {
231  if (op1.overlap (op2)) {
232  if (op2.bot_left.x () > op1.bot_left.x ())
233  op1.bot_left.set_x (op2.bot_left.x ());
234 
235  if (op2.top_right.x () < op1.top_right.x ())
236  op1.top_right.set_x (op2.top_right.x ());
237 
238  if (op2.bot_left.y () > op1.bot_left.y ())
239  op1.bot_left.set_y (op2.bot_left.y ());
240 
241  if (op2.top_right.y () < op1.top_right.y ())
242  op1.top_right.set_y (op2.top_right.y ());
243  }
244  else {
245  op1.bot_left.set_x (INT16_MAX);
246  op1.bot_left.set_y (INT16_MAX);
247  op1.top_right.set_x (-INT16_MAX);
248  op1.top_right.set_y (-INT16_MAX);
249  }
250  return op1;
251 }
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
void set_x(int16_t xin)
rewrite function
Definition: points.h:61
bool overlap(const TBOX &box) const
Definition: rect.h:345

◆ operator+=

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

Definition at line 205 of file rect.cpp.

207  {
208  if (op2.bot_left.x () < op1.bot_left.x ())
209  op1.bot_left.set_x (op2.bot_left.x ());
210 
211  if (op2.top_right.x () > op1.top_right.x ())
212  op1.top_right.set_x (op2.top_right.x ());
213 
214  if (op2.bot_left.y () < op1.bot_left.y ())
215  op1.bot_left.set_y (op2.bot_left.y ());
216 
217  if (op2.top_right.y () > op1.top_right.y ())
218  op1.top_right.set_y (op2.top_right.y ());
219 
220  return op1;
221 }
void set_y(int16_t yin)
rewrite function
Definition: points.h:65
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52
void set_x(int16_t xin)
rewrite function
Definition: points.h:61

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