Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_BASEGFX_RANGE_B1DRANGE_HXX
21 : #define INCLUDED_BASEGFX_RANGE_B1DRANGE_HXX
22 :
23 : #include <basegfx/range/basicrange.hxx>
24 : #include <basegfx/basegfxdllapi.h>
25 :
26 :
27 : namespace basegfx
28 : {
29 : class B1IRange;
30 :
31 : /** A one-dimensional interval over doubles
32 :
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).
36 :
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)).
41 :
42 : That means, isInside(val) will return true also for values of
43 : val=a or val=b.
44 : */
45 : class B1DRange
46 : {
47 : ::basegfx::BasicRange< double, DoubleTraits > maRange;
48 :
49 : public:
50 0 : B1DRange() {}
51 :
52 : /// Create degenerate interval consisting of a single double number
53 : explicit B1DRange(double fStartValue)
54 : : maRange(fStartValue)
55 : {
56 : }
57 :
58 : /// Create proper interval between the two given double values
59 0 : B1DRange(double fStartValue1, double fStartValue2)
60 0 : : maRange(fStartValue1)
61 : {
62 0 : expand(fStartValue2);
63 0 : }
64 :
65 : /** Check if the interval set is empty
66 :
67 : @return false, if no value is in this set - having a
68 : single value included will already return true.
69 : */
70 : bool isEmpty() const
71 : {
72 : return maRange.isEmpty();
73 : }
74 :
75 : /// reset the object to empty state again, clearing all values
76 : void reset()
77 : {
78 : maRange.reset();
79 : }
80 :
81 : bool operator==( const B1DRange& rRange ) const
82 : {
83 : return (maRange == rRange.maRange);
84 : }
85 :
86 0 : bool operator!=( const B1DRange& rRange ) const
87 : {
88 0 : return (maRange != rRange.maRange);
89 : }
90 :
91 : bool equal(const B1DRange& rRange) const
92 : {
93 : return (maRange.equal(rRange.maRange));
94 : }
95 :
96 : /// get lower bound of the set. returns arbitrary values for empty sets.
97 0 : double getMinimum() const
98 : {
99 0 : return maRange.getMinimum();
100 : }
101 :
102 : /// get upper bound of the set. returns arbitrary values for empty sets.
103 0 : double getMaximum() const
104 : {
105 0 : return maRange.getMaximum();
106 : }
107 :
108 : /// return difference between upper and lower value. returns 0 for empty sets.
109 0 : double getRange() const
110 : {
111 0 : return maRange.getRange();
112 : }
113 :
114 : /// return middle of upper and lower value. returns 0 for empty sets.
115 : double getCenter() const
116 : {
117 : return maRange.getCenter();
118 : }
119 :
120 : /// yields true if value is contained in set
121 : bool isInside(double fValue) const
122 : {
123 : return maRange.isInside(fValue);
124 : }
125 :
126 : /// yields true if rRange is inside, or equal to set
127 : bool isInside(const B1DRange& rRange) const
128 : {
129 : return maRange.isInside(rRange.maRange);
130 : }
131 :
132 : /// yields true if rRange at least partly inside set
133 0 : bool overlaps(const B1DRange& rRange) const
134 : {
135 0 : return maRange.overlaps(rRange.maRange);
136 : }
137 :
138 : /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
139 : bool overlapsMore(const B1DRange& rRange) const
140 : {
141 : return maRange.overlapsMore(rRange.maRange);
142 : }
143 :
144 : /// add fValue to the set, expanding as necessary
145 0 : void expand(double fValue)
146 : {
147 0 : maRange.expand(fValue);
148 0 : }
149 :
150 : /// add rRange to the set, expanding as necessary
151 0 : void expand(const B1DRange& rRange)
152 : {
153 0 : maRange.expand(rRange.maRange);
154 0 : }
155 :
156 : /// calc set intersection
157 : void intersect(const B1DRange& rRange)
158 : {
159 : maRange.intersect(rRange.maRange);
160 : }
161 :
162 : /// grow set by fValue on both sides
163 : void grow(double fValue)
164 : {
165 : maRange.grow(fValue);
166 : }
167 : };
168 :
169 : } // end of namespace basegfx
170 :
171 :
172 : #endif // INCLUDED_BASEGFX_RANGE_B1DRANGE_HXX
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|