1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
13 #include <basegfx/utils/common.hxx>
14 #include <basegfx/numeric/ftools.hxx>
18 template <typename TYPE
> class Tuple2D
22 // temporary alias mnX with mfX and mnY with mfY
39 This parameter is used to initialize the X-coordinate
43 This parameter is used to initialize the Y-coordinate
46 Tuple2D(TYPE x
, TYPE y
)
52 double get(Axis2D eAxis
) { return eAxis
== Axis2D::X
? getX() : getY(); }
54 void set(Axis2D eAxis
, TYPE fValue
)
56 if (eAxis
== Axis2D::X
)
62 /// Get X-Coordinate of 2D Tuple
63 TYPE
getX() const { return mnX
; }
65 /// Get Y-Coordinate of 2D Tuple
66 TYPE
getY() const { return mnY
; }
68 /// Set X-Coordinate of 2D Tuple
69 void setX(TYPE fX
) { mnX
= fX
; }
71 /// Set Y-Coordinate of 2D Tuple
72 void setY(TYPE fY
) { mnY
= fY
; }
74 /// Adjust X-Coordinate of 2D Tuple
75 void adjustX(TYPE fX
) { mnX
+= fX
; }
77 /// Adjust Y-Coordinate of 2D Tuple
78 void adjustY(TYPE fY
) { mnY
+= fY
; }
80 // comparators with tolerance
82 template <typename T
= TYPE
, std::enable_if_t
<std::is_integral_v
<T
>, int> = 0>
83 bool equal(const Tuple2D
<TYPE
>& rTup
) const
85 return mfX
== rTup
.mfX
&& mfY
== rTup
.mfY
;
88 template <typename T
= TYPE
, std::enable_if_t
<std::is_floating_point_v
<T
>, int> = 0>
89 bool equal(const Tuple2D
<TYPE
>& rTup
) const
91 return this == &rTup
|| (fTools::equal(mfX
, rTup
.mfX
) && fTools::equal(mfY
, rTup
.mfY
));
94 template <typename T
= TYPE
, std::enable_if_t
<std::is_integral_v
<T
>, int> = 0>
95 bool equalZero() const
97 return mnX
== 0 && mnY
== 0;
100 template <typename T
= TYPE
, std::enable_if_t
<std::is_floating_point_v
<T
>, int> = 0>
101 bool equalZero() const
103 return fTools::equalZero(mfX
) && fTools::equalZero(mfY
);
106 // operator overrides
108 Tuple2D
<TYPE
>& operator+=(const Tuple2D
<TYPE
>& rTup
)
115 Tuple2D
<TYPE
>& operator-=(const Tuple2D
<TYPE
>& rTup
)
122 Tuple2D
<TYPE
>& operator/=(const Tuple2D
<TYPE
>& rTup
)
129 Tuple2D
<TYPE
>& operator*=(const Tuple2D
<TYPE
>& rTup
)
136 Tuple2D
<TYPE
>& operator*=(TYPE t
)
143 Tuple2D
<TYPE
>& operator/=(TYPE t
)
150 Tuple2D
<TYPE
> operator-(void) const { return Tuple2D
<TYPE
>(-mfX
, -mfY
); }
152 bool operator==(const Tuple2D
<TYPE
>& rTup
) const { return mfX
== rTup
.mfX
&& mfY
== rTup
.mfY
; }
154 bool operator!=(const Tuple2D
<TYPE
>& rTup
) const { return !(*this == rTup
); }
157 template <typename TYPE
>
158 inline Tuple2D
<TYPE
> operator-(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
160 Tuple2D
<TYPE
> aNew(rTupA
);
165 template <typename TYPE
>
166 inline Tuple2D
<TYPE
> operator+(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
168 Tuple2D
<TYPE
> aNew(rTupA
);
173 template <typename TYPE
>
174 inline Tuple2D
<TYPE
> operator*(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
176 Tuple2D
<TYPE
> aNew(rTupA
);
181 template <typename TYPE
>
182 inline Tuple2D
<TYPE
> operator/(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
184 Tuple2D
<TYPE
> aNew(rTupA
);
189 } // end of namespace basegfx
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */