LibreOffice Module basegfx (master) 1
Range2D.hxx
Go to the documentation of this file.
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#pragma once
21
25
26namespace basegfx
27{
28template <typename TYPE, typename TRAITS> class Range2D
29{
30protected:
33
34public:
35 typedef TYPE ValueType;
36 typedef TRAITS TraitsType;
37
38 Range2D() = default;
39
41 explicit Range2D(const Tuple2D<TYPE>& rTuple)
42 : maRangeX(rTuple.getX())
43 , maRangeY(rTuple.getY())
44 {
45 }
46
48 Range2D(const Tuple2D<TYPE>& rTuple1, const Tuple2D<TYPE>& rTuple2)
49 : maRangeX(rTuple1.getX())
50 , maRangeY(rTuple1.getY())
51 {
52 expand(rTuple2);
53 }
54
56 Range2D(TYPE x1, TYPE y1, TYPE x2, TYPE y2)
57 : maRangeX(x1)
58 , maRangeY(y1)
59 {
60 maRangeX.expand(x2);
61 maRangeY.expand(y2);
62 }
63
69 bool isEmpty() const { return maRangeX.isEmpty() || maRangeY.isEmpty(); }
70
72 void reset()
73 {
76 }
77
78 bool operator==(const Range2D& rRange) const
79 {
80 return maRangeX == rRange.maRangeX && maRangeY == rRange.maRangeY;
81 }
82
83 bool operator!=(const Range2D& rRange) const
84 {
85 return maRangeX != rRange.maRangeX || maRangeY != rRange.maRangeY;
86 }
87
88 bool equal(const Range2D& rRange) const
89 {
90 return maRangeX.equal(rRange.maRangeX) && maRangeY.equal(rRange.maRangeY);
91 }
92
94 TYPE getMinX() const { return maRangeX.getMinimum(); }
95
97 TYPE getMinY() const { return maRangeY.getMinimum(); }
98
100 TYPE getMaxX() const { return maRangeX.getMaximum(); }
101
103 TYPE getMaxY() const { return maRangeY.getMaximum(); }
104
106 TYPE getWidth() const { return maRangeX.getRange(); }
107
109 TYPE getHeight() const { return maRangeY.getRange(); }
110
112 double getCenterX() const { return maRangeX.getCenter(); }
113
115 double getCenterY() const { return maRangeY.getCenter(); }
116
118 bool isInside(const Tuple2D<TYPE>& rTuple) const
119 {
120 return maRangeX.isInside(rTuple.getX()) && maRangeY.isInside(rTuple.getY());
121 }
122
124 bool isInside(const Range2D& rRange) const
125 {
126 return maRangeX.isInside(rRange.maRangeX) && maRangeY.isInside(rRange.maRangeY);
127 }
128
130 bool overlaps(const Range2D& rRange) const
131 {
132 return maRangeX.overlaps(rRange.maRangeX) && maRangeY.overlaps(rRange.maRangeY);
133 }
134
136 bool overlapsMore(const Range2D& rRange) const
137 {
139 }
140
142 void expand(const Tuple2D<TYPE>& rTuple)
143 {
144 maRangeX.expand(rTuple.getX());
145 maRangeY.expand(rTuple.getY());
146 }
147
149 void expand(const Range2D& rRange)
150 {
151 maRangeX.expand(rRange.maRangeX);
152 maRangeY.expand(rRange.maRangeY);
153 }
154
156 void intersect(const Range2D& rRange)
157 {
160 }
161
163 void grow(TYPE fValue)
164 {
165 maRangeX.grow(fValue);
166 maRangeY.grow(fValue);
167 }
168
170 void grow(const Tuple2D<TYPE>& rTuple)
171 {
172 maRangeX.grow(rTuple.getX());
173 maRangeY.grow(rTuple.getY());
174 }
175
177 Tuple2D<TYPE> clamp(const Tuple2D<TYPE>& rTuple) const
178 {
179 return Tuple2D<TYPE>(maRangeX.clamp(rTuple.getX()), maRangeY.clamp(rTuple.getY()));
180 }
181};
182
183} // end of namespace basegfx
184
185/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool overlaps(const BasicRange &rRange) const
Definition: basicrange.hxx:108
T clamp(T nValue) const
Definition: basicrange.hxx:250
bool isEmpty() const
Definition: basicrange.hxx:57
bool overlapsMore(const BasicRange &rRange) const
Definition: basicrange.hxx:127
bool isInside(T nValue) const
Definition: basicrange.hxx:77
double getCenter() const
Definition: basicrange.hxx:65
void intersect(const BasicRange &rRange)
Definition: basicrange.hxx:205
bool equal(const BasicRange &rRange) const
Definition: basicrange.hxx:145
T getMaximum() const
Definition: basicrange.hxx:63
T getMinimum() const
Definition: basicrange.hxx:62
void grow(T nValue)
Definition: basicrange.hxx:226
void expand(T nValue)
Definition: basicrange.hxx:152
Traits::DifferenceType getRange() const
Definition: basicrange.hxx:276
TYPE getMaxX() const
get upper bound of the set. returns arbitrary values for empty sets.
Definition: Range2D.hxx:100
void grow(TYPE fValue)
grow set by fValue on all sides
Definition: Range2D.hxx:163
bool overlapsMore(const Range2D &rRange) const
yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
Definition: Range2D.hxx:136
TYPE getWidth() const
return difference between upper and lower X value. returns 0 for empty sets.
Definition: Range2D.hxx:106
bool operator==(const Range2D &rRange) const
Definition: Range2D.hxx:78
TYPE getMinX() const
get lower bound of the set. returns arbitrary values for empty sets.
Definition: Range2D.hxx:94
void expand(const Range2D &rRange)
add rRange to the set, expanding as necessary
Definition: Range2D.hxx:149
bool isInside(const Range2D &rRange) const
yields true if rRange is inside, or equal to set
Definition: Range2D.hxx:124
basegfx::BasicRange< TYPE, TRAITS > maRangeX
Definition: Range2D.hxx:31
TYPE getMinY() const
get lower bound of the set. returns arbitrary values for empty sets.
Definition: Range2D.hxx:97
double getCenterX() const
return center X value of set. returns 0 for empty sets.
Definition: Range2D.hxx:112
void expand(const Tuple2D< TYPE > &rTuple)
add point to the set, expanding as necessary
Definition: Range2D.hxx:142
Range2D(const Tuple2D< TYPE > &rTuple)
Create degenerate interval consisting of a single point.
Definition: Range2D.hxx:41
double getCenterY() const
return center Y value of set. returns 0 for empty sets.
Definition: Range2D.hxx:115
void grow(const Tuple2D< TYPE > &rTuple)
grow set by axis aware values from rTuple
Definition: Range2D.hxx:170
void reset()
reset the object to empty state again, clearing all values
Definition: Range2D.hxx:72
TRAITS TraitsType
Definition: Range2D.hxx:36
Range2D(const Tuple2D< TYPE > &rTuple1, const Tuple2D< TYPE > &rTuple2)
Create proper interval between the two given points.
Definition: Range2D.hxx:48
TYPE getMaxY() const
get upper bound of the set. returns arbitrary values for empty sets.
Definition: Range2D.hxx:103
void intersect(const Range2D &rRange)
calc set intersection
Definition: Range2D.hxx:156
basegfx::BasicRange< TYPE, TRAITS > maRangeY
Definition: Range2D.hxx:32
bool isInside(const Tuple2D< TYPE > &rTuple) const
yields true if given point is contained in set
Definition: Range2D.hxx:118
Range2D(TYPE x1, TYPE y1, TYPE x2, TYPE y2)
Create proper interval between the two given pairs.
Definition: Range2D.hxx:56
bool isEmpty() const
Check if the interval set is empty.
Definition: Range2D.hxx:69
Tuple2D< TYPE > clamp(const Tuple2D< TYPE > &rTuple) const
clamp value on range
Definition: Range2D.hxx:177
bool equal(const Range2D &rRange) const
Definition: Range2D.hxx:88
Range2D()=default
TYPE getHeight() const
return difference between upper and lower Y value. returns 0 for empty sets.
Definition: Range2D.hxx:109
bool overlaps(const Range2D &rRange) const
yields true if rRange at least partly inside set
Definition: Range2D.hxx:130
bool operator!=(const Range2D &rRange) const
Definition: Range2D.hxx:83
TYPE getX() const
Get X-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:63
TYPE getY() const
Get Y-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:66
TYPE