1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _BGFX_RANGE_B2IBOX_HXX
21 #define _BGFX_RANGE_B2IBOX_HXX
23 #include <basegfx/point/b2ipoint.hxx>
24 #include <basegfx/point/b2dpoint.hxx>
25 #include <basegfx/tuple/b2ituple.hxx>
26 #include <basegfx/tuple/b2i64tuple.hxx>
27 #include <basegfx/range/basicbox.hxx>
29 #include <basegfx/basegfxdllapi.h>
34 /** A two-dimensional interval over integers
36 This is most easily depicted as a set of integers, bounded by
37 a lower and an upper value - but excluding the upper
38 value. All inbetween values are included in the set (see also
39 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
41 The set is half-open, i.e. the lower bound is included, the
42 upper bound not (if you're used to the notation - we're
43 talking about [a,b) here, compared to closed [a,b] or fully
44 open intervals (a,b)).
46 If you don't need a half-open interval, check B2IRange.
48 That means, isInside(val) will return true also for values of
49 val=a, but not for val=b.
51 Alternatively, consider this a rectangle, where the rightmost
52 pixel column and the bottommost pixel row are excluded - this
53 is much like polygon filling. As a result, filling a given
54 rectangle with basebmp::BitmapDevice::fillPolyPolygon(), will
55 affect exactly the same set of pixel as isInside() would
63 typedef sal_Int32 ValueType
;
64 typedef Int32Traits TraitsType
;
68 /// Create degenerate interval that's still empty
69 explicit B2IBox(const B2ITuple
& rTuple
)
70 : maRangeX(rTuple
.getX()),
71 maRangeY(rTuple
.getY())
75 /// Create proper interval between the two given points
87 /// Create proper interval between the two given points
88 B2IBox(const B2ITuple
& rTuple1
,
89 const B2ITuple
& rTuple2
) :
90 maRangeX(rTuple1
.getX()),
91 maRangeY(rTuple1
.getY())
96 /** Check if the interval set is empty
98 @return false, if no value is in this set - having a
99 single value included will still return false.
103 return maRangeX
.isEmpty() || maRangeY
.isEmpty();
106 /// reset the object to empty state again, clearing all values
113 bool operator==( const B2IBox
& rBox
) const
115 return (maRangeX
== rBox
.maRangeX
116 && maRangeY
== rBox
.maRangeY
);
119 bool operator!=( const B2IBox
& rBox
) const
121 return (maRangeX
!= rBox
.maRangeX
122 || maRangeY
!= rBox
.maRangeY
);
125 /// get lower bound of the set. returns arbitrary values for empty sets.
126 sal_Int32
getMinX() const
128 return maRangeX
.getMinimum();
131 /// get lower bound of the set. returns arbitrary values for empty sets.
132 sal_Int32
getMinY() const
134 return maRangeY
.getMinimum();
137 /// get upper bound of the set. returns arbitrary values for empty sets.
138 sal_Int32
getMaxX() const
140 return maRangeX
.getMaximum();
143 /// get upper bound of the set. returns arbitrary values for empty sets.
144 sal_Int32
getMaxY() const
146 return maRangeY
.getMaximum();
149 /// return difference between upper and lower X value. returns 0 for empty sets.
150 sal_Int64
getWidth() const
152 return maRangeX
.getRange();
155 /// return difference between upper and lower Y value. returns 0 for empty sets.
156 sal_Int64
getHeight() const
158 return maRangeY
.getRange();
161 /// get lower bound of the set. returns arbitrary values for empty sets.
162 B2IPoint
getMinimum() const
165 maRangeX
.getMinimum(),
166 maRangeY
.getMinimum()
170 /// get upper bound of the set. returns arbitrary values for empty sets.
171 B2IPoint
getMaximum() const
174 maRangeX
.getMaximum(),
175 maRangeY
.getMaximum()
179 /// return difference between upper and lower value. returns (0,0) for empty sets.
180 B2I64Tuple
getRange() const
188 /// return center point of set. returns (0,0) for empty sets.
189 B2DPoint
getCenter() const
192 maRangeX
.getCenter(),
197 /// yields true if point is contained in set
198 bool isInside(const B2ITuple
& rTuple
) const
201 maRangeX
.isInside(rTuple
.getX())
202 && maRangeY
.isInside(rTuple
.getY())
206 /// yields true if rBox is inside, or equal to set
207 bool isInside(const B2IBox
& rBox
) const
210 maRangeX
.isInside(rBox
.maRangeX
)
211 && maRangeY
.isInside(rBox
.maRangeY
)
215 /// yields true if rBox at least partly inside set
216 bool overlaps(const B2IBox
& rBox
) const
219 maRangeX
.overlaps(rBox
.maRangeX
)
220 && maRangeY
.overlaps(rBox
.maRangeY
)
224 /// add point to the set, expanding as necessary
225 void expand(const B2ITuple
& rTuple
)
227 maRangeX
.expand(rTuple
.getX());
228 maRangeY
.expand(rTuple
.getY());
231 /// add rBox to the set, expanding as necessary
232 void expand(const B2IBox
& rBox
)
234 maRangeX
.expand(rBox
.maRangeX
);
235 maRangeY
.expand(rBox
.maRangeY
);
238 /// calc set intersection
239 void intersect(const B2IBox
& rBox
)
241 maRangeX
.intersect(rBox
.maRangeX
);
242 maRangeY
.intersect(rBox
.maRangeY
);
245 /// grow set by nValue on all sides
246 void grow(sal_Int32 nValue
)
248 maRangeX
.grow(nValue
);
249 maRangeY
.grow(nValue
);
257 } // end of namespace basegfx
259 #endif /* _BGFX_RANGE_B2IBOX_HXX */
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */