tesseract  4.0.0-1-g2a2b
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 34 of file rect.h.

Constructor & Destructor Documentation

◆ TBOX() [1/4]

TBOX::TBOX ( )
inline

Definition at line 36 of file rect.h.

36  : // empty constructor making a null box
37  bot_left (INT16_MAX, INT16_MAX), top_right (-INT16_MAX, -INT16_MAX) {
38  }

◆ 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:57
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53

◆ 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:72
int16_t top() const
Definition: rect.h:58
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ TBOX() [4/4]

TBOX::TBOX ( const FCOORD  pt)
inline

Definition at line 318 of file rect.h.

320  {
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())));
325 }
integer coordinate
Definition: points.h:32
float x() const
Definition: points.h:208
float y() const
Definition: points.h:211

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:72
int16_t top() const
Definition: rect.h:58
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ area()

int32_t TBOX::area ( ) const
inline

Definition at line 122 of file rect.h.

122  { // what is the area?
123  if (!null_box ())
124  return width () * height ();
125  else
126  return 0;
127  }
bool null_box() const
Definition: rect.h:50
int16_t width() const
Definition: rect.h:115
int16_t height() const
Definition: rect.h:108

◆ botleft()

const ICOORD& TBOX::botleft ( ) const
inline

Definition at line 92 of file rect.h.

92  { // access function
93  return bot_left;
94  }

◆ botright()

ICOORD TBOX::botright ( ) const
inline

Definition at line 96 of file rect.h.

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

◆ bottom()

int16_t TBOX::bottom ( ) const
inline

Definition at line 65 of file rect.h.

65  { // coord of bottom
66  return bot_left.y ();
67  }
int16_t y() const
access_function
Definition: points.h:57

◆ 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_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
TBOX()
Definition: rect.h:36
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ contains() [1/2]

bool TBOX::contains ( const FCOORD  pt) const
inline

Definition at line 333 of file rect.h.

333  {
334  return ((pt.x () >= bot_left.x ()) &&
335  (pt.x () <= top_right.x ()) &&
336  (pt.y () >= bot_left.y ()) && (pt.y () <= top_right.y ()));
337 }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
float x() const
Definition: points.h:208
float y() const
Definition: points.h:211

◆ contains() [2/2]

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

Definition at line 345 of file rect.h.

345  {
346  return (contains (box.bot_left) && contains (box.top_right));
347 }
bool contains(const FCOORD pt) const
Definition: rect.h:333

◆ 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:69

◆ height()

int16_t TBOX::height ( ) const
inline

Definition at line 108 of file rect.h.

108  { // how high is it?
109  if (!null_box ())
110  return top_right.y () - bot_left.y ();
111  else
112  return 0;
113  }
bool null_box() const
Definition: rect.h:50
int16_t y() const
access_function
Definition: points.h:57

◆ 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 y() const
access_function
Definition: points.h:57
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
int16_t x() const
access function
Definition: points.h:53
bool overlap(const TBOX &box) const
Definition: rect.h:355
TBOX()
Definition: rect.h:36
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ left()

int16_t TBOX::left ( ) const
inline

Definition at line 72 of file rect.h.

72  { // coord of left
73  return bot_left.x ();
74  }
int16_t x() const
access function
Definition: points.h:53

◆ major_overlap()

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

Definition at line 368 of file rect.h.

369  {
370  int overlap = std::min(box.top_right.x(), top_right.x());
371  overlap -= std::max(box.bot_left.x(), bot_left.x());
372  overlap += overlap;
373  if (overlap < std::min(box.width(), width()))
374  return false;
375  overlap = std::min(box.top_right.y(), top_right.y());
376  overlap -= std::max(box.bot_left.y(), bot_left.y());
377  overlap += overlap;
378  if (overlap < std::min(box.height(), height()))
379  return false;
380  return true;
381 }
int16_t y() const
access_function
Definition: points.h:57
int16_t width() const
Definition: rect.h:115
int16_t x() const
access function
Definition: points.h:53
bool overlap(const TBOX &box) const
Definition: rect.h:355
int16_t height() const
Definition: rect.h:108

◆ major_x_overlap()

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

Definition at line 412 of file rect.h.

412  {
413  int16_t overlap = box.width();
414  if (this->left() > box.left()) {
415  overlap -= this->left() - box.left();
416  }
417  if (this->right() < box.right()) {
418  overlap -= box.right() - this->right();
419  }
420  return (overlap >= box.width() / 2 || overlap >= this->width() / 2);
421 }
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
bool overlap(const TBOX &box) const
Definition: rect.h:355
int16_t right() const
Definition: rect.h:79

◆ major_y_overlap()

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

Definition at line 439 of file rect.h.

439  {
440  int16_t overlap = box.height();
441  if (this->bottom() > box.bottom()) {
442  overlap -= this->bottom() - box.bottom();
443  }
444  if (this->top() < box.top()) {
445  overlap -= box.top() - this->top();
446  }
447  return (overlap >= box.height() / 2 || overlap >= this->height() / 2);
448 }
int16_t top() const
Definition: rect.h:58
bool overlap(const TBOX &box) const
Definition: rect.h:355
int16_t bottom() const
Definition: rect.h:65
int16_t height() const
Definition: rect.h:108

◆ move() [1/2]

void TBOX::move ( const ICOORD  vec)
inline

Definition at line 157 of file rect.h.

158  { // by vector
159  bot_left += vec;
160  top_right += vec;
161  }

◆ move() [2/2]

void TBOX::move ( const FCOORD  vec)
inline

Definition at line 163 of file rect.h.

164  { // by float vector
165  bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() + vec.x())));
166  // round left
167  bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() + vec.y())));
168  // round down
169  top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() + vec.x())));
170  // round right
171  top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() + vec.y())));
172  // round up
173  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
float x() const
Definition: points.h:208
void set_y(int16_t yin)
rewrite function
Definition: points.h:66
float y() const
Definition: points.h:211

◆ move_bottom_edge()

void TBOX::move_bottom_edge ( const int16_t  y)
inline

Definition at line 137 of file rect.h.

138  { // by +/- y
139  bot_left += ICOORD (0, y);
140  }
integer coordinate
Definition: points.h:32

◆ move_left_edge()

void TBOX::move_left_edge ( const int16_t  x)
inline

Definition at line 142 of file rect.h.

143  { // by +/- x
144  bot_left += ICOORD (x, 0);
145  }
integer coordinate
Definition: points.h:32

◆ move_right_edge()

void TBOX::move_right_edge ( const int16_t  x)
inline

Definition at line 147 of file rect.h.

148  { // by +/- x
149  top_right += ICOORD (x, 0);
150  }
integer coordinate
Definition: points.h:32

◆ move_top_edge()

void TBOX::move_top_edge ( const int16_t  y)
inline

Definition at line 152 of file rect.h.

153  { // by +/- y
154  top_right += ICOORD (0, y);
155  }
integer coordinate
Definition: points.h:32

◆ null_box()

bool TBOX::null_box ( ) const
inline

Definition at line 50 of file rect.h.

50  { // Is box null
51  return ((left () >= right ()) || (top () <= bottom ()));
52  }
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ operator==()

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

Definition at line 54 of file rect.h.

54  {
55  return bot_left == other.bot_left && top_right == other.top_right;
56  }

◆ overlap()

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

Definition at line 355 of file rect.h.

356  {
357  return ((box.bot_left.x () <= top_right.x ()) &&
358  (box.top_right.x () >= bot_left.x ()) &&
359  (box.bot_left.y () <= top_right.y ()) &&
360  (box.top_right.y () >= bot_left.y ()));
361 }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53

◆ overlap_fraction()

double TBOX::overlap_fraction ( const TBOX box) const
inline

Definition at line 388 of file rect.h.

388  {
389  double fraction = 0.0;
390  if (this->area()) {
391  fraction = this->intersection(box).area() * 1.0 / this->area();
392  }
393  return fraction;
394 }
TBOX intersection(const TBOX &box) const
Definition: rect.cpp:87
int32_t area() const
Definition: rect.h:122

◆ pad()

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

Definition at line 131 of file rect.h.

131  {
132  ICOORD pad(xpad, ypad);
133  bot_left -= pad;
134  top_right += pad;
135  }
integer coordinate
Definition: points.h:32
void pad(int xpad, int ypad)
Definition: rect.h:131

◆ plot() [1/2]

void TBOX::plot ( ScrollView fd) const
inline

Definition at line 286 of file rect.h.

287  { // where to paint
288  fd->Rectangle(bot_left.x (), bot_left.y (), top_right.x (),
289  top_right.y ());
290  }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:602

◆ 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 plot(ScrollView *fd) const
Definition: rect.h:286
void Pen(Color color)
Definition: scrollview.cpp:722
void Brush(Color color)
Definition: scrollview.cpp:728

◆ print()

void TBOX::print ( ) const
inline

Definition at line 278 of file rect.h.

278  { // print
279  tprintf("Bounding box=(%d,%d)->(%d,%d)\n",
280  left(), bottom(), right(), top());
281  }
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ 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:72
int16_t top() const
Definition: rect.h:58
void add_str_int(const char *str, int number)
Definition: strngs.cpp:379
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65

◆ right()

int16_t TBOX::right ( ) const
inline

Definition at line 79 of file rect.h.

79  { // coord of right
80  return top_right.x ();
81  }
int16_t x() const
access function
Definition: points.h:53

◆ rotate()

void TBOX::rotate ( const FCOORD vec)
inline

Definition at line 197 of file rect.h.

197  { // by vector
198  bot_left.rotate (vec);
199  top_right.rotate (vec);
200  *this = TBOX (bot_left, top_right);
201  }
void rotate(const FCOORD &vec)
Definition: points.h:537
TBOX()
Definition: rect.h:36

◆ 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 }
void rotate(const FCOORD &vec)
Definition: rect.h:197
int16_t y() const
access_function
Definition: points.h:57
Definition: rect.h:34
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
void rotate(const FCOORD &vec)
Definition: points.h:537

◆ scale() [1/2]

void TBOX::scale ( const float  f)
inline

Definition at line 175 of file rect.h.

176  { // by multiplier
177  // round left
178  bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * f)));
179  // round down
180  bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * f)));
181  // round right
182  top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * f)));
183  // round up
184  top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * f)));
185  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ scale() [2/2]

void TBOX::scale ( const FCOORD  vec)
inline

Definition at line 186 of file rect.h.

187  { // by float vector
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())));
192  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
float x() const
Definition: points.h:208
void set_y(int16_t yin)
rewrite function
Definition: points.h:66
float y() const
Definition: points.h:211

◆ 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 68 of file rect.h.

68  {
69  bot_left.set_y(y);
70  }
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ set_left()

void TBOX::set_left ( int  x)
inline

Definition at line 75 of file rect.h.

75  {
76  bot_left.set_x(x);
77  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62

◆ set_right()

void TBOX::set_right ( int  x)
inline

Definition at line 82 of file rect.h.

82  {
83  top_right.set_x(x);
84  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62

◆ 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 271 of file rect.h.

271  {
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);
276  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ set_top()

void TBOX::set_top ( int  y)
inline

Definition at line 61 of file rect.h.

61  {
62  top_right.set_y(y);
63  }
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ top()

int16_t TBOX::top ( ) const
inline

Definition at line 58 of file rect.h.

58  { // coord of top
59  return top_right.y ();
60  }
int16_t y() const
access_function
Definition: points.h:57

◆ topleft()

ICOORD TBOX::topleft ( ) const
inline

Definition at line 100 of file rect.h.

100  { // ~ access function
101  return ICOORD (bot_left.x (), top_right.y ());
102  }
int16_t y() const
access_function
Definition: points.h:57
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53

◆ topright()

const ICOORD& TBOX::topright ( ) const
inline

Definition at line 104 of file rect.h.

104  { // access function
105  return top_right;
106  }

◆ width()

int16_t TBOX::width ( ) const
inline

Definition at line 115 of file rect.h.

115  { // how high is it?
116  if (!null_box ())
117  return top_right.x () - bot_left.x ();
118  else
119  return 0;
120  }
bool null_box() const
Definition: rect.h:50
int16_t x() const
access function
Definition: points.h:53

◆ 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:72
int16_t right() const
Definition: rect.h:79

◆ x_gap()

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

Definition at line 225 of file rect.h.

225  {
226  return std::max(bot_left.x(), box.bot_left.x()) -
227  std::min(top_right.x(), box.top_right.x());
228  }
int16_t x() const
access function
Definition: points.h:53

◆ x_middle()

int TBOX::x_middle ( ) const
inline

Definition at line 85 of file rect.h.

85  {
86  return (bot_left.x() + top_right.x()) / 2;
87  }
int16_t x() const
access function
Definition: points.h:53

◆ x_overlap()

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

Definition at line 401 of file rect.h.

401  {
402  return ((box.bot_left.x() <= top_right.x()) &&
403  (box.top_right.x() >= bot_left.x()));
404 }
int16_t x() const
access function
Definition: points.h:53

◆ x_overlap_fraction()

double TBOX::x_overlap_fraction ( const TBOX box) const
inline

Definition at line 457 of file rect.h.

457  {
458  int low = std::max(left(), other.left());
459  int high = std::min(right(), other.right());
460  int width = right() - left();
461  if (width == 0) {
462  int x = left();
463  if (other.left() <= x && x <= other.right())
464  return 1.0;
465  else
466  return 0.0;
467  } else {
468  return std::max(0.0, static_cast<double>(high - low) / width);
469  }
470 }
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t right() const
Definition: rect.h:79

◆ y_gap()

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

Definition at line 233 of file rect.h.

233  {
234  return std::max(bot_left.y(), box.bot_left.y()) -
235  std::min(top_right.y(), box.top_right.y());
236  }
int16_t y() const
access_function
Definition: points.h:57

◆ y_middle()

int TBOX::y_middle ( ) const
inline

Definition at line 88 of file rect.h.

88  {
89  return (bot_left.y() + top_right.y()) / 2;
90  }
int16_t y() const
access_function
Definition: points.h:57

◆ y_overlap()

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

Definition at line 428 of file rect.h.

428  {
429  return ((box.bot_left.y() <= top_right.y()) &&
430  (box.top_right.y() >= bot_left.y()));
431 }
int16_t y() const
access_function
Definition: points.h:57

◆ y_overlap_fraction()

double TBOX::y_overlap_fraction ( const TBOX box) const
inline

Definition at line 479 of file rect.h.

479  {
480  int low = std::max(bottom(), other.bottom());
481  int high = std::min(top(), other.top());
482  int height = top() - bottom();
483  if (height == 0) {
484  int y = bottom();
485  if (other.bottom() <= y && y <= other.top())
486  return 1.0;
487  else
488  return 0.0;
489  } else {
490  return std::max(0.0, static_cast<double>(high - low) / height);
491  }
492 }
int16_t top() const
Definition: rect.h:58
int16_t bottom() const
Definition: rect.h:65
int16_t height() const
Definition: rect.h:108

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_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
bool overlap(const TBOX &box) const
Definition: rect.h:355
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ 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_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

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