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_B1IRANGE_HXX
21 #define _BGFX_RANGE_B1IRANGE_HXX
23 #include <basegfx/range/basicrange.hxx>
24 #include <basegfx/basegfxdllapi.h>
29 /** A one-dimensional interval over integers
31 This is a set of real numbers, bounded by a lower and an upper
32 value. All inbetween values are included in the set (see also
33 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
35 Probably you rather want B1IBox for integers.
37 The set is closed, i.e. the upper and the lower bound are
38 included (if you're used to the notation - we're talking about
39 [a,b] here, compared to half-open [a,b) or open intervals
42 That means, isInside(val) will return true also for values of
49 ::basegfx::BasicRange
< sal_Int32
, Int32Traits
> maRange
;
54 /// Create degenerate interval consisting of a single double number
55 explicit B1IRange(sal_Int32 nStartValue
)
56 : maRange(nStartValue
)
60 /// Create proper interval between the two given values
61 B1IRange(sal_Int32 nStartValue1
, sal_Int32 nStartValue2
)
62 : maRange(nStartValue1
)
67 /** Check if the interval set is empty
69 @return false, if no value is in this set - having a
70 single value included will already return true.
74 return maRange
.isEmpty();
77 /// reset the object to empty state again, clearing all values
83 bool operator==( const B1IRange
& rRange
) const
85 return (maRange
== rRange
.maRange
);
88 bool operator!=( const B1IRange
& rRange
) const
90 return (maRange
!= rRange
.maRange
);
93 /// get lower bound of the set. returns arbitrary values for empty sets.
94 sal_Int32
getMinimum() const
96 return maRange
.getMinimum();
99 /// get upper bound of the set. returns arbitrary values for empty sets.
100 sal_Int32
getMaximum() const
102 return maRange
.getMaximum();
105 /// return difference between upper and lower value. returns 0 for empty sets.
106 Int32Traits::DifferenceType
getRange() const
108 return maRange
.getRange();
111 /// return middle of upper and lower value. returns 0 for empty sets.
112 double getCenter() const
114 return maRange
.getCenter();
117 /// yields true if value is contained in set
118 bool isInside(sal_Int32 nValue
) const
120 return maRange
.isInside(nValue
);
123 /// yields true if rRange is inside, or equal to set
124 bool isInside(const B1IRange
& rRange
) const
126 return maRange
.isInside(rRange
.maRange
);
129 /// yields true if rRange at least partly inside set
130 bool overlaps(const B1IRange
& rRange
) const
132 return maRange
.overlaps(rRange
.maRange
);
135 /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
136 bool overlapsMore(const B1IRange
& rRange
) const
138 return maRange
.overlapsMore(rRange
.maRange
);
141 /// add nValue to the set, expanding as necessary
142 void expand(sal_Int32 nValue
)
144 maRange
.expand(nValue
);
147 /// add rRange to the set, expanding as necessary
148 void expand(const B1IRange
& rRange
)
150 maRange
.expand(rRange
.maRange
);
153 /// calc set intersection
154 void intersect(const B1IRange
& rRange
)
156 maRange
.intersect(rRange
.maRange
);
159 /// grow set by nValue on both sides
160 void grow(sal_Int32 nValue
)
162 maRange
.grow(nValue
);
165 } // end of namespace basegfx
167 #endif /* _BGFX_RANGE_B1IRANGE_HXX */
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */