cid#1607257 Overflowed constant
[LibreOffice.git] / include / basegfx / range / b3drange.hxx
blob338c4f54a029e2c5d8c3d43d53974eebf79b7b27
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/vector/b3dvector.hxx>
23 #include <basegfx/point/b3dpoint.hxx>
24 #include <basegfx/tuple/b3dtuple.hxx>
25 #include <basegfx/range/basicrange.hxx>
26 #include <basegfx/basegfxdllapi.h>
28 namespace basegfx
30 class B3DHomMatrix;
32 class SAL_WARN_UNUSED B3DRange
34 typedef ::basegfx::BasicRange< double, DoubleTraits > MyBasicRange;
36 MyBasicRange maRangeX;
37 MyBasicRange maRangeY;
38 MyBasicRange maRangeZ;
40 public:
41 B3DRange() {}
43 explicit B3DRange(const B3DTuple& rTuple)
44 : maRangeX(rTuple.getX()),
45 maRangeY(rTuple.getY()),
46 maRangeZ(rTuple.getZ())
50 B3DRange(double x1,
51 double y1,
52 double z1,
53 double x2,
54 double y2,
55 double z2)
56 : maRangeX(x1),
57 maRangeY(y1),
58 maRangeZ(z1)
60 maRangeX.expand(x2);
61 maRangeY.expand(y2);
62 maRangeZ.expand(z2);
65 B3DRange(const B3DTuple& rTuple1,
66 const B3DTuple& rTuple2)
67 : maRangeX(rTuple1.getX()),
68 maRangeY(rTuple1.getY()),
69 maRangeZ(rTuple1.getZ())
71 expand(rTuple2);
74 bool isEmpty() const
76 return (
77 maRangeX.isEmpty()
78 || maRangeY.isEmpty()
79 || maRangeZ.isEmpty()
83 void reset()
85 maRangeX.reset();
86 maRangeY.reset();
87 maRangeZ.reset();
90 bool operator==( const B3DRange& rRange ) const
92 return (maRangeX == rRange.maRangeX
93 && maRangeY == rRange.maRangeY
94 && maRangeZ == rRange.maRangeZ);
97 bool operator!=( const B3DRange& rRange ) const
99 return (maRangeX != rRange.maRangeX
100 || maRangeY != rRange.maRangeY
101 || maRangeZ != rRange.maRangeZ);
104 double getMinX() const
106 return maRangeX.getMinimum();
109 double getMinY() const
111 return maRangeY.getMinimum();
114 double getMinZ() const
116 return maRangeZ.getMinimum();
119 double getMaxX() const
121 return maRangeX.getMaximum();
124 double getMaxY() const
126 return maRangeY.getMaximum();
129 double getMaxZ() const
131 return maRangeZ.getMaximum();
134 double getWidth() const
136 return maRangeX.getRange();
139 double getHeight() const
141 return maRangeY.getRange();
144 double getDepth() const
146 return maRangeZ.getRange();
149 B3DVector getRange() const
151 return B3DVector(
152 maRangeX.getRange(),
153 maRangeY.getRange(),
154 maRangeZ.getRange()
158 B3DPoint getCenter() const
160 return B3DPoint(
161 maRangeX.getCenter(),
162 maRangeY.getCenter(),
163 maRangeZ.getCenter()
167 bool overlaps(const B3DRange& rRange) const
169 return (
170 maRangeX.overlaps(rRange.maRangeX)
171 && maRangeY.overlaps(rRange.maRangeY)
172 && maRangeZ.overlaps(rRange.maRangeZ)
176 void expand(const B3DTuple& rTuple)
178 maRangeX.expand(rTuple.getX());
179 maRangeY.expand(rTuple.getY());
180 maRangeZ.expand(rTuple.getZ());
183 void expand(const B3DRange& rRange)
185 maRangeX.expand(rRange.maRangeX);
186 maRangeY.expand(rRange.maRangeY);
187 maRangeZ.expand(rRange.maRangeZ);
190 void grow(double fValue)
192 maRangeX.grow(fValue);
193 maRangeY.grow(fValue);
194 maRangeZ.grow(fValue);
197 /// clamp value on range
198 B3DTuple clamp(const B3DTuple& rTuple) const
200 return B3DTuple(
201 maRangeX.clamp(rTuple.getX()),
202 maRangeY.clamp(rTuple.getY()),
203 maRangeZ.clamp(rTuple.getZ()));
206 BASEGFX_DLLPUBLIC void transform(const B3DHomMatrix& rMatrix);
208 /** Transform Range by given transformation matrix.
210 This operation transforms the Range by transforming all eight possible
211 extrema points (corners) of the given range and building a new one.
212 This means that the range will grow evtl. when a shear and/or rotation
213 is part of the transformation.
215 B3DRange& operator*=( const ::basegfx::B3DHomMatrix& rMat );
217 /** Get a range filled with (0.0, 0.0, 0.0, 1.0, 1.0, 1.0) */
218 static const B3DRange& getUnitB3DRange();
221 /** Transform B3DRange by given transformation matrix (see operator*=())
223 B3DRange operator*( const B3DHomMatrix& rMat, const B3DRange& rB2DRange );
225 } // end of namespace basegfx
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */