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_B1IRANGE_HXX
30 : : #define _BGFX_RANGE_B1IRANGE_HXX
31 : :
32 : : #include <basegfx/range/basicrange.hxx>
33 : : #include <basegfx/basegfxdllapi.h>
34 : :
35 : :
36 : : namespace basegfx
37 : : {
38 : : /** A one-dimensional interval over integers
39 : :
40 : : This is a set of real numbers, bounded by a lower and an upper
41 : : value. All inbetween values are included in the set (see also
42 : : http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
43 : :
44 : : Probably you rather want B1IBox for integers.
45 : :
46 : : The set is closed, i.e. the upper and the lower bound are
47 : : included (if you're used to the notation - we're talking about
48 : : [a,b] here, compared to half-open [a,b) or open intervals
49 : : (a,b)).
50 : :
51 : : That means, isInside(val) will return true also for values of
52 : : val=a or val=b.
53 : :
54 : : @see B1IBox
55 : : */
56 : : class B1IRange
57 : : {
58 : : ::basegfx::BasicRange< sal_Int32, Int32Traits > maRange;
59 : :
60 : : public:
61 : 5 : B1IRange() {}
62 : :
63 : : /// Create degenerate interval consisting of a single double number
64 : : explicit B1IRange(sal_Int32 nStartValue)
65 : : : maRange(nStartValue)
66 : : {
67 : : }
68 : :
69 : : /// Create proper interval between the two given values
70 : 20 : B1IRange(sal_Int32 nStartValue1, sal_Int32 nStartValue2)
71 : 20 : : maRange(nStartValue1)
72 : : {
73 : 20 : expand(nStartValue2);
74 : 20 : }
75 : :
76 : : /** Check if the interval set is empty
77 : :
78 : : @return false, if no value is in this set - having a
79 : : single value included will already return true.
80 : : */
81 : 20 : bool isEmpty() const
82 : : {
83 : 20 : return maRange.isEmpty();
84 : : }
85 : :
86 : : /// reset the object to empty state again, clearing all values
87 : : void reset()
88 : : {
89 : : maRange.reset();
90 : : }
91 : :
92 : : bool operator==( const B1IRange& rRange ) const
93 : : {
94 : : return (maRange == rRange.maRange);
95 : : }
96 : :
97 : : bool operator!=( const B1IRange& rRange ) const
98 : : {
99 : : return (maRange != rRange.maRange);
100 : : }
101 : :
102 : : /// get lower bound of the set. returns arbitrary values for empty sets.
103 : : sal_Int32 getMinimum() const
104 : : {
105 : : return maRange.getMinimum();
106 : : }
107 : :
108 : : /// get upper bound of the set. returns arbitrary values for empty sets.
109 : : sal_Int32 getMaximum() const
110 : : {
111 : : return maRange.getMaximum();
112 : : }
113 : :
114 : : /// return difference between upper and lower value. returns 0 for empty sets.
115 : 10 : Int32Traits::DifferenceType getRange() const
116 : : {
117 : 10 : return maRange.getRange();
118 : : }
119 : :
120 : : /// return middle of upper and lower value. returns 0 for empty sets.
121 : 15 : double getCenter() const
122 : : {
123 : 15 : return maRange.getCenter();
124 : : }
125 : :
126 : : /// yields true if value is contained in set
127 : 15 : bool isInside(sal_Int32 nValue) const
128 : : {
129 : 15 : return maRange.isInside(nValue);
130 : : }
131 : :
132 : : /// yields true if rRange is inside, or equal to set
133 : : bool isInside(const B1IRange& rRange) const
134 : : {
135 : : return maRange.isInside(rRange.maRange);
136 : : }
137 : :
138 : : /// yields true if rRange at least partly inside set
139 : 5 : bool overlaps(const B1IRange& rRange) const
140 : : {
141 : 5 : return maRange.overlaps(rRange.maRange);
142 : : }
143 : :
144 : : /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
145 : 10 : bool overlapsMore(const B1IRange& rRange) const
146 : : {
147 : 10 : return maRange.overlapsMore(rRange.maRange);
148 : : }
149 : :
150 : : /// add nValue to the set, expanding as necessary
151 : 35 : void expand(sal_Int32 nValue)
152 : : {
153 : 35 : maRange.expand(nValue);
154 : 35 : }
155 : :
156 : : /// add rRange to the set, expanding as necessary
157 : : void expand(const B1IRange& rRange)
158 : : {
159 : : maRange.expand(rRange.maRange);
160 : : }
161 : :
162 : : /// calc set intersection
163 : 10 : void intersect(const B1IRange& rRange)
164 : : {
165 : 10 : maRange.intersect(rRange.maRange);
166 : 10 : }
167 : :
168 : : /// grow set by nValue on both sides
169 : : void grow(sal_Int32 nValue)
170 : : {
171 : : maRange.grow(nValue);
172 : : }
173 : : };
174 : : } // end of namespace basegfx
175 : :
176 : : #endif /* _BGFX_RANGE_B1IRANGE_HXX */
177 : :
178 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|