diff options
Diffstat (limited to 'include/basegfx')
-rw-r--r-- | include/basegfx/tuple/b2dtuple.hxx | 26 | ||||
-rw-r--r-- | include/basegfx/utils/common.hxx | 33 |
2 files changed, 44 insertions, 15 deletions
diff --git a/include/basegfx/tuple/b2dtuple.hxx b/include/basegfx/tuple/b2dtuple.hxx index 059820bd78fd..d26310de9975 100644 --- a/include/basegfx/tuple/b2dtuple.hxx +++ b/include/basegfx/tuple/b2dtuple.hxx @@ -23,6 +23,7 @@ #include <sal/types.h> #include <basegfx/numeric/ftools.hxx> #include <basegfx/basegfxdllapi.h> +#include <basegfx/utils/common.hxx> namespace basegfx { @@ -39,10 +40,11 @@ namespace basegfx class SAL_WARN_UNUSED B2DTuple { protected: - double mfX; - double mfY; + double mfX; + double mfY; public: + /** Create a 2D Tuple The tuple is initialized to (0.0, 0.0) @@ -98,27 +100,21 @@ namespace basegfx mfY = fY; } - /// Array-access to 2D Tuple - const double& operator[] (int nPos) const + double get(Axis2D eAxis) { - // Here, normally one if(...) should be used. In the assumption that - // both double members can be accessed as an array a shortcut is used here. - // if(0 == nPos) return mfX; return mfY; - return *((&mfX) + nPos); + return eAxis == Axis2D::X ? getX() : getY(); } - /// Array-access to 2D Tuple - double& operator[] (int nPos) + void set(Axis2D eAxis, double fValue) { - // Here, normally one if(...) should be used. In the assumption that - // both double members can be accessed as an array a shortcut is used here. - // if(0 == nPos) return mfX; return mfY; - return *((&mfX) + nPos); + if (eAxis == Axis2D::X) + setX(fValue); + else + setY(fValue); } // comparators with tolerance - bool equalZero() const { return (this == &getEmptyTuple() || diff --git a/include/basegfx/utils/common.hxx b/include/basegfx/utils/common.hxx new file mode 100644 index 000000000000..522bfbcb2bff --- /dev/null +++ b/include/basegfx/utils/common.hxx @@ -0,0 +1,33 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +namespace basegfx +{ +// The axis or dimension in a 2D coordiante system +enum class Axis2D +{ + X, + Y +}; + +} // end of namespace basegfx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |