workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / basegfx / range / b1drange.hxx
blob14d7f30251227f6c83e4f12a947dee99e4c6d3f8
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 #pragma once
22 #include <basegfx/range/basicrange.hxx>
25 namespace basegfx
28 /** A one-dimensional interval over doubles
30 This is a set of real numbers, bounded by a lower and an upper
31 value. All inbetween values are included in the set (see also
32 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
34 The set is closed, i.e. the upper and the lower bound are
35 included (if you're used to the notation - we're talking about
36 [a,b] here, compared to half-open [a,b) or open intervals
37 (a,b)).
39 That means, isInside(val) will return true also for values of
40 val=a or val=b.
42 class B1DRange
44 ::basegfx::BasicRange< double, DoubleTraits > maRange;
46 public:
47 B1DRange() {}
49 /// Create degenerate interval consisting of a single double number
50 explicit B1DRange(double fStartValue)
51 : maRange(fStartValue)
55 /// Create proper interval between the two given double values
56 B1DRange(double fStartValue1, double fStartValue2)
57 : maRange(fStartValue1)
59 expand(fStartValue2);
62 /** Check if the interval set is empty
64 @return false, if no value is in this set - having a
65 single value included will already return true.
67 bool isEmpty() const
69 return maRange.isEmpty();
72 bool operator==( const B1DRange& rRange ) const
74 return (maRange == rRange.maRange);
77 bool operator!=( const B1DRange& rRange ) const
79 return (maRange != rRange.maRange);
82 /// get lower bound of the set. returns arbitrary values for empty sets.
83 double getMinimum() const
85 return maRange.getMinimum();
88 /// get upper bound of the set. returns arbitrary values for empty sets.
89 double getMaximum() const
91 return maRange.getMaximum();
94 /// return difference between upper and lower value. returns 0 for empty sets.
95 double getRange() const
97 return maRange.getRange();
100 /// return middle of upper and lower value. returns 0 for empty sets.
101 double getCenter() const
103 return maRange.getCenter();
106 /// yields true if value is contained in set
107 bool isInside(double fValue) const
109 return maRange.isInside(fValue);
112 /// yields true if rRange at least partly inside set
113 bool overlaps(const B1DRange& rRange) const
115 return maRange.overlaps(rRange.maRange);
118 /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
119 bool overlapsMore(const B1DRange& rRange) const
121 return maRange.overlapsMore(rRange.maRange);
124 /// add fValue to the set, expanding as necessary
125 void expand(double fValue)
127 maRange.expand(fValue);
130 /// add rRange to the set, expanding as necessary
131 void expand(const B1DRange& rRange)
133 maRange.expand(rRange.maRange);
136 /// calc set intersection
137 void intersect(const B1DRange& rRange)
139 maRange.intersect(rRange.maRange);
142 /// clamp value on range
143 double clamp(double fValue) const
145 return maRange.clamp(fValue);
149 /** Write to char stream */
150 template<typename charT, typename traits>
151 inline std::basic_ostream<charT, traits>& operator<<(
152 std::basic_ostream<charT, traits>& stream, const B1DRange& range)
154 return stream << "[" << range.getMinimum() << ", " << range.getMaximum() << "]";
157 } // end of namespace basegfx
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */