Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _BGFX_RANGE_B1IBOX_HXX
30 : : #define _BGFX_RANGE_B1IBOX_HXX
31 : :
32 : : #include <basegfx/range/basicbox.hxx>
33 : : #include <basegfx/basegfxdllapi.h>
34 : :
35 : :
36 : : namespace basegfx
37 : : {
38 : : /** A one-dimensional interval over integers
39 : :
40 : : This is most easily depicted as a set of integers, bounded by
41 : : a lower and an upper value - but excluding the upper
42 : : value. All inbetween values are included in the set (see also
43 : : http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
44 : :
45 : : The set is half-open, i.e. the lower bound is included, the
46 : : upper bound not (if you're used to the notation - we're
47 : : talking about [a,b) here, compared to closed [a,b] or fully
48 : : open intervals (a,b)).
49 : :
50 : : If you don't need a half-open interval, check B1IRange.
51 : :
52 : : That means, isInside(val) will return true also for values of
53 : : val=a, but not for val=b.
54 : :
55 : : @see B1IRange
56 : : */
57 : : class B1IBox
58 : : {
59 : : ::basegfx::BasicBox maRange;
60 : :
61 : : public:
62 : 5 : B1IBox() {}
63 : :
64 : : /// Create degenerate interval that's still empty
65 : : explicit B1IBox(sal_Int32 nStartValue)
66 : : : maRange(nStartValue)
67 : : {
68 : : }
69 : :
70 : : /// Create proper interval between the two given values
71 : 20 : B1IBox(sal_Int32 nStartValue1, sal_Int32 nStartValue2)
72 : 20 : : maRange(nStartValue1)
73 : : {
74 : 20 : expand(nStartValue2);
75 : 20 : }
76 : :
77 : : /** Check if the interval set is empty
78 : :
79 : : @return false, if no value is in this set - having a
80 : : single value included will still return false.
81 : : */
82 : 20 : bool isEmpty() const
83 : : {
84 : 20 : return maRange.isEmpty();
85 : : }
86 : :
87 : : /// reset the object to empty state again, clearing all values
88 : : void reset()
89 : : {
90 : : maRange.reset();
91 : : }
92 : :
93 : : bool operator==( const B1IBox& rBox ) const
94 : : {
95 : : return (maRange == rBox.maRange);
96 : : }
97 : :
98 : : bool operator!=( const B1IBox& rBox ) const
99 : : {
100 : : return (maRange != rBox.maRange);
101 : : }
102 : :
103 : : /// get lower bound of the set. returns arbitrary values for empty sets.
104 : : sal_Int32 getMinimum() const
105 : : {
106 : : return maRange.getMinimum();
107 : : }
108 : :
109 : : /// get upper bound of the set. returns arbitrary values for empty sets.
110 : : sal_Int32 getMaximum() const
111 : : {
112 : : return maRange.getMaximum();
113 : : }
114 : :
115 : : /// return difference between upper and lower value. returns 0 for empty sets.
116 : 10 : Int32Traits::DifferenceType getRange() const
117 : : {
118 : 10 : return maRange.getRange();
119 : : }
120 : :
121 : : /// return middle of upper and lower value. returns 0 for empty sets.
122 : 10 : double getCenter() const
123 : : {
124 : 10 : return maRange.getCenter();
125 : : }
126 : :
127 : : /// yields true if value is contained in set
128 : 15 : bool isInside(sal_Int32 nValue) const
129 : : {
130 : 15 : return maRange.isInside(nValue);
131 : : }
132 : :
133 : : /// yields true if rRange is inside, or equal to set
134 : : bool isInside(const B1IBox& rBox) const
135 : : {
136 : : return maRange.isInside(rBox.maRange);
137 : : }
138 : :
139 : : /// yields true if rRange at least partly inside set
140 : 10 : bool overlaps(const B1IBox& rBox) const
141 : : {
142 : 10 : return maRange.overlaps(rBox.maRange);
143 : : }
144 : :
145 : : /// add nValue to the set, expanding as necessary
146 : 35 : void expand(sal_Int32 nValue)
147 : : {
148 : 35 : maRange.expand(nValue);
149 : 35 : }
150 : :
151 : : /// add rBox to the set, expanding as necessary
152 : : void expand(const B1IBox& rBox)
153 : : {
154 : : maRange.expand(rBox.maRange);
155 : : }
156 : :
157 : : /// calc set intersection
158 : 10 : void intersect(const B1IBox& rBox)
159 : : {
160 : 10 : maRange.intersect(rBox.maRange);
161 : 10 : }
162 : :
163 : : /// grow set by nValue on both sides
164 : : void grow(sal_Int32 nValue)
165 : : {
166 : : maRange.grow(nValue);
167 : : }
168 : : };
169 : : } // end of namespace basegfx
170 : :
171 : : #endif /* _BGFX_RANGE_B1IBOX_HXX */
172 : :
173 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|