include/basegfx/tuple/Size2D.hxx | 115 ++++++++++++++++++++++++++++++++++++++ include/basegfx/tuple/Tuple2D.hxx | 2 2 files changed, 117 insertions(+)
New commits: commit ac7c09450bfc50269c0244fdb6eb55f2829d7dbf Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Sep 6 19:39:00 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Sep 10 08:46:23 2022 +0200 basegfx: add Size2D template class - subclass Tuple2D Also improve Tuple2D - add operators Change-Id: I9b23fb2f716ab99a4d4349a48f4ccc2334a9f865 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139682 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/basegfx/tuple/Size2D.hxx b/include/basegfx/tuple/Size2D.hxx new file mode 100644 index 000000000000..87bd95330bb8 --- /dev/null +++ b/include/basegfx/tuple/Size2D.hxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include <basegfx/tuple/Tuple2D.hxx> + +namespace basegfx +{ +template <typename TYPE> class Size2D : protected Tuple2D<TYPE> +{ +public: + Size2D(TYPE width, TYPE height) + : Tuple2D<TYPE>(width, height) + { + } + + Size2D(Tuple2D<double> const& rTuple) + : Tuple2D<TYPE>(rTuple.getX(), rTuple.getY()) + { + } + + TYPE getWidth() const { return Tuple2D<TYPE>::getX(); } + + TYPE getHeight() const { return Tuple2D<TYPE>::getY(); } + + void setWidth(TYPE const& rWidth) { Tuple2D<TYPE>::setX(rWidth); } + + void setHeight(TYPE const& rHeight) { Tuple2D<TYPE>::setY(rHeight); } + + bool operator==(Size2D<TYPE> const& rSize) const { return Tuple2D<TYPE>::operator==(rSize); } + + bool operator!=(Size2D<TYPE> const& rSize) const { return Tuple2D<TYPE>::operator!=(rSize); } + + Size2D<TYPE>& operator-=(Size2D<TYPE> const& rSize) + { + Tuple2D<TYPE>::operator-=(rSize); + return *this; + } + + Size2D<TYPE>& operator+=(Size2D<TYPE> const& rSize) + { + Tuple2D<TYPE>::operator+=(rSize); + return *this; + } + + Size2D<TYPE>& operator/=(Size2D<TYPE> const& rSize) + { + Tuple2D<TYPE>::operator/=(rSize); + return *this; + } + + Size2D<TYPE>& operator*=(Size2D<TYPE> const& rSize) + { + Tuple2D<TYPE>::operator*=(rSize); + return *this; + } + + Size2D<TYPE>& operator*=(TYPE value) + { + Tuple2D<TYPE>::operator*=(value); + return *this; + } + + Size2D<TYPE>& operator/=(TYPE value) + { + Tuple2D<TYPE>::operator/=(value); + return *this; + } + + Size2D<TYPE> operator-(void) const { return Tuple2D<TYPE>::operator-(); } +}; + +template <typename TYPE> +inline Size2D<TYPE> operator-(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB) +{ + Size2D<TYPE> aNew(rSizeA); + aNew -= rSizeB; + return aNew; +} + +template <typename TYPE> +inline Size2D<TYPE> operator+(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB) +{ + Size2D<TYPE> aNew(rSizeA); + aNew += rSizeB; + return aNew; +} + +template <typename TYPE> +inline Size2D<TYPE> operator*(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB) +{ + Size2D<TYPE> aNew(rSizeA); + aNew *= rSizeB; + return aNew; +} + +template <typename TYPE> +inline Size2D<TYPE> operator/(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB) +{ + Size2D<TYPE> aNew(rSizeA); + aNew /= rSizeB; + return aNew; +} + +} // end of namespace gfx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basegfx/tuple/Tuple2D.hxx b/include/basegfx/tuple/Tuple2D.hxx index 8bc53fe9b88d..b4d1dbe2f508 100644 --- a/include/basegfx/tuple/Tuple2D.hxx +++ b/include/basegfx/tuple/Tuple2D.hxx @@ -147,6 +147,8 @@ public: return *this; } + Tuple2D<TYPE> operator-(void) const { return Tuple2D<TYPE>(-mfX, -mfY); } + bool operator==(const Tuple2D<TYPE>& rTup) const { return mfX == rTup.mfX && mfY == rTup.mfY; } bool operator!=(const Tuple2D<TYPE>& rTup) const { return !(*this == rTup); }