36 #ifndef VIGRA_DIFF2D_HXX
37 #define VIGRA_DIFF2D_HXX
42 #include "iteratortags.hxx"
43 #include "iteratortraits.hxx"
44 #include "iteratoradapter.hxx"
52 class Diff2DConstRowIteratorPolicy
55 typedef Diff BaseType;
56 typedef Diff value_type;
57 typedef typename Diff::MoveX difference_type;
58 typedef Diff
const & reference;
59 typedef Diff index_reference;
60 typedef Diff
const * pointer;
61 typedef std::random_access_iterator_tag iterator_category;
63 static void initialize(BaseType &) {}
65 static reference dereference(BaseType
const & d)
68 static index_reference dereference(BaseType d, difference_type n)
74 static bool equal(BaseType
const & d1, BaseType
const & d2)
75 {
return d1.x == d2.x; }
77 static bool less(BaseType
const & d1, BaseType
const & d2)
78 {
return d1.x < d2.x; }
80 static difference_type difference(BaseType
const & d1, BaseType
const & d2)
81 {
return d1.x - d2.x; }
83 static void increment(BaseType & d)
86 static void decrement(BaseType & d)
89 static void advance(BaseType & d, difference_type n)
94 class Diff2DConstColumnIteratorPolicy
97 typedef Diff BaseType;
98 typedef Diff value_type;
99 typedef typename Diff::MoveY difference_type;
100 typedef Diff
const & reference;
101 typedef Diff index_reference;
102 typedef Diff
const * pointer;
103 typedef std::random_access_iterator_tag iterator_category;
105 static void initialize(BaseType & ) {}
107 static reference dereference(BaseType
const & d)
110 static index_reference dereference(BaseType d, difference_type n)
116 static bool equal(BaseType
const & d1, BaseType
const & d2)
117 {
return d1.y == d2.y; }
119 static bool less(BaseType
const & d1, BaseType
const & d2)
120 {
return d1.y < d2.y; }
122 static difference_type difference(BaseType
const & d1, BaseType
const & d2)
123 {
return d1.y - d2.y; }
125 static void increment(BaseType & d)
128 static void decrement(BaseType & d)
131 static void advance(BaseType & d, difference_type n)
300 x = (int)(
x * factor);
301 y = (int)(
y * factor);
318 x = (int)(
x / factor);
319 y = (int)(
y / factor);
327 return Diff2D(
x * factor,
y * factor);
334 return Diff2D((
int)(
x * factor), (
int)(
y * factor));
341 return Diff2D(
x / factor,
y / factor);
348 return Diff2D((
int)(
x / factor), (
int)(
y / factor));
369 return (
x == r.
x) && (
y == r.
y);
376 return (
x != r.
x) || (
y != r.
y);
442 struct IteratorTraits<Diff2D >
444 typedef Diff2D Iterator;
445 typedef Iterator iterator;
446 typedef Iterator const_iterator;
448 typedef iterator::iterator_category iterator_category;
449 typedef iterator::value_type value_type;
450 typedef iterator::reference reference;
451 typedef iterator::index_reference index_reference;
452 typedef iterator::pointer pointer;
453 typedef iterator::difference_type difference_type;
454 typedef iterator::row_iterator row_iterator;
455 typedef iterator::column_iterator column_iterator;
456 typedef StandardConstValueAccessor<Diff2D> DefaultAccessor;
457 typedef StandardConstValueAccessor<Diff2D> default_accessor;
458 typedef VigraTrueType hasConstantStrides;
720 return Size2D(s.
x - offset.
x, s.
y - offset.
y);
765 inline Point2D operator*(Point2D l,
double r)
771 inline Point2D operator*(
double l, Point2D r)
777 inline Size2D operator*(Size2D l,
double r)
783 inline Size2D operator*(
double l, Size2D r)
789 inline Point2D operator/(Point2D l,
double r)
795 inline Size2D operator/(Size2D l,
double r)
801 inline Point2D operator*(Point2D l,
int r)
807 inline Point2D operator*(
int l, Point2D r)
813 inline Size2D operator*(Size2D l,
int r)
819 inline Size2D operator*(
int l, Size2D r)
825 inline Point2D operator/(Point2D l,
int r)
831 inline Size2D operator/(Size2D l,
int r)
874 Point2D upperLeft_, lowerRight_;
887 : upperLeft_(upperLeft), lowerRight_(lowerRight)
893 : upperLeft_(left, top), lowerRight_(right, bottom)
899 : upperLeft_(upperLeft), lowerRight_(upperLeft + size)
945 lowerRight_ += newUpperLeft - upperLeft_;
946 upperLeft_ = newUpperLeft;
961 upperLeft_ += offset;
962 lowerRight_ += offset;
991 return lowerRight_.
x;
999 return lowerRight_.
y;
1007 return lowerRight_.
x - upperLeft_.
x;
1015 return lowerRight_.
y - upperLeft_.
y;
1033 return lowerRight_ - upperLeft_;
1041 lowerRight_ = upperLeft_ +
size;
1049 lowerRight_ = upperLeft_ +
Size2D(width, height);
1059 lowerRight_ += offset;
1069 upperLeft_ +=
Diff2D(-borderWidth, -borderWidth);
1070 lowerRight_ +=
Diff2D(borderWidth, borderWidth);
1082 upperLeft_ +=
Diff2D(-borderWidth, -borderHeight);
1083 lowerRight_ +=
Diff2D(borderWidth, borderHeight);
1089 return (upperLeft_ == r.upperLeft_) && (lowerRight_ == r.lowerRight_);
1095 return (upperLeft_ != r.upperLeft_) || (lowerRight_ != r.lowerRight_);
1107 return ((lowerRight_.
x <= upperLeft_.
x) ||
1108 (lowerRight_.
y <= upperLeft_.
y));
1118 return ((upperLeft_.
x <= p.
x) &&
1119 (upperLeft_.
y <= p.
y) &&
1120 (p.
x < lowerRight_.
x) &&
1121 (p.
y < lowerRight_.
y));
1143 return ((r.upperLeft_.
x < lowerRight_.
x) &&
1144 (upperLeft_.
x < r.lowerRight_.
x) &&
1145 (r.upperLeft_.
y < lowerRight_.
y) &&
1146 (upperLeft_.
y < r.lowerRight_.
y))
1160 lowerRight_ = p +
Diff2D(1, 1);
1164 if(p.
x < upperLeft_.
x)
1166 if(p.
y < upperLeft_.
y)
1168 if(lowerRight_.
x <= p.
x)
1169 lowerRight_.
x = p.
x + 1;
1170 if(lowerRight_.
y <= p.
y)
1171 lowerRight_.
y = p.
y + 1;
1198 return operator=(r);
1200 if(r.upperLeft_.
x < upperLeft_.
x)
1201 upperLeft_.
x = r.upperLeft_.
x;
1202 if(r.upperLeft_.
y < upperLeft_.
y)
1203 upperLeft_.
y = r.upperLeft_.
y;
1204 if(lowerRight_.
x < r.lowerRight_.
x)
1205 lowerRight_.
x = r.lowerRight_.
x;
1206 if(lowerRight_.
y < r.lowerRight_.
y)
1207 lowerRight_.
y = r.lowerRight_.
y;
1233 lowerRight_ = p +
Diff2D(1, 1);
1236 lowerRight_ = upperLeft_;
1262 return operator=(r);
1264 if(upperLeft_.
x < r.upperLeft_.
x)
1265 upperLeft_.
x = r.upperLeft_.
x;
1266 if(upperLeft_.
y < r.upperLeft_.
y)
1267 upperLeft_.
y = r.upperLeft_.
y;
1268 if(r.lowerRight_.
x < lowerRight_.
x)
1269 lowerRight_.
x = r.lowerRight_.
x;
1270 if(r.lowerRight_.
y < lowerRight_.
y)
1271 lowerRight_.
y = r.lowerRight_.
y;
1281 upperLeft_ *= factor;
1282 lowerRight_ *= factor;
1292 upperLeft_ *= factor;
1293 lowerRight_ *= factor;
1303 return Rect2D(*
this)*=factor;
1312 return Rect2D(*
this)*=factor;
1340 Dist2D(
int the_width,
int the_height)
1377 {
return Diff2D(width, height); }
1396 o <<
'(' << d.
x <<
", " << d.
y <<
')';
1407 s <<
'(' << d.
x <<
'x' << d.
y <<
')';
1419 <<
" = " << r.
size() <<
"]";
1425 #endif // VIGRA_DIFF2D_HXX
Diff2D operator*(double factor) const
Definition: diff2d.hxx:332
int MoveY
Definition: diff2d.hxx:229
bool intersects(Rect2D const &r) const
Definition: diff2d.hxx:1141
int left() const
Definition: diff2d.hxx:974
Rect2D(int left, int top, int right, int bottom)
Definition: diff2d.hxx:892
Rect2D & operator*=(double factor)
Definition: diff2d.hxx:1290
int operator[](int index) const
Definition: diff2d.hxx:417
Diff2D(int ax, int ay)
Definition: diff2d.hxx:240
bool isEmpty() const
Definition: diff2d.hxx:1105
Diff2D & operator/=(double factor)
Definition: diff2d.hxx:316
Definition: diff2d.hxx:1337
int width() const
Definition: diff2d.hxx:1005
Rect2D operator|(Rect2D const &r) const
Definition: diff2d.hxx:1216
int area() const
Definition: diff2d.hxx:538
Diff2D const * pointer
Definition: diff2d.hxx:206
Rect2D & operator&=(Rect2D const &r)
Definition: diff2d.hxx:1257
Rect2D()
Definition: diff2d.hxx:879
bool operator==(Rect2D const &r) const
equality check
Definition: diff2d.hxx:1087
int y
Definition: diff2d.hxx:392
void moveBy(Diff2D const &offset)
Definition: diff2d.hxx:959
Diff2D operator-(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:711
Rect2D operator|(Point2D const &p) const
Definition: diff2d.hxx:1181
Point2D & operator=(Diff2D const &v)
Definition: diff2d.hxx:654
bool operator!=(Diff2D const &r) const
Definition: diff2d.hxx:374
Point2D()
Definition: diff2d.hxx:617
index_reference operator[](Diff2D const &offset) const
Definition: diff2d.hxx:696
Rect2D(Point2D const &upperLeft, Size2D const &size)
Definition: diff2d.hxx:898
int right() const
Definition: diff2d.hxx:989
int px() const
Definition: diff2d.hxx:640
Rect2D operator&(Rect2D const &r) const
Definition: diff2d.hxx:1320
Size2D operator-() const
Definition: diff2d.hxx:552
int x
Definition: diff2d.hxx:385
Diff2D PixelType
Definition: diff2d.hxx:190
Diff2D operator+(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:739
Two dimensional difference vector.
Definition: diff2d.hxx:185
int top() const
Definition: diff2d.hxx:981
Rect2D(Point2D const &upperLeft, Point2D const &lowerRight)
Definition: diff2d.hxx:886
void addSize(Size2D const &offset)
Definition: diff2d.hxx:1057
Point2D operator-() const
Definition: diff2d.hxx:661
Point2D const & reference
Definition: diff2d.hxx:605
Diff2D & operator=(Diff2D const &v)
Definition: diff2d.hxx:252
void setUpperLeft(Point2D const &ul)
Definition: diff2d.hxx:927
Rect2D & operator&=(Point2D const &p)
Definition: diff2d.hxx:1228
void addBorder(int borderWidth)
Definition: diff2d.hxx:1067
Size2D()
Definition: diff2d.hxx:487
index_reference operator[](Diff2D const &offset) const
Definition: diff2d.hxx:410
Diff2D()
Definition: diff2d.hxx:234
reference operator*() const
Definition: diff2d.hxx:396
void setLowerRight(Point2D const &lr)
Definition: diff2d.hxx:935
int width() const
Definition: diff2d.hxx:510
Two dimensional size object.
Definition: diff2d.hxx:482
Point2D const & upperLeft() const
Definition: diff2d.hxx:911
Two dimensional point or position.
Definition: diff2d.hxx:592
index_reference operator()(int const &dx, int const &dy) const
Definition: diff2d.hxx:689
index_reference operator()(int const &dx, int const &dy) const
Definition: diff2d.hxx:403
Diff2D value_type
Definition: diff2d.hxx:194
Size2D & operator=(Diff2D const &v)
Definition: diff2d.hxx:545
Point2D const * pointer
Definition: diff2d.hxx:613
Diff2D & operator/=(int factor)
Definition: diff2d.hxx:307
row_iterator rowIterator() const
Definition: diff2d.hxx:431
int height() const
Definition: diff2d.hxx:517
Diff2D & operator+=(Diff2D const &offset)
Definition: diff2d.hxx:271
Diff2D difference_type
Definition: diff2d.hxx:210
int MoveX
Definition: diff2d.hxx:226
Size2D size() const
Definition: diff2d.hxx:1031
int bottom() const
Definition: diff2d.hxx:997
Rect2D & operator|=(Rect2D const &r)
Definition: diff2d.hxx:1193
image_traverser_tag iterator_category
Definition: diff2d.hxx:214
pointer operator->() const
Definition: diff2d.hxx:424
Point2D & operator+=(Diff2D const &offset)
Definition: diff2d.hxx:668
Point2D(Point2D const &v)
Definition: diff2d.hxx:628
Point2D value_type
Definition: diff2d.hxx:601
Diff2D index_reference
Definition: diff2d.hxx:202
Point2D PixelType
Definition: diff2d.hxx:597
Diff2D & operator-=(Diff2D const &offset)
Definition: diff2d.hxx:280
pointer operator->() const
Definition: diff2d.hxx:703
Rect2D(Size2D const &size)
Definition: diff2d.hxx:904
Point2D & operator-=(Diff2D const &offset)
Definition: diff2d.hxx:675
Rect2D operator*(int factor) const
Definition: diff2d.hxx:1301
Rect2D & operator|=(Point2D const &p)
Definition: diff2d.hxx:1155
Diff2D operator/(int factor) const
Definition: diff2d.hxx:339
Diff2D & operator*=(double factor)
Definition: diff2d.hxx:298
void moveBy(int xOffset, int yOffset)
Definition: diff2d.hxx:967
double magnitude() const
Definition: diff2d.hxx:360
void setSize(Size2D const &size)
Definition: diff2d.hxx:1039
Size2D(int width, int height)
Definition: diff2d.hxx:492
Diff2D operator/(double factor) const
Definition: diff2d.hxx:346
Diff2D(Diff2D const &v)
Definition: diff2d.hxx:246
void addBorder(int borderWidth, int borderHeight)
Definition: diff2d.hxx:1080
void setHeight(int h)
Definition: diff2d.hxx:531
Diff2D operator*(int factor) const
Definition: diff2d.hxx:325
Two dimensional rectangle.
Definition: diff2d.hxx:872
column_iterator columnIterator() const
Definition: diff2d.hxx:436
bool contains(Point2D const &p) const
Definition: diff2d.hxx:1116
Diff2D & operator*=(int factor)
Definition: diff2d.hxx:289
bool operator==(Diff2D const &r) const
Definition: diff2d.hxx:367
Rect2D operator&(Point2D const &p) const
Definition: diff2d.hxx:1245
Rect2D operator*(double factor) const
Definition: diff2d.hxx:1310
int area() const
Definition: diff2d.hxx:1022
Diff2D const & reference
Definition: diff2d.hxx:198
void moveTo(Point2D const &newUpperLeft)
Definition: diff2d.hxx:943
IteratorAdaptor< Diff2DConstColumnIteratorPolicy< Diff2D > > column_iterator
Definition: diff2d.hxx:222
void setSize(int width, int height)
Definition: diff2d.hxx:1047
bool operator!=(Rect2D const &r) const
inequality check
Definition: diff2d.hxx:1093
void moveTo(int left, int top)
Definition: diff2d.hxx:952
Size2D(Size2D const &v)
Definition: diff2d.hxx:498
Size2D(Diff2D const &v)
Definition: diff2d.hxx:504
reference operator*() const
Definition: diff2d.hxx:682
bool contains(Rect2D const &r) const
Definition: diff2d.hxx:1130
Quickly create 1-dimensional iterator adapters.
Definition: iteratoradapter.hxx:147
Rect2D & operator*=(int factor)
Definition: diff2d.hxx:1279
int height() const
Definition: diff2d.hxx:1013
Point2D(int x, int y)
Definition: diff2d.hxx:622
Size2D & operator-=(Diff2D const &offset)
Definition: diff2d.hxx:566
Point2D index_reference
Definition: diff2d.hxx:609
int squaredMagnitude() const
Definition: diff2d.hxx:353
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
Point2D(Diff2D const &v)
Definition: diff2d.hxx:634
void setWidth(int w)
Definition: diff2d.hxx:524
Diff2D operator-() const
Definition: diff2d.hxx:264
int py() const
Definition: diff2d.hxx:647
Size2D & operator+=(Diff2D const &offset)
Definition: diff2d.hxx:559
IteratorAdaptor< Diff2DConstRowIteratorPolicy< Diff2D > > row_iterator
Definition: diff2d.hxx:218
Point2D const & lowerRight() const
Definition: diff2d.hxx:919