Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / basegfx / range / b1drange.hxx
blobc1e35b13605ce663f667d4ea598bc77e2df6216e
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_B1DRANGE_HXX
21 #define INCLUDED_BASEGFX_RANGE_B1DRANGE_HXX
23 #include <basegfx/range/basicrange.hxx>
24 #include <basegfx/basegfxdllapi.h>
27 namespace basegfx
30 /** A one-dimensional interval over doubles
32 This is a set of real numbers, bounded by a lower and an upper
33 value. All inbetween values are included in the set (see also
34 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
36 The set is closed, i.e. the upper and the lower bound are
37 included (if you're used to the notation - we're talking about
38 [a,b] here, compared to half-open [a,b) or open intervals
39 (a,b)).
41 That means, isInside(val) will return true also for values of
42 val=a or val=b.
44 class B1DRange
46 ::basegfx::BasicRange< double, DoubleTraits > maRange;
48 public:
49 B1DRange() {}
51 /// Create degenerate interval consisting of a single double number
52 explicit B1DRange(double fStartValue)
53 : maRange(fStartValue)
57 /// Create proper interval between the two given double values
58 B1DRange(double fStartValue1, double fStartValue2)
59 : maRange(fStartValue1)
61 expand(fStartValue2);
64 /** Check if the interval set is empty
66 @return false, if no value is in this set - having a
67 single value included will already return true.
69 bool isEmpty() const
71 return maRange.isEmpty();
74 bool operator==( const B1DRange& rRange ) const
76 return (maRange == rRange.maRange);
79 bool operator!=( const B1DRange& rRange ) const
81 return (maRange != rRange.maRange);
84 /// get lower bound of the set. returns arbitrary values for empty sets.
85 double getMinimum() const
87 return maRange.getMinimum();
90 /// get upper bound of the set. returns arbitrary values for empty sets.
91 double getMaximum() const
93 return maRange.getMaximum();
96 /// return difference between upper and lower value. returns 0 for empty sets.
97 double getRange() const
99 return maRange.getRange();
102 /// return middle of upper and lower value. returns 0 for empty sets.
103 double getCenter() const
105 return maRange.getCenter();
108 /// yields true if value is contained in set
109 bool isInside(double fValue) const
111 return maRange.isInside(fValue);
114 /// yields true if rRange at least partly inside set
115 bool overlaps(const B1DRange& rRange) const
117 return maRange.overlaps(rRange.maRange);
120 /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
121 bool overlapsMore(const B1DRange& rRange) const
123 return maRange.overlapsMore(rRange.maRange);
126 /// add fValue to the set, expanding as necessary
127 void expand(double fValue)
129 maRange.expand(fValue);
132 /// add rRange to the set, expanding as necessary
133 void expand(const B1DRange& rRange)
135 maRange.expand(rRange.maRange);
138 /// calc set intersection
139 void intersect(const B1DRange& rRange)
141 maRange.intersect(rRange.maRange);
146 } // end of namespace basegfx
149 #endif // INCLUDED_BASEGFX_RANGE_B1DRANGE_HXX
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */