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 <o3tl/concepts.hxx>
14 #include <basegfx/utils/common.hxx>
15 #include <basegfx/numeric/ftools.hxx>
19 template <typename TYPE
> class Tuple2D
29 This parameter is used to initialize the X-coordinate
33 This parameter is used to initialize the Y-coordinate
36 Tuple2D(TYPE x
, TYPE y
)
42 double get(Axis2D eAxis
) { return eAxis
== Axis2D::X
? getX() : getY(); }
44 void set(Axis2D eAxis
, TYPE fValue
)
46 if (eAxis
== Axis2D::X
)
52 /// Get X-Coordinate of 2D Tuple
53 TYPE
getX() const { return mnX
; }
55 /// Get Y-Coordinate of 2D Tuple
56 TYPE
getY() const { return mnY
; }
58 /// Set X-Coordinate of 2D Tuple
59 void setX(TYPE fX
) { mnX
= fX
; }
61 /// Set Y-Coordinate of 2D Tuple
62 void setY(TYPE fY
) { mnY
= fY
; }
64 /// Adjust X-Coordinate of 2D Tuple
65 void adjustX(TYPE fX
) { mnX
+= fX
; }
67 /// Adjust Y-Coordinate of 2D Tuple
68 void adjustY(TYPE fY
) { mnY
+= fY
; }
70 // comparators with tolerance
72 template <o3tl::integral T
= TYPE
> bool equal(const Tuple2D
<TYPE
>& rTup
) const
74 return mnX
== rTup
.mnX
&& mnY
== rTup
.mnY
;
77 template <o3tl::floating_point T
= TYPE
> bool equal(const Tuple2D
<TYPE
>& rTup
) const
79 return this == &rTup
|| (fTools::equal(mnX
, rTup
.mnX
) && fTools::equal(mnY
, rTup
.mnY
));
82 template <o3tl::integral T
= TYPE
> bool equalZero() const { return mnX
== 0 && mnY
== 0; }
84 template <o3tl::floating_point T
= TYPE
> bool equalZero() const
86 return fTools::equalZero(mnX
) && fTools::equalZero(mnY
);
91 Tuple2D
<TYPE
>& operator+=(const Tuple2D
<TYPE
>& rTup
)
98 Tuple2D
<TYPE
>& operator-=(const Tuple2D
<TYPE
>& rTup
)
105 Tuple2D
<TYPE
>& operator/=(const Tuple2D
<TYPE
>& rTup
)
112 Tuple2D
<TYPE
>& operator*=(const Tuple2D
<TYPE
>& rTup
)
119 Tuple2D
<TYPE
>& operator*=(TYPE t
)
126 Tuple2D
<TYPE
>& operator/=(TYPE t
)
133 Tuple2D
<TYPE
> operator-(void) const { return Tuple2D
<TYPE
>(-mnX
, -mnY
); }
135 bool operator==(const Tuple2D
<TYPE
>& rTup
) const { return mnX
== rTup
.mnX
&& mnY
== rTup
.mnY
; }
137 bool operator!=(const Tuple2D
<TYPE
>& rTup
) const { return !(*this == rTup
); }
140 template <typename TYPE
>
141 inline Tuple2D
<TYPE
> operator-(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
143 Tuple2D
<TYPE
> aNew(rTupA
);
148 template <typename TYPE
>
149 inline Tuple2D
<TYPE
> operator+(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
151 Tuple2D
<TYPE
> aNew(rTupA
);
156 template <typename TYPE
>
157 inline Tuple2D
<TYPE
> operator*(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
159 Tuple2D
<TYPE
> aNew(rTupA
);
164 template <typename TYPE
>
165 inline Tuple2D
<TYPE
> operator/(const Tuple2D
<TYPE
>& rTupA
, const Tuple2D
<TYPE
>& rTupB
)
167 Tuple2D
<TYPE
> aNew(rTupA
);
172 } // end of namespace basegfx
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */