libcrn  3.9.5
A document image processing library
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNRect.h
Go to the documentation of this file.
1 /* Copyright 2006-2016 Yann LEYDIER, Asma OUJI, CoReNum, INSA-Lyon, Université Paris Descartes, ENS-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNRect.h
19  * \author Yann LEYDIER, Jean DUONG, Asma OUJI
20  */
21 
22 #ifndef CRNRECT_HEADER
23 #define CRNRECT_HEADER
24 
25 #include <CRNObject.h>
28 #include <iterator>
29 #include <CRNData/CRNForeach.h>
30 #include <CRNException.h>
31 #include <set>
32 
33 namespace crn
34 {
35  /****************************************************************************/
46  class Rect: public Object
47  {
48  public:
50  Rect() noexcept:bx(0),by(0),ex(0),ey(0),w(0),h(0), valid(false) {}
51 
61  inline Rect(int begX, int begY, int endX, int endY) noexcept:bx(begX),by(begY),ex(endX),ey(endY)
62  { w = ex - bx + 1; h = ey - by + 1; valid = (w >= 0) && (h >= 0); }
63 
71  Rect(int x, int y) noexcept:bx(x),by(y),ex(x),ey(y),w(1),h(1),valid(true) { }
72 
79  Rect(const Point2DInt &p) noexcept:bx(p.X),by(p.Y),ex(p.X),ey(p.Y),w(1),h(1),valid(true) { }
80 
81  Rect(const Rect&) = default;
82  Rect(Rect&&) = default;
83  virtual ~Rect() override = default;
84 
85  Rect& operator=(const Rect&) = default;
86  Rect& operator=(Rect&&) = default;
87 
89  bool operator==(const Rect &r) const noexcept;
91  bool operator!=(const Rect &r) const noexcept;
92 
94  inline bool IsValid() const noexcept { return valid; }
95 
99  inline int GetLeft() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return bx; }
103  inline int GetRight() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return ex; }
107  inline int GetTop() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return by; }
111  inline int GetBottom() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return ey; }
115  inline int GetWidth() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return w; }
119  inline int GetHeight() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return h; }
123  inline Point2DInt GetTopLeft() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return Point2DInt(bx, by); }
127  inline Point2DInt GetBottomRight() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return Point2DInt(ex, ey); }
131  inline Point2DInt GetCenter() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return Point2DInt((bx + ex) / 2, (by + ey) / 2); }
135  inline int GetCenterX() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return (bx + ex) / 2; }
139  inline int GetCenterY() const { if (!valid) throw ExceptionUninitialized("The rectangle isn't initialized."); return (by + ey) / 2; }
140 
142  unsigned int GetArea() const noexcept { return valid ? (w * h) : 0; }
144  inline unsigned int GetPerimeter() const noexcept
145  {
146  if (! valid)
147  return 0;
148  return (w*h == 1) ? 1 : (w + h) * 2 - 4;
149  }
150 
152  inline int SetLeft(int begX) noexcept
153  {
154  bx = begX;
155  if(!valid)
156  {
157  ex = bx;
158  by = ey = 0;
159  h = 1;
160  valid = true;
161  }
162  w = ex - bx + 1;
163  return bx;
164  }
166  inline int SetRight(int endX) noexcept
167  {
168  ex = endX;
169  if (!valid)
170  {
171  bx = ex;
172  by = ey = 0;
173  h = 1;
174  valid = true;
175  }
176  w = ex - bx + 1;
177  return ex;
178  }
180  inline int SetTop(int begY) noexcept
181  {
182  by = begY;
183  if (!valid)
184  {
185  ey = by;
186  ex = bx = 0;
187  w = 1;
188  valid = true;
189  }
190  h = ey - by + 1;
191  return by;
192  }
194  inline int SetBottom(int endY) noexcept
195  {
196  ey = endY;
197  if (!valid)
198  {
199  by = ey;
200  ex = bx = 0;
201  w = 1;
202  valid = true;
203  }
204  h = ey - by + 1;
205  return ey;
206  }
210  inline int SetWidth(int wid)
211  {
212  if (!valid)
213  throw ExceptionUninitialized("The rectangle isn't initialized.");
214  w = wid;
215  ex = bx + w - 1;
216  return w;
217  }
221  inline int SetHeight(int hei)
222  {
223  if (!valid)
224  throw ExceptionUninitialized("The rectangle isn't initialized.");
225  h = hei;
226  ey = by + h - 1;
227  return h;
228  }
229 
231  int Overlap(const Rect &r, Orientation orientation) const;
232 
234  Rect operator&(const Rect &r) const;
236  Rect operator|(const Rect &r) const;
238  void operator&=(const Rect &r);
240  void operator|=(const Rect &r);
241 
243  bool Contains(int x, int y) const noexcept;
245  bool Contains(const Rect &rct) const;
246 
248  const Rect& operator*=(double s);
250  Rect operator*(double s) const;
252  void Translate(int x, int y);
253 
262  template <class ITER> static Rect SmallestRectEmbedding(ITER it_begin, ITER it_end)
263  {
264  Rect first_rct = *it_begin;
265  int l = first_rct.GetLeft();
266  int r = first_rct.GetRight();
267  int t = first_rct.GetTop();
268  int b = first_rct.GetBottom();
269  ITER it = it_begin + 1;
270  while (it != it_end)
271  {
272  Rect rb = *it;
273  l = std::min(l, rb.GetLeft());
274  r = std::max(r, rb.GetRight());
275  t = std::min(t, rb.GetTop());
276  b = std::max(b, rb.GetBottom());
277  ++it;
278  }
279  return Rect(l, t, r, b);
280  }
281 
290  template <class ITER> static int MedianWidth(ITER it_begin, ITER it_end)
291  {
292  auto w = std::vector<int>();
293  for (auto it = it_begin; it != it_end; ++it)
294  w.push_back(it->GetWidth());
295  return MedianValue(w);
296  }
297 
306  template <class ITER> static int MedianHeight(ITER it_begin, ITER it_end)
307  {
308  auto h = std::vector<int>();
309  for (auto it = it_begin; it != it_end; ++it)
310  h.push_back(it->GetHeight());
311  return MedianValue(h);
312  }
313 
322  template <class ITER> static double MeanWidth(ITER it_begin, ITER it_end)
323  {
324  double cumul = 0.0;
325  double counter = 0.0;
326  ITER it = it_begin;
327  while (it != it_end)
328  {
329  cumul += ((*it).GetWidth());
330  counter += 1.0;
331  ++it;
332  }
333  return cumul / std::max(1.0, counter);
334  }
335 
344  template <class ITER> static double MeanHeight(ITER it_begin, ITER it_end)
345  {
346  double cumul = 0.0;
347  double counter = 0.0;
348  ITER it = it_begin;
349  while (it != it_end)
350  {
351  cumul += ((*it).GetHeight());
352  counter += 1.0;
353  ++it;
354  }
355  return cumul / std::max(1.0, counter);
356  }
357 
367  template <class ITER> static std::vector<Rect> FindClosestsToBorder(ITER it_begin, ITER it_end, Direction drt)
368  {
369  std::vector<Rect> closest;
370 
371  ITER it_ref = it_begin;
372 
373  if (drt == Direction::LEFT)
374  {
375  while (it_ref != it_end)
376  {
377  bool is_extremal = true;
378  int border_ref = it_ref->GetLeft();
379 
380  ITER it_cmp = it_begin;
381 
382  while ((it_cmp != it_end) && (is_extremal))
383  {
384  if (it_cmp != it_ref)
385  if (it_ref->Overlap(*it_cmp, Orientation::VERTICAL))
386  if (border_ref > it_cmp->GetLeft())
387  is_extremal = false;
388 
389  ++it_cmp;
390  }
391 
392  if (is_extremal)
393  closest.push_back(*it_ref);
394 
395  ++it_ref;
396  }
397  }
398  else if (drt == Direction::RIGHT)
399  {
400  while (it_ref != it_end)
401  {
402  bool is_extremal = true;
403  int border_ref = it_ref->GetRight();
404 
405  ITER it_cmp = it_begin;
406 
407  while ((it_cmp != it_end) && (is_extremal))
408  {
409  if (it_cmp != it_ref)
410  if (it_ref->Overlap(*it_cmp, Orientation::VERTICAL))
411  if (border_ref < it_cmp->GetRight())
412  is_extremal = false;
413 
414  ++it_cmp;
415  }
416 
417  if (is_extremal)
418  closest.push_back(*it_ref);
419 
420  ++it_ref;
421  }
422  }
423  else if (drt == Direction::TOP)
424  {
425  while (it_ref != it_end)
426  {
427  bool is_extremal = true;
428  int border_ref = it_ref->GetTop();
429 
430  ITER it_cmp = it_begin;
431 
432  while ((it_cmp != it_end) && (is_extremal))
433  {
434  if (it_cmp != it_ref)
435  if (it_ref->Overlap(*it_cmp, Orientation::HORIZONTAL))
436  if (border_ref > it_cmp->GetTop())
437  is_extremal = false;
438 
439  ++it_cmp;
440  }
441 
442  if (is_extremal)
443  closest.push_back(*it_ref);
444 
445  ++it_ref;
446  }
447  }
448  else if (drt == Direction::BOTTOM)
449  {
450  while (it_ref != it_end)
451  {
452  bool is_extremal = true;
453  int border_ref = it_ref->GetBottom();
454 
455  ITER it_cmp = it_begin;
456 
457  while ((it_cmp != it_end) && (is_extremal))
458  {
459  if (it_cmp != it_ref)
460  if (it_ref->Overlap(*it_cmp, Orientation::HORIZONTAL))
461  if (border_ref < it_cmp->GetBottom())
462  is_extremal = false;
463 
464  ++it_cmp;
465  }
466 
467  if (is_extremal)
468  closest.push_back(*it_ref);
469 
470  ++it_ref;
471  }
472  }
473 
474  return closest;
475  }
476 
485  template <class ITER> std::vector<Rect> FindIncluded(ITER it_begin, ITER it_end)
486  {
487  std::vector<Rect> included;
488  const auto r_left = GetLeft();
489  const auto r_right = GetRight();
490  const auto r_top = GetTop();
491  const auto r_bottom = GetBottom();
492  ITER it = it_begin;
493  while (it != it_end)
494  {
495  Rect r_i = *it;
496  if((r_i.GetTop() >= r_top) && (r_i.GetBottom() <= r_bottom) &&
497  (r_i.GetLeft() >= r_left) && (r_i.GetRight() <= r_right))
498  {
499  included.push_back(r_i);
500  }
501  ++it;
502  }
503  return included;
504  }
505 
515  template <class ITER> std::vector<Rect> FindIntersecting(ITER it_begin, ITER it_end, double ratio = 0)
516  {
517  ratio = std::max(ratio, 0.0);
518  ratio = std::min(ratio, 1.0);
519  std::vector<Rect> touching;
520  ITER it = it_begin;
521  while (it != it_end)
522  {
523  Rect rb = *it;
524  if (rb.IsValid())
525  {
526  Rect rct_inter = (*this)&rb;
527  if((rct_inter).IsValid())
528  {
529  if (rct_inter.GetArea() > ratio * rb.GetArea())
530  {
531  touching.push_back(rb);
532  }
533  }
534  }
535  ++it;
536  }
537  return touching;
538  }
539 
541  String ToString() const;
542 
547  class Sorter: public std::binary_function<const Rect&, const Rect&, bool>
548  {
549  public:
551  Sorter(Direction sort_direction);
560  bool operator()(const Rect &r1, const Rect &r2) const;
561  private:
562  Direction direction;
563  };
564 
569  class OrthogonalSorter: public std::binary_function<const Rect&, const Rect&, bool>
570  {
571  public:
573  OrthogonalSorter(Direction sort_direction);
583  bool operator()(const Rect &r1, const Rect &r2) const;
584  private:
585  Direction direction;
586  };
587 
592  class InclusionSorter: public std::binary_function<const Rect&, const Rect&, bool>
593  {
594  public:
605  bool operator()(const Rect &r1, const Rect &r2) const;
606  };
607 
612  class HorizontalStretchingSorter: public std::binary_function<const Rect&, const Rect&, bool>
613  {
614  public:
625  bool operator()(const Rect &r1, const Rect &r2) const;
626  };
627 
632  class AreaSorter: public std::binary_function<const Rect&, const Rect&, bool>
633  {
634  public:
638  inline AreaSorter(bool biggertosmaller = false):big2low(biggertosmaller) {}
646  inline bool operator()(const Rect &r1, const Rect &r2) const
647  { if (big2low)
648  return r1.GetArea() > r2.GetArea();
649  else
650  return r1.GetArea() < r2.GetArea();
651  }
652  private:
653  bool big2low;
654  };
655 
660  class HeightSorter: public std::binary_function<const Rect&, const Rect&, bool>
661  {
662  public:
666  inline HeightSorter(bool tallertosmaller = false):tall2small(tallertosmaller) {}
674  inline bool operator()(const Rect &r1, const Rect &r2) const
675  { if (tall2small)
676  return r1.GetHeight() > r2.GetHeight();
677  else
678  return r1.GetHeight() < r2.GetHeight();
679  }
680  private:
681  bool tall2small;
682  };
683 
684 
689  struct BitwiseCompare: public std::binary_function<const Rect&, const Rect&, bool>
690  {
692  inline bool operator()(const Rect &r1, const Rect &r2) const
693  {
694  if (r1.GetLeft() < r2.GetLeft())
695  return true;
696  else if (r1.GetLeft() == r2.GetLeft())
697  {
698  if (r1.GetTop() < r2.GetTop())
699  return true;
700  else if (r1.GetTop() == r2.GetTop())
701  {
702  if ((r1.GetRight() < r2.GetRight()))
703  return true;
704  else if ((r1.GetRight() == r2.GetRight()))
705  {
706  if ((r1.GetBottom() < r2.GetBottom()))
707  return true;
708  }
709  }
710  }
711  return false;
712  }
713  };
715  using Set = std::set<Rect, Rect::BitwiseCompare>;
717  static Set EmptySet() { return Set(BitwiseCompare()); }
718 
723  class iterator: public std::iterator<std::input_iterator_tag, const crn::Point2DInt>
724  {
725  public:
726  iterator() noexcept:valid(false) {}
727  iterator(const Rect &r) noexcept:pos(r.GetLeft(), r.GetTop()),minx(r.GetLeft()),maxx(r.GetRight()),maxy(r.GetBottom()),valid(true) {}
728  iterator(const iterator &) = default;
729  iterator(iterator &&) = default;
730  virtual ~iterator() {}
731  iterator& operator=(const iterator &) = default;
732  iterator& operator=(iterator &&) = default;
733  bool operator==(const iterator &other) const noexcept;
734  bool operator!=(const iterator &other) const noexcept { return !(other == *this); }
735  virtual const iterator& operator++() noexcept;
736  iterator operator++(int nouse) noexcept;
737  reference operator*() const noexcept { return pos; }
738  pointer operator->() const noexcept { return &pos; }
739  bool IsValid() const noexcept { return valid; }
740  protected:
742  int minx, maxx, maxy;
743  bool valid;
744  };
746  inline iterator begin() const { return iterator(*this); }
748  inline iterator end() const { return iterator(); }
750  inline iterator cbegin() const { return iterator(*this); }
752  inline iterator cend() const { return iterator(); }
753 
758  class spiral_iterator: public std::iterator<std::input_iterator_tag, const crn::Point2DInt>
759  {
760  public:
762  spiral_iterator(const Rect &r);
763  spiral_iterator(const spiral_iterator &) = default;
764  spiral_iterator(spiral_iterator &&) = default;
766  spiral_iterator& operator=(const spiral_iterator &) = default;
768  bool operator==(const spiral_iterator &other) const;
769  bool operator!=(const spiral_iterator &other) const { return !(other == *this); }
770  const spiral_iterator& operator++();
771  spiral_iterator operator++(int nouse);
772  reference operator*() const { return pos; }
773  pointer operator->() const { return &pos; }
774  bool IsValid() const { return valid; }
775 
776  private:
777  void update();
778  int rectl = 0, rectt = 0, rectr = 0, rectb = 0;
779  Point2DInt pos;
780  Point2DInt ref;
781  int border = 0;
782  int framel = 0, framer = 0, framet = 0, frameb = 0;
783  Direction dir;
784  int offset = 0;
785  int limit = 0;
786  int pass = 0;
787  Point2DInt pdir;
788  bool preproc = false;
789  bool valid = false;
790  };
792  inline spiral_iterator SBegin() const { return spiral_iterator(*this); }
794  inline spiral_iterator SEnd() const { return spiral_iterator(); }
795 
797  void Deserialize(xml::Element &el);
799  xml::Element Serialize(xml::Element &parent) const;
800 
801  private:
802  int bx, by, ex, ey;
803  int w, h;
804  bool valid;
808  };
809  template<> struct IsSerializable<Rect> : public std::true_type {};
810  template<> struct IsClonable<Rect> : public std::true_type {};
811 
813 
814 }
815 
818 
819 #endif
820 
T MedianValue(const std::vector< T > &v)
Median value.
virtual ~Rect() override=default
virtual const iterator & operator++() noexcept
Definition: CRNRect.cpp:483
AreaSorter(bool biggertosmaller=false)
Constructor.
Definition: CRNRect.h:638
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.cpp:340
Functor to sort rectangles regarding horizontal stretching values.
Definition: CRNRect.h:612
#define CRN_SERIALIZATION_CONSTRUCTOR(classname)
Defines a default constructor from xml element.
Definition: CRNObject.h:165
pointer operator->() const
Definition: CRNRect.h:773
Point2DInt GetBottomRight() const
Returns the bottom-right coordinates.
Definition: CRNRect.h:127
OrthogonalSorter(Direction sort_direction)
Constructor.
Definition: CRNRect.cpp:318
bool operator==(const spiral_iterator &other) const
Definition: CRNRect.cpp:647
#define CRN_ADD_RANGED_FOR_TO_CONST_POINTERS(TYPE)
Enables ranged for for smart pointers on a type.
Definition: CRNForeach.h:51
Rect(const Point2DInt &p) noexcept
Rectangle constructor.
Definition: CRNRect.h:79
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.cpp:257
Orientation
An enumeration of orientations.
Definition: CRNMath.h:152
spiral_iterator & operator=(const spiral_iterator &)=default
static Set EmptySet()
Creates an empty set of Rects.
Definition: CRNRect.h:717
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.cpp:419
InclusionSorter()
Constructor.
Definition: CRNRect.h:596
XML element.
Definition: CRNXml.h:135
int Overlap(const Rect &r, Orientation orientation) const
Compute overlap in a given orientation.
Definition: CRNRect.cpp:101
Functor to sort rectangles regarding surfaces.
Definition: CRNRect.h:660
iterator & operator=(const iterator &)=default
int GetBottom() const
Returns the bottommost coordinate.
Definition: CRNRect.h:111
Unintialized object error.
Definition: CRNException.h:155
Functor to sort Rects in sets and maps.
Definition: CRNRect.h:689
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.cpp:401
Direction
An enumeration of directions.
Definition: CRNMath.h:122
#define CRN_ADD_RANGED_FOR_TO_POINTERS(TYPE)
Enables ranged for for smart pointers on a type.
Definition: CRNForeach.h:37
int SetHeight(int hei)
Changes the height of the rectangle.
Definition: CRNRect.h:221
spiral_iterator SBegin() const
Returns an spiral iterator to the first point of the rectangle.
Definition: CRNRect.h:792
iterator() noexcept
Definition: CRNRect.h:726
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.h:646
Rect operator|(const Rect &r) const
Computes the union of two rectangles.
Definition: CRNRect.cpp:124
int GetTop() const
Returns the topmost coordinate.
Definition: CRNRect.h:107
iterator cbegin() const
Returns an iterator to the first point of the rectangle.
Definition: CRNRect.h:750
int GetLeft() const
Returns the leftmost coordinate.
Definition: CRNRect.h:99
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.h:674
Functor to sort rectangles regarding surfaces.
Definition: CRNRect.h:632
static std::vector< Rect > FindClosestsToBorder(ITER it_begin, ITER it_end, Direction drt)
Get rectangles closest to border in a direction from a collection of rectangles.
Definition: CRNRect.h:367
A UTF32 character string class.
Definition: CRNString.h:61
void Deserialize(xml::Element &el)
Initializes the object from an XML element. Unsafe.
Definition: CRNRect.cpp:550
int SetBottom(int endY) noexcept
Changes the bottommost coordinate.
Definition: CRNRect.h:194
std::set< Rect, Rect::BitwiseCompare > Set
A set of Rects.
Definition: CRNRect.h:715
spiral_iterator SEnd() const
Returns an spiral iterator after the last point of the rectangle.
Definition: CRNRect.h:794
#define false
Definition: ConvertUTF.cpp:56
bool operator()(const Rect &r1, const Rect &r2) const
Comparison function.
Definition: CRNRect.h:692
HorizontalStretchingSorter()
Constructor.
Definition: CRNRect.h:616
int SetWidth(int wid)
Changes the width of the rectangle.
Definition: CRNRect.h:210
crn::Point2DInt pos
Definition: CRNRect.h:741
bool Contains(int x, int y) const noexcept
Checks if the rectangle contains a point.
Definition: CRNRect.cpp:514
const Rect & operator*=(double s)
Scales the rectangle.
Definition: CRNRect.cpp:436
xml::Element Serialize(xml::Element &parent) const
Dumps the object to an XML element. Unsafe.
Definition: CRNRect.cpp:579
Sorter(Direction sort_direction)
Constructor.
Definition: CRNRect.cpp:236
unsigned int GetArea() const noexcept
Returns the area of the rectangle.
Definition: CRNRect.h:142
unsigned int GetPerimeter() const noexcept
Returns the perimeter of the rectangle.
Definition: CRNRect.h:144
Rect & operator=(const Rect &)=default
Functor to sort rectangles regarding directions.
Definition: CRNRect.h:547
iterator end() const
Returns an iterator after the last point of the rectangle.
Definition: CRNRect.h:748
void operator&=(const Rect &r)
Keeps only the intersecting part with another rectangle.
Definition: CRNRect.cpp:147
bool IsValid() const
Definition: CRNRect.h:774
bool IsValid() const noexcept
Returns whether the rect is valid.
Definition: CRNRect.h:94
const spiral_iterator & operator++()
Definition: CRNRect.cpp:658
Functor to sort rectangles by inclusion.
Definition: CRNRect.h:592
bool operator!=(const iterator &other) const noexcept
Definition: CRNRect.h:734
iterator begin() const
Returns an iterator to the first point of the rectangle.
Definition: CRNRect.h:746
Point2DInt GetCenter() const
Returns the center coordinates.
Definition: CRNRect.h:131
bool IsValid() const noexcept
Definition: CRNRect.h:739
iterator cend() const
Returns an iterator after the last point of the rectangle.
Definition: CRNRect.h:752
void Translate(int x, int y)
Translates the rectangle.
Definition: CRNRect.cpp:598
pointer operator->() const noexcept
Definition: CRNRect.h:738
int GetHeight() const
Returns the height of the rectangle.
Definition: CRNRect.h:119
Rect operator&(const Rect &r) const
Computes the intersection of two rectangles.
Definition: CRNRect.cpp:74
static int MedianWidth(ITER it_begin, ITER it_end)
Get median width value for a collection of rectangles.
Definition: CRNRect.h:290
Point2DInt GetTopLeft() const
Returns the top-left coordinates.
Definition: CRNRect.h:123
Rect() noexcept
Dummy constructor. DO NOT USE.
Definition: CRNRect.h:50
HeightSorter(bool tallertosmaller=false)
Constructor.
Definition: CRNRect.h:666
std::vector< Rect > FindIntersecting(ITER it_begin, ITER it_end, double ratio=0)
Get the rectangles intersecting significantly this from a collection.
Definition: CRNRect.h:515
bool operator==(const iterator &other) const noexcept
Definition: CRNRect.cpp:473
int SetRight(int endX) noexcept
Changes the rightmost coordinate.
Definition: CRNRect.h:166
int SetTop(int begY) noexcept
Changes the topmost coordinate.
Definition: CRNRect.h:180
bool operator!=(const spiral_iterator &other) const
Definition: CRNRect.h:769
static Rect SmallestRectEmbedding(ITER it_begin, ITER it_end)
Get the smallest rectangle embedding a collection of rectangles.
Definition: CRNRect.h:262
int GetWidth() const
Returns the width of the rectangle.
Definition: CRNRect.h:115
static double MeanWidth(ITER it_begin, ITER it_end)
Get average width value for a collection of rectangles.
Definition: CRNRect.h:322
static double MeanHeight(ITER it_begin, ITER it_end)
Get median height value for a collection of rectangles.
Definition: CRNRect.h:344
virtual ~iterator()
Definition: CRNRect.h:730
int GetCenterX() const
Returns the horizontal center coordinate.
Definition: CRNRect.h:135
Functor to sort rectangles regarding orthogonal directions.
Definition: CRNRect.h:569
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
Definition: CRNObject.h:173
Rect operator*(double s) const
Creates a scaled rectangle.
Definition: CRNRect.cpp:460
void operator|=(const Rect &r)
Merges with another rectangle.
Definition: CRNRect.cpp:178
String ToString() const
Dumps to a string.
Definition: CRNRect.cpp:206
iterator for a Rect
Definition: CRNRect.h:723
CRN_ALIAS_SMART_PTR(ImageBW)
bool operator==(const Rect &r) const noexcept
Checks if two rectangles are identical.
Definition: CRNRect.cpp:38
Rect(int x, int y) noexcept
Rectangle constructor.
Definition: CRNRect.h:71
bool operator!=(const Rect &r) const noexcept
Checks if two rectangles are different.
Definition: CRNRect.cpp:56
A 2D point class.
Definition: CRNPoint2DInt.h:39
static int MedianHeight(ITER it_begin, ITER it_end)
Get median height value for a collection of rectangles.
Definition: CRNRect.h:306
int GetRight() const
Returns the rightmost coordinate.
Definition: CRNRect.h:103
reference operator*() const
Definition: CRNRect.h:772
int GetCenterY() const
Returns the vertical center coordinate.
Definition: CRNRect.h:139
Spiral iterator for a Rect.
Definition: CRNRect.h:758
iterator(const Rect &r) noexcept
Definition: CRNRect.h:727
Rect(int begX, int begY, int endX, int endY) noexcept
Rectangle constructor.
Definition: CRNRect.h:61
int SetLeft(int begX) noexcept
Changes the leftmost coordinate.
Definition: CRNRect.h:152
std::vector< Rect > FindIncluded(ITER it_begin, ITER it_end)
Get the rectangles included in this.
Definition: CRNRect.h:485
A rectangle class.
Definition: CRNRect.h:46