36#ifndef VIGRA_DIFF2D_HXX
37#define VIGRA_DIFF2D_HXX
42#include "iteratortags.hxx"
43#include "iteratortraits.hxx"
44#include "iteratoradapter.hxx"
52class 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)
94class 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);
442struct 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;
706 return Size2D(s.
x - offset.
x, s.
y - offset.
y);
751inline Point2D operator*(Point2D l,
double r)
757inline Point2D operator*(
double l, Point2D r)
763inline Size2D operator*(Size2D l,
double r)
769inline Size2D operator*(
double l, Size2D r)
775inline Point2D operator/(Point2D l,
double r)
781inline Size2D operator/(Size2D l,
double r)
787inline Point2D operator*(Point2D l,
int r)
793inline Point2D operator*(
int l, Point2D r)
799inline Size2D operator*(Size2D l,
int r)
805inline Size2D operator*(
int l, Size2D r)
811inline Point2D operator/(Point2D l,
int r)
817inline Size2D operator/(Size2D l,
int r)
860 Point2D upperLeft_, lowerRight_;
931 lowerRight_ += newUpperLeft - upperLeft_;
932 upperLeft_ = newUpperLeft;
947 upperLeft_ += offset;
948 lowerRight_ += offset;
977 return lowerRight_.
x;
985 return lowerRight_.
y;
993 return lowerRight_.
x - upperLeft_.
x;
1001 return lowerRight_.
y - upperLeft_.
y;
1019 return lowerRight_ - upperLeft_;
1027 lowerRight_ = upperLeft_ +
size;
1045 lowerRight_ += offset;
1055 upperLeft_ +=
Diff2D(-borderWidth, -borderWidth);
1056 lowerRight_ +=
Diff2D(borderWidth, borderWidth);
1068 upperLeft_ +=
Diff2D(-borderWidth, -borderHeight);
1069 lowerRight_ +=
Diff2D(borderWidth, borderHeight);
1075 return (upperLeft_ == r.upperLeft_) && (lowerRight_ == r.lowerRight_);
1081 return (upperLeft_ != r.upperLeft_) || (lowerRight_ != r.lowerRight_);
1093 return ((lowerRight_.
x <= upperLeft_.
x) ||
1094 (lowerRight_.
y <= upperLeft_.
y));
1104 return ((upperLeft_.
x <= p.
x) &&
1105 (upperLeft_.
y <= p.
y) &&
1106 (p.
x < lowerRight_.
x) &&
1107 (p.
y < lowerRight_.
y));
1129 return ((r.upperLeft_.
x < lowerRight_.
x) &&
1130 (upperLeft_.
x < r.lowerRight_.
x) &&
1131 (r.upperLeft_.
y < lowerRight_.
y) &&
1132 (upperLeft_.
y < r.lowerRight_.
y))
1146 lowerRight_ = p +
Diff2D(1, 1);
1150 if(p.
x < upperLeft_.
x)
1152 if(p.
y < upperLeft_.
y)
1154 if(lowerRight_.
x <= p.
x)
1155 lowerRight_.
x = p.
x + 1;
1156 if(lowerRight_.
y <= p.
y)
1157 lowerRight_.
y = p.
y + 1;
1184 return operator=(r);
1186 if(r.upperLeft_.
x < upperLeft_.
x)
1187 upperLeft_.
x = r.upperLeft_.
x;
1188 if(r.upperLeft_.
y < upperLeft_.
y)
1189 upperLeft_.
y = r.upperLeft_.
y;
1190 if(lowerRight_.
x < r.lowerRight_.
x)
1191 lowerRight_.
x = r.lowerRight_.
x;
1192 if(lowerRight_.
y < r.lowerRight_.
y)
1193 lowerRight_.
y = r.lowerRight_.
y;
1219 lowerRight_ = p +
Diff2D(1, 1);
1222 lowerRight_ = upperLeft_;
1248 return operator=(r);
1250 if(upperLeft_.
x < r.upperLeft_.
x)
1251 upperLeft_.
x = r.upperLeft_.
x;
1252 if(upperLeft_.
y < r.upperLeft_.
y)
1253 upperLeft_.
y = r.upperLeft_.
y;
1254 if(r.lowerRight_.
x < lowerRight_.
x)
1255 lowerRight_.
x = r.lowerRight_.
x;
1256 if(r.lowerRight_.
y < lowerRight_.
y)
1257 lowerRight_.
y = r.lowerRight_.
y;
1267 upperLeft_ *= factor;
1268 lowerRight_ *= factor;
1278 upperLeft_ *= factor;
1279 lowerRight_ *= factor;
1289 return Rect2D(*
this)*=factor;
1298 return Rect2D(*
this)*=factor;
1326 Dist2D(
int the_width,
int the_height)
1363 {
return Diff2D(width, height); }
1382 o <<
'(' << d.
x <<
", " << d.
y <<
')';
1393 s <<
'(' << d.
x <<
'x' << d.
y <<
')';
1405 <<
" = " << r.
size() <<
"]";
Two dimensional difference vector.
Definition diff2d.hxx:186
bool operator==(Diff2D const &r) const
Definition diff2d.hxx:367
int squaredMagnitude() const
Definition diff2d.hxx:353
int y
Definition diff2d.hxx:392
Diff2D operator*(double factor) const
Definition diff2d.hxx:332
Diff2D const & reference
Definition diff2d.hxx:198
image_traverser_tag iterator_category
Definition diff2d.hxx:214
Diff2D & operator=(Diff2D const &v)
Definition diff2d.hxx:252
IteratorAdaptor< Diff2DConstColumnIteratorPolicy< Diff2D > > column_iterator
Definition diff2d.hxx:222
int operator[](int index) const
Definition diff2d.hxx:417
int MoveY
Definition diff2d.hxx:229
Diff2D const * pointer
Definition diff2d.hxx:206
Diff2D operator/(double factor) const
Definition diff2d.hxx:346
int x
Definition diff2d.hxx:385
Diff2D(Diff2D const &v)
Definition diff2d.hxx:246
Diff2D & operator-=(Diff2D const &offset)
Definition diff2d.hxx:280
Diff2D & operator*=(double factor)
Definition diff2d.hxx:298
Diff2D PixelType
Definition diff2d.hxx:190
index_reference operator()(int const &dx, int const &dy) const
Definition diff2d.hxx:403
Diff2D & operator+=(Diff2D const &offset)
Definition diff2d.hxx:271
Diff2D index_reference
Definition diff2d.hxx:202
bool operator!=(Diff2D const &r) const
Definition diff2d.hxx:374
row_iterator rowIterator() const
Definition diff2d.hxx:431
Diff2D value_type
Definition diff2d.hxx:194
IteratorAdaptor< Diff2DConstRowIteratorPolicy< Diff2D > > row_iterator
Definition diff2d.hxx:218
Diff2D difference_type
Definition diff2d.hxx:210
index_reference operator[](Diff2D const &offset) const
Definition diff2d.hxx:410
Diff2D()
Definition diff2d.hxx:234
Diff2D & operator*=(int factor)
Definition diff2d.hxx:289
reference operator*() const
Definition diff2d.hxx:396
Diff2D operator-() const
Definition diff2d.hxx:264
Diff2D & operator/=(double factor)
Definition diff2d.hxx:316
Diff2D operator*(int factor) const
Definition diff2d.hxx:325
Diff2D & operator/=(int factor)
Definition diff2d.hxx:307
int MoveX
Definition diff2d.hxx:226
column_iterator columnIterator() const
Definition diff2d.hxx:436
pointer operator->() const
Definition diff2d.hxx:424
Diff2D(int ax, int ay)
Definition diff2d.hxx:240
double magnitude() const
Definition diff2d.hxx:360
Diff2D operator/(int factor) const
Definition diff2d.hxx:339
Definition diff2d.hxx:1324
Quickly create 1-dimensional iterator adapters.
Definition iteratoradapter.hxx:148
Two dimensional point or position.
Definition diff2d.hxx:586
Point2D operator-() const
Definition diff2d.hxx:647
Point2D PixelType
Definition diff2d.hxx:590
Point2D const * pointer
Definition diff2d.hxx:606
Point2D const & reference
Definition diff2d.hxx:598
Point2D & operator=(Diff2D const &v)
Definition diff2d.hxx:640
Point2D index_reference
Definition diff2d.hxx:602
Point2D(int x, int y)
Definition diff2d.hxx:614
index_reference operator()(int const &dx, int const &dy) const
Definition diff2d.hxx:675
Point2D(Diff2D const &v)
Definition diff2d.hxx:620
int py() const
Definition diff2d.hxx:633
index_reference operator[](Diff2D const &offset) const
Definition diff2d.hxx:682
Point2D & operator+=(Diff2D const &offset)
Definition diff2d.hxx:654
reference operator*() const
Definition diff2d.hxx:668
Point2D value_type
Definition diff2d.hxx:594
Point2D & operator-=(Diff2D const &offset)
Definition diff2d.hxx:661
pointer operator->() const
Definition diff2d.hxx:689
int px() const
Definition diff2d.hxx:626
Two dimensional rectangle.
Definition diff2d.hxx:859
int top() const
Definition diff2d.hxx:967
void addBorder(int borderWidth, int borderHeight)
Definition diff2d.hxx:1066
bool contains(Rect2D const &r) const
Definition diff2d.hxx:1116
Rect2D()
Definition diff2d.hxx:865
void setSize(Size2D const &size)
Definition diff2d.hxx:1025
void addBorder(int borderWidth)
Definition diff2d.hxx:1053
Rect2D(Point2D const &upperLeft, Size2D const &size)
Definition diff2d.hxx:884
Rect2D operator|(Rect2D const &r) const
Definition diff2d.hxx:1202
void moveBy(Diff2D const &offset)
Definition diff2d.hxx:945
void setSize(int width, int height)
Definition diff2d.hxx:1033
Rect2D & operator&=(Point2D const &p)
Definition diff2d.hxx:1214
int right() const
Definition diff2d.hxx:975
Point2D const & upperLeft() const
Definition diff2d.hxx:897
int bottom() const
Definition diff2d.hxx:983
void moveBy(int xOffset, int yOffset)
Definition diff2d.hxx:953
Rect2D & operator*=(int factor)
Definition diff2d.hxx:1265
void setLowerRight(Point2D const &lr)
Definition diff2d.hxx:921
Rect2D operator*(double factor) const
Definition diff2d.hxx:1296
void setUpperLeft(Point2D const &ul)
Definition diff2d.hxx:913
Rect2D & operator*=(double factor)
Definition diff2d.hxx:1276
bool operator==(Rect2D const &r) const
equality check
Definition diff2d.hxx:1073
Rect2D & operator&=(Rect2D const &r)
Definition diff2d.hxx:1243
Rect2D operator&(Rect2D const &r) const
Definition diff2d.hxx:1306
Point2D const & lowerRight() const
Definition diff2d.hxx:905
bool intersects(Rect2D const &r) const
Definition diff2d.hxx:1127
void addSize(Size2D const &offset)
Definition diff2d.hxx:1043
Rect2D & operator|=(Point2D const &p)
Definition diff2d.hxx:1141
Rect2D(Point2D const &upperLeft, Point2D const &lowerRight)
Definition diff2d.hxx:872
bool contains(Point2D const &p) const
Definition diff2d.hxx:1102
void moveTo(Point2D const &newUpperLeft)
Definition diff2d.hxx:929
int left() const
Definition diff2d.hxx:960
bool operator!=(Rect2D const &r) const
inequality check
Definition diff2d.hxx:1079
Rect2D operator|(Point2D const &p) const
Definition diff2d.hxx:1167
bool isEmpty() const
Definition diff2d.hxx:1091
Rect2D & operator|=(Rect2D const &r)
Definition diff2d.hxx:1179
int height() const
Definition diff2d.hxx:999
Rect2D(int left, int top, int right, int bottom)
Definition diff2d.hxx:878
int width() const
Definition diff2d.hxx:991
void moveTo(int left, int top)
Definition diff2d.hxx:938
Rect2D operator&(Point2D const &p) const
Definition diff2d.hxx:1231
Rect2D operator*(int factor) const
Definition diff2d.hxx:1287
Size2D size() const
Definition diff2d.hxx:1017
Rect2D(Size2D const &size)
Definition diff2d.hxx:890
int area() const
Definition diff2d.hxx:1008
Two dimensional size object.
Definition diff2d.hxx:483
Size2D operator-() const
Definition diff2d.hxx:545
void setHeight(int h)
Definition diff2d.hxx:524
Size2D(Diff2D const &v)
Definition diff2d.hxx:497
Size2D & operator=(Diff2D const &v)
Definition diff2d.hxx:538
Size2D(int width, int height)
Definition diff2d.hxx:491
void setWidth(int w)
Definition diff2d.hxx:517
Size2D & operator-=(Diff2D const &offset)
Definition diff2d.hxx:559
Size2D & operator+=(Diff2D const &offset)
Definition diff2d.hxx:552
int height() const
Definition diff2d.hxx:510
int width() const
Definition diff2d.hxx:503
int area() const
Definition diff2d.hxx:531
Diff2D operator+(Diff2D const &a, Diff2D const &b)
Definition diff2d.hxx:725
Diff2D operator-(Diff2D const &a, Diff2D const &b)
Definition diff2d.hxx:697