LibreOffice Module basegfx (master) 1
b3dtuple.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
22#include <sal/types.h>
26
27namespace basegfx
28{
29 class B3ITuple;
30
40 {
41 public:
47 : Tuple3D(0.0, 0.0, 0.0)
48 {}
49
64 B3DTuple(double fX, double fY, double fZ)
65 : Tuple3D(fX, fY, fZ)
66 {}
67
69 const double& operator[] (int nPos) const
70 {
71 // Here, normally two if(...)'s should be used. In the assumption that
72 // both double members can be accessed as an array a shortcut is used here.
73 // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ;
74 return *((&mfX) + nPos);
75 }
76
78 double& operator[] (int nPos)
79 {
80 // Here, normally two if(...)'s should be used. In the assumption that
81 // both double members can be accessed as an array a shortcut is used here.
82 // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ;
83 return *((&mfX) + nPos);
84 }
85
86 // comparators with tolerance
87
88
89 bool equalZero() const
90 {
91 return (this == &getEmptyTuple() ||
95 }
96
97 bool equal(const B3DTuple& rTup) const
98 {
99 return (
100 this == &rTup ||
101 (::basegfx::fTools::equal(mfX, rTup.mfX) &&
102 ::basegfx::fTools::equal(mfY, rTup.mfY) &&
103 ::basegfx::fTools::equal(mfZ, rTup.mfZ)));
104 }
105
106 // operators
107
108 B3DTuple operator-(void) const
109 {
110 return B3DTuple(-mfX, -mfY, -mfZ);
111 }
112
113 bool operator==(const B3DTuple& rTup) const
114 {
115 return ::basegfx::fTools::equal(mfX, rTup.mfX) &&
116 ::basegfx::fTools::equal(mfY, rTup.mfY) &&
117 ::basegfx::fTools::equal(mfZ, rTup.mfZ);
118 }
119
120 bool operator!=(const B3DTuple& rTup) const { return !operator==(rTup); }
121
122 void correctValues(const double fCompareValue = 0.0)
123 {
124 if(0.0 == fCompareValue)
125 {
127 {
128 mfX = 0.0;
129 }
130
132 {
133 mfY = 0.0;
134 }
135
137 {
138 mfZ = 0.0;
139 }
140 }
141 else
142 {
143 if(::basegfx::fTools::equal(mfX, fCompareValue))
144 {
145 mfX = fCompareValue;
146 }
147
148 if(::basegfx::fTools::equal(mfY, fCompareValue))
149 {
150 mfY = fCompareValue;
151 }
152
153 if(::basegfx::fTools::equal(mfZ, fCompareValue))
154 {
155 mfZ = fCompareValue;
156 }
157 }
158 }
159
160 static const B3DTuple& getEmptyTuple();
161 };
162
163 // external operators
164
165
166 inline B3DTuple interpolate(const B3DTuple& rOld1, const B3DTuple& rOld2, double t)
167 {
168 if(rOld1 == rOld2)
169 {
170 return rOld1;
171 }
172 else if(0.0 >= t)
173 {
174 return rOld1;
175 }
176 else if(1.0 <= t)
177 {
178 return rOld2;
179 }
180 else
181 {
182 return B3DTuple(
183 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
184 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(),
185 ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ());
186 }
187 }
188
189 inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2)
190 {
191 return B3DTuple(
192 rtl_math_approxEqual(rOld1.getX(), rOld2.getX()) ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
193 rtl_math_approxEqual(rOld1.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5,
194 rtl_math_approxEqual(rOld1.getZ(), rOld2.getZ()) ? rOld1.getZ() : (rOld1.getZ() + rOld2.getZ()) * 0.5);
195 }
196
197 inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB)
198 {
199 B3DTuple aSum(rTupA);
200 aSum += rTupB;
201 return aSum;
202 }
203
204 inline B3DTuple operator-(const B3DTuple& rTupA, const B3DTuple& rTupB)
205 {
206 B3DTuple aSub(rTupA);
207 aSub -= rTupB;
208 return aSub;
209 }
210
211 inline B3DTuple operator*(const B3DTuple& rTupA, const B3DTuple& rTupB)
212 {
213 B3DTuple aMul(rTupA);
214 aMul *= rTupB;
215 return aMul;
216 }
217
218 inline B3DTuple operator*(const B3DTuple& rTup, double t)
219 {
220 B3DTuple aNew(rTup);
221 aNew *= t;
222 return aNew;
223 }
224
225 inline B3DTuple operator/(const B3DTuple& rTup, double t)
226 {
227 B3DTuple aNew(rTup);
228 aNew /= t;
229 return aNew;
230 }
231
236 BASEGFX_DLLPUBLIC B3ITuple fround(const B3DTuple& rTup);
237} // end of namespace basegfx
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
Base class for all Points/Vectors with three double values.
Definition: b3dtuple.hxx:40
bool operator!=(const B3DTuple &rTup) const
Definition: b3dtuple.hxx:120
void correctValues(const double fCompareValue=0.0)
Definition: b3dtuple.hxx:122
bool equalZero() const
Definition: b3dtuple.hxx:89
B3DTuple()
Create a 3D Tuple.
Definition: b3dtuple.hxx:46
B3DTuple(double fX, double fY, double fZ)
Create a 3D Tuple.
Definition: b3dtuple.hxx:64
bool equal(const B3DTuple &rTup) const
Definition: b3dtuple.hxx:97
B3DTuple operator-(void) const
Definition: b3dtuple.hxx:108
bool operator==(const B3DTuple &rTup) const
Definition: b3dtuple.hxx:113
TYPE getX() const
Get X-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:57
TYPE getZ() const
Get Z-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:63
TYPE getY() const
Get Y-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:60
sal_uInt16 nPos
bool equalZero(const T &rfVal)
Compare against small value.
Definition: ftools.hxx:156
B2DTuple interpolate(const B2DTuple &rOld1, const B2DTuple &rOld2, double t)
Definition: b2dtuple.hxx:96
B2ITuple operator+(const B2ITuple &rTupA, const B2ITuple &rTupB)
Definition: b2ituple.hxx:72
B2DTuple average(const B2DTuple &rOld1, const B2DTuple &rOld2)
Definition: b2dtuple.hxx:118
B2IRange fround(const B2DRange &rRange)
Round double to nearest integer for 2D range.
Definition: b2drange.cxx:64
B2ITuple operator-(const B2ITuple &rTupA, const B2ITuple &rTupB)
Definition: b2ituple.hxx:79
B2DPoint operator*(const ::basegfx::B2DHomMatrix &rMat, const B2DPoint &rPoint)
Definition: b2dpoint.cxx:43
B2DTuple operator/(const B2DTuple &rTup, double t)
Definition: b2dtuple.hxx:139
double mfY
double mfX
#define SAL_WARN_UNUSED
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)