bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / basegfx / range / b2ibox.hxx
blob6fb26abc7d04c67e69c839f05bcdef8c51ba6381
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 INCLUDED_BASEGFX_RANGE_B2IBOX_HXX
21 #define INCLUDED_BASEGFX_RANGE_B2IBOX_HXX
23 #include <ostream>
25 #include <basegfx/tuple/b2ituple.hxx>
26 #include <basegfx/range/basicbox.hxx>
28 namespace basegfx
30 /** A two-dimensional interval over integers
32 This is most easily depicted as a set of integers, bounded by
33 a lower and an upper value - but excluding the upper
34 value. All inbetween values are included in the set (see also
35 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
37 The set is half-open, i.e. the lower bound is included, the
38 upper bound not (if you're used to the notation - we're
39 talking about [a,b) here, compared to closed [a,b] or fully
40 open intervals (a,b)).
42 If you don't need a half-open interval, check B2IRange.
44 That means, isInside(val) will return true also for values of
45 val=a, but not for val=b.
47 Alternatively, consider this a rectangle, where the rightmost
48 pixel column and the bottommost pixel row are excluded - this
49 is much like polygon filling. As a result, filling a given
50 rectangle with basebmp::BitmapDevice::fillPolyPolygon(), will
51 affect exactly the same set of pixel as isInside() would
52 return true for.
54 @see B2IRange
56 class B2IBox
58 public:
59 typedef sal_Int32 ValueType;
60 typedef Int32Traits TraitsType;
62 B2IBox() {}
64 /// Create degenerate interval that's still empty
65 explicit B2IBox(const B2ITuple& rTuple)
66 : maRangeX(rTuple.getX()),
67 maRangeY(rTuple.getY())
71 /// Create proper interval between the two given points
72 B2IBox(sal_Int32 x1,
73 sal_Int32 y1,
74 sal_Int32 x2,
75 sal_Int32 y2) :
76 maRangeX(x1),
77 maRangeY(y1)
79 maRangeX.expand(x2);
80 maRangeY.expand(y2);
83 /// Create proper interval between the two given points
84 B2IBox(const B2ITuple& rTuple1,
85 const B2ITuple& rTuple2) :
86 maRangeX(rTuple1.getX()),
87 maRangeY(rTuple1.getY())
89 expand( rTuple2 );
92 /** Check if the interval set is empty
94 @return false, if no value is in this set - having a
95 single value included will still return false.
97 bool isEmpty() const
99 return maRangeX.isEmpty() || maRangeY.isEmpty();
102 bool operator==( const B2IBox& rBox ) const
104 return (maRangeX == rBox.maRangeX
105 && maRangeY == rBox.maRangeY);
108 bool operator!=( const B2IBox& rBox ) const
110 return (maRangeX != rBox.maRangeX
111 || maRangeY != rBox.maRangeY);
114 /// get lower bound of the set. returns arbitrary values for empty sets.
115 sal_Int32 getMinX() const
117 return maRangeX.getMinimum();
120 /// get lower bound of the set. returns arbitrary values for empty sets.
121 sal_Int32 getMinY() const
123 return maRangeY.getMinimum();
126 /// get upper bound of the set. returns arbitrary values for empty sets.
127 sal_Int32 getMaxX() const
129 return maRangeX.getMaximum();
132 /// get upper bound of the set. returns arbitrary values for empty sets.
133 sal_Int32 getMaxY() const
135 return maRangeY.getMaximum();
138 /// return difference between upper and lower X value. returns 0 for empty sets.
139 sal_Int64 getWidth() const
141 return maRangeX.getRange();
144 /// return difference between upper and lower Y value. returns 0 for empty sets.
145 sal_Int64 getHeight() const
147 return maRangeY.getRange();
150 /// yields true if point is contained in set
151 bool isInside(const B2ITuple& rTuple) const
153 return (
154 maRangeX.isInside(rTuple.getX())
155 && maRangeY.isInside(rTuple.getY())
159 /// add point to the set, expanding as necessary
160 void expand(const B2ITuple& rTuple)
162 maRangeX.expand(rTuple.getX());
163 maRangeY.expand(rTuple.getY());
166 /// calc set intersection
167 void intersect(const B2IBox& rBox)
169 maRangeX.intersect(rBox.maRangeX);
170 maRangeY.intersect(rBox.maRangeY);
173 private:
174 BasicBox maRangeX;
175 BasicBox maRangeY;
178 } // end of namespace basegfx
180 template< typename charT, typename traits >
181 inline std::basic_ostream<charT, traits> & operator <<(
182 std::basic_ostream<charT, traits> & stream, const basegfx::B2IBox& box )
184 if (box.isEmpty())
185 return stream << "EMPTY";
186 else
187 return stream << box.getWidth() << 'x' << box.getHeight()
188 << "@(" << box.getMinX() << "," << box.getMinY() << ")";
191 #endif // INCLUDED_BASEGFX_RANGE_B2IBOX_HXX
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */