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