update credits
[LibreOffice.git] / include / basegfx / range / b1drange.hxx
blobffe704a1b845e9dc38329217b5b84f92c4c98bd5
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 _BGFX_RANGE_B1DRANGE_HXX
21 #define _BGFX_RANGE_B1DRANGE_HXX
23 #include <basegfx/range/basicrange.hxx>
24 #include <basegfx/basegfxdllapi.h>
27 namespace basegfx
29 class B1IRange;
31 /** A one-dimensional interval over doubles
33 This is a set of real numbers, bounded by a lower and an 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 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
40 (a,b)).
42 That means, isInside(val) will return true also for values of
43 val=a or val=b.
45 class B1DRange
47 ::basegfx::BasicRange< double, DoubleTraits > maRange;
49 public:
50 B1DRange() {}
52 /// Create degenerate interval consisting of a single double number
53 explicit B1DRange(double fStartValue)
54 : maRange(fStartValue)
58 /// Create proper interval between the two given double values
59 B1DRange(double fStartValue1, double fStartValue2)
60 : maRange(fStartValue1)
62 expand(fStartValue2);
65 /** Check if the interval set is empty
67 @return false, if no value is in this set - having a
68 single value included will already return true.
70 bool isEmpty() const
72 return maRange.isEmpty();
75 /// reset the object to empty state again, clearing all values
76 void reset()
78 maRange.reset();
81 bool operator==( const B1DRange& rRange ) const
83 return (maRange == rRange.maRange);
86 bool operator!=( const B1DRange& rRange ) const
88 return (maRange != rRange.maRange);
91 bool equal(const B1DRange& rRange) const
93 return (maRange.equal(rRange.maRange));
96 /// get lower bound of the set. returns arbitrary values for empty sets.
97 double getMinimum() const
99 return maRange.getMinimum();
102 /// get upper bound of the set. returns arbitrary values for empty sets.
103 double getMaximum() const
105 return maRange.getMaximum();
108 /// return difference between upper and lower value. returns 0 for empty sets.
109 double getRange() const
111 return maRange.getRange();
114 /// return middle of upper and lower value. returns 0 for empty sets.
115 double getCenter() const
117 return maRange.getCenter();
120 /// yields true if value is contained in set
121 bool isInside(double fValue) const
123 return maRange.isInside(fValue);
126 /// yields true if rRange is inside, or equal to set
127 bool isInside(const B1DRange& rRange) const
129 return maRange.isInside(rRange.maRange);
132 /// yields true if rRange at least partly inside set
133 bool overlaps(const B1DRange& rRange) const
135 return maRange.overlaps(rRange.maRange);
138 /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
139 bool overlapsMore(const B1DRange& rRange) const
141 return maRange.overlapsMore(rRange.maRange);
144 /// add fValue to the set, expanding as necessary
145 void expand(double fValue)
147 maRange.expand(fValue);
150 /// add rRange to the set, expanding as necessary
151 void expand(const B1DRange& rRange)
153 maRange.expand(rRange.maRange);
156 /// calc set intersection
157 void intersect(const B1DRange& rRange)
159 maRange.intersect(rRange.maRange);
162 /// grow set by fValue on both sides
163 void grow(double fValue)
165 maRange.grow(fValue);
169 } // end of namespace basegfx
172 #endif /* _BGFX_RANGE_B1DRANGE_HXX */
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */