diff options
Diffstat (limited to 'basegfx/inc/basegfx/point')
-rw-r--r-- | basegfx/inc/basegfx/point/b2dhompoint.hxx | 238 | ||||
-rw-r--r-- | basegfx/inc/basegfx/point/b2dpoint.hxx | 154 | ||||
-rw-r--r-- | basegfx/inc/basegfx/point/b2ipoint.hxx | 130 | ||||
-rw-r--r-- | basegfx/inc/basegfx/point/b3dhompoint.hxx | 408 | ||||
-rw-r--r-- | basegfx/inc/basegfx/point/b3dpoint.hxx | 153 | ||||
-rw-r--r-- | basegfx/inc/basegfx/point/b3ipoint.hxx | 142 |
6 files changed, 1225 insertions, 0 deletions
diff --git a/basegfx/inc/basegfx/point/b2dhompoint.hxx b/basegfx/inc/basegfx/point/b2dhompoint.hxx new file mode 100644 index 000000000000..591aec5e9ad3 --- /dev/null +++ b/basegfx/inc/basegfx/point/b2dhompoint.hxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: b2dhompoint.hxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B2DHOMPOINT_HXX +#define _BGFX_POINT_B2DHOMPOINT_HXX + +#include <basegfx/point/b2dpoint.hxx> + +namespace basegfx +{ + /** Basic homogen Point class with two double values and one homogen factor + + This class provides access to homogen coordinates in 2D. + For this purpose all the operators which need to do specific + action due to their homogenity are implemented here. + The only caveat are member methods which are declared as const + but do change the content. These are documented for that reason. + The class is designed to provide homogenous coordinates without + direct access to the homogen part (mfW). This is also the reason + for leaving out the [] operators which return references to members. + + @see B2DTuple + */ + class B2DHomPoint + { + protected: + /// This member contains the coordinate part of the point + ::basegfx::B2DTuple maTuple; + + /// This Member holds the homogenous part of the point + double mfW; + + /** Test if this homogen point does have a homogenous part + + @return Returns true if this point has no homogenous part + */ + bool implIsHomogenized() const; + + /** Remove homogenous part of this Point + + This method does necessary calculations to remove + the evtl. homogenous part of this Point. This may + change all members. + */ + void implHomogenize(); + + /** Test and on demand remove homogenous part + + This method tests if this Point does have a homogenous part + and then evtl. takes actions to remove that part. + + @attention Even when this method is const it may change all + members of this instance. This is due to the fact that changing + the homogenous part of a homogenous point does from a mathematical + point of view not change the point at all. + */ + void implTestAndHomogenize() const; + + public: + /** Create a homogen point + + The point is initialized to (0.0, 0.0) + */ + B2DHomPoint() + : maTuple(), + mfW(1.0) + {} + + /** Create a homogen point + + @param fX + This parameter is used to initialize the X-coordinate + of the Point. The homogenous part is initialized to 1.0. + + @param fY + This parameter is used to initialize the Y-coordinate + of the Point. The homogenous part is initialized to 1.0. + */ + B2DHomPoint(double fX, double fY) + : maTuple(fX, fY), + mfW(1.0) + {} + + /** Create a copy of a 2D Point + + @param rVec + The 2D point which will be copied. The homogenous part + is initialized to 1.0. + */ + B2DHomPoint(const B2DPoint& rVec) + : maTuple(rVec), + mfW(1.0) + {} + + /** Create a copy of a homogen point + + @param rVec + The homogen point which will be copied. The homogenous part + is copied, too. + */ + B2DHomPoint(const B2DHomPoint& rVec) + : maTuple(rVec.maTuple.getX(), rVec.maTuple.getY()), + mfW(rVec.mfW) + {} + + ~B2DHomPoint() + {} + + /** Get a 2D point from this homogenous point + + This method normalizes this homogen point if necessary and + returns the corresponding 2D point for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + B2DPoint getB2DPoint() const; + + /** Get X-coordinate + + This method normalizes this homogen point if necessary and + returns the corresponding X-coordinate for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + double getX() const; + + /** Get Y-coordinate + + This method normalizes this homogen point if necessary and + returns the corresponding Y-coordinate for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + double getY() const; + + /** Set X-coordinate of the homogen point. + + This method sets the X-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. + + @param fX + The to-be-set X-coordinate without homogenous part. + */ + void setX(double fX); + + /** Set Y-coordinate of the homogen point. + + This method sets the Y-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. + + @param fY + The to-be-set Y-coordinate without homogenous part. + */ + void setY(double fY); + + // operators + ////////////////////////////////////////////////////////////////////// + + B2DHomPoint& operator+=( const B2DHomPoint& rPnt ); + + B2DHomPoint& operator-=( const B2DHomPoint& rPnt ); + + B2DHomPoint& operator*=(double t); + + B2DHomPoint& operator*=( const B2DHomMatrix& rMat ); + + B2DHomPoint& operator/=(double t); + + B2DHomPoint& operator-(void); + + bool operator==( const B2DHomPoint& rPnt ) const; + + bool operator!=( const B2DHomPoint& rPnt ) const; + + B2DHomPoint& operator=( const B2DHomPoint& rPnt ); + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + B2DHomPoint minimum(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + + B2DHomPoint maximum(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + + B2DHomPoint absolute(const B2DHomPoint& rVec); + + B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t); + + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2); + + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3); + + B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + + B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB); + + B2DHomPoint operator*(const B2DHomPoint& rVec, double t); + + B2DHomPoint operator*(double t, const B2DHomPoint& rVec); + + B2DHomPoint operator*( const B2DHomMatrix& rMat, const B2DHomPoint& rPoint ); + + B2DHomPoint operator/(const B2DHomPoint& rVec, double t); + + B2DHomPoint operator/(double t, const B2DHomPoint& rVec); +} // end of namespace basegfx + +#endif /* _BGFX_POINT_B2DHOMPOINT_HXX */ diff --git a/basegfx/inc/basegfx/point/b2dpoint.hxx b/basegfx/inc/basegfx/point/b2dpoint.hxx new file mode 100644 index 000000000000..ad65b836409c --- /dev/null +++ b/basegfx/inc/basegfx/point/b2dpoint.hxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: b2dpoint.hxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B2DPOINT_HXX +#define _BGFX_POINT_B2DPOINT_HXX + +#include <basegfx/tuple/b2dtuple.hxx> +#include <basegfx/point/b2ipoint.hxx> + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + // predeclaration + class B2DHomMatrix; + + /** Base Point class with two double values + + This class derives all operators and common handling for + a 2D data class from B2DTuple. All necessary extensions + which are special for points will be added here. + + @see B2DTuple + */ + class B2DPoint : public ::basegfx::B2DTuple + { + public: + /** Create a 2D Point + + The point is initialized to (0.0, 0.0) + */ + B2DPoint() + : B2DTuple() + {} + + /** Create a 2D Point + + @param fX + This parameter is used to initialize the X-coordinate + of the 2D Point. + + @param fY + This parameter is used to initialize the Y-coordinate + of the 2D Point. + */ + B2DPoint(double fX, double fY) + : B2DTuple(fX, fY) + {} + + /** Create a copy of a 2D Point + + @param rPoint + The 2D Point which will be copied. + */ + B2DPoint(const B2DPoint& rPoint) + : B2DTuple(rPoint) + {} + + /** Create a copy of a 2D Point + + @param rPoint + The 2D Point which will be copied. + */ + B2DPoint(const ::basegfx::B2IPoint& rPoint) + : B2DTuple(rPoint) + {} + + /** constructor with tuple to allow copy-constructing + from B2DTuple-based classes + */ + B2DPoint(const ::basegfx::B2DTuple& rTuple) + : B2DTuple(rTuple) + {} + + ~B2DPoint() + {} + + /** *=operator to allow usage from B2DPoint, too + */ + B2DPoint& operator*=( const B2DPoint& rPnt ) + { + mfX *= rPnt.mfX; + mfY *= rPnt.mfY; + return *this; + } + + /** *=operator to allow usage from B2DPoint, too + */ + B2DPoint& operator*=(double t) + { + mfX *= t; + mfY *= t; + return *this; + } + + /** assignment operator to allow assigning the results + of B2DTuple calculations + */ + B2DPoint& operator=( const ::basegfx::B2DTuple& rPoint ); + + /** Transform point by given transformation matrix. + + The translational components of the matrix are, in + contrast to B2DVector, applied. + */ + B2DPoint& operator*=( const ::basegfx::B2DHomMatrix& rMat ); + + static const B2DPoint& getEmptyPoint() + { + return (const B2DPoint&) ::basegfx::B2DTuple::getEmptyTuple(); + } + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + /** Transform B2DPoint by given transformation matrix. + + Since this is a Point, translational components of the + matrix are used. + */ + B2DPoint operator*( const B2DHomMatrix& rMat, const B2DPoint& rPoint ); +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +#endif /* _BGFX_POINT_B2DPOINT_HXX */ diff --git a/basegfx/inc/basegfx/point/b2ipoint.hxx b/basegfx/inc/basegfx/point/b2ipoint.hxx new file mode 100644 index 000000000000..198e7a1dd22b --- /dev/null +++ b/basegfx/inc/basegfx/point/b2ipoint.hxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: b2ipoint.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B2IPOINT_HXX +#define _BGFX_POINT_B2IPOINT_HXX + +#include <basegfx/tuple/b2ituple.hxx> + +namespace basegfx +{ + // predeclaration + class B2DHomMatrix; + + /** Base Point class with two sal_Int32 values + + This class derives all operators and common handling for + a 2D data class from B2ITuple. All necessary extensions + which are special for points will be added here. + + @see B2ITuple + */ + class B2IPoint : public ::basegfx::B2ITuple + { + public: + /** Create a 2D Point + + The point is initialized to (0, 0) + */ + B2IPoint() + : B2ITuple() + {} + + /** Create a 2D Point + + @param nX + This parameter is used to initialize the X-coordinate + of the 2D Point. + + @param nY + This parameter is used to initialize the Y-coordinate + of the 2D Point. + */ + B2IPoint(sal_Int32 nX, sal_Int32 nY) + : B2ITuple(nX, nY) + {} + + /** Create a copy of a 2D Point + + @param rPoint + The 2D Point which will be copied. + */ + B2IPoint(const B2IPoint& rPoint) + : B2ITuple(rPoint) + {} + + /** constructor with tuple to allow copy-constructing + from B2ITuple-based classes + */ + B2IPoint(const ::basegfx::B2ITuple& rTuple) + : B2ITuple(rTuple) + {} + + ~B2IPoint() + {} + + /** *=operator to allow usage from B2IPoint, too + */ + B2IPoint& operator*=( const B2IPoint& rPnt ) + { + mnX *= rPnt.mnX; + mnY *= rPnt.mnY; + return *this; + } + + /** *=operator to allow usage from B2IPoint, too + */ + B2IPoint& operator*=(sal_Int32 t) + { + mnX *= t; + mnY *= t; + return *this; + } + + /** assignment operator to allow assigning the results + of B2ITuple calculations + */ + B2IPoint& operator=( const ::basegfx::B2ITuple& rPoint ); + + /** Transform point by given transformation matrix. + + The translational components of the matrix are, in + contrast to B2DVector, applied. + */ + B2IPoint& operator*=( const ::basegfx::B2DHomMatrix& rMat ); + + static const B2IPoint& getEmptyPoint() + { + return (const B2IPoint&) ::basegfx::B2ITuple::getEmptyTuple(); + } + }; +} // end of namespace basegfx + +#endif /* _BGFX_POINT_B2IPOINT_HXX */ diff --git a/basegfx/inc/basegfx/point/b3dhompoint.hxx b/basegfx/inc/basegfx/point/b3dhompoint.hxx new file mode 100644 index 000000000000..bbe684144641 --- /dev/null +++ b/basegfx/inc/basegfx/point/b3dhompoint.hxx @@ -0,0 +1,408 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: b3dhompoint.hxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B3DHOMPOINT_HXX +#define _BGFX_POINT_B3DHOMPOINT_HXX + +#include <basegfx/point/b3dpoint.hxx> + +namespace basegfx +{ + /** Basic homogen Point class with three double values and one homogen factor + + This class provides access to homogen coordinates in 3D. + For this purpose all the operators which need to do specific + action due to their homogenity are implemented here. + The only caveat are member methods which are declared as const + but do change the content. These are documented for that reason. + The class is designed to provide homogenous coordinates without + direct access to the homogen part (mfW). This is also the reason + for leaving out the [] operators which return references to members. + + @see B3DTuple + */ + class B3DHomPoint + { + protected: + /// This member contains the coordinate part of the point + ::basegfx::B3DTuple maTuple; + + /// This Member holds the homogenous part of the point + double mfW; + + /** Test if this homogen point does have a homogenous part + + @return Returns true if this point has no homogenous part + */ + bool implIsHomogenized() const + { + const double fOne(1.0); + return ::basegfx::fTools::equal(mfW, fOne); + } + + /** Remove homogenous part of this Point + + This method does necessary calculations to remove + the evtl. homogenous part of this Point. This may + change all members. + */ + void implHomogenize(); + + /** Test and on demand remove homogenous part + + This method tests if this Point does have a homogenous part + and then evtl. takes actions to remove that part. + + @attention Even when this method is const it may change all + members of this instance. This is due to the fact that changing + the homogenous part of a homogenous point does from a mathematical + point of view not change the point at all. + */ + void implTestAndHomogenize() const + { + if(!implIsHomogenized()) + ((B3DHomPoint*)this)->implHomogenize(); + } + + public: + /** Create a homogen point + + The point is initialized to (0.0, 0.0, 0.0) + */ + B3DHomPoint() + : maTuple(), + mfW(1.0) + {} + + /** Create a homogen point + + @param fX + This parameter is used to initialize the X-coordinate + of the Point. The homogenous part is initialized to 1.0. + + @param fY + This parameter is used to initialize the Y-coordinate + of the Point. The homogenous part is initialized to 1.0. + + @param fZ + This parameter is used to initialize the Z-coordinate + of the Point. The homogenous part is initialized to 1.0. + */ + B3DHomPoint(double fX, double fY, double fZ) + : maTuple(fX, fY, fZ), + mfW(1.0) + {} + + /** Create a copy of a 3D Point + + @param rVec + The 3D point which will be copied. The homogenous part + is initialized to 1.0. + */ + B3DHomPoint(const B3DPoint& rVec) + : maTuple(rVec), + mfW(1.0) + {} + + /** Create a copy of a homogen point + + @param rVec + The homogen point which will be copied. The homogenous part + is copied, too. + */ + B3DHomPoint(const B3DHomPoint& rVec) + : maTuple(rVec.maTuple.getX(), rVec.maTuple.getY(), rVec.maTuple.getZ()), + mfW(rVec.mfW) + {} + + ~B3DHomPoint() + {} + + /** get a 3D point from this homogenous point + + This method normalizes this homogen point if necessary and + returns the corresponding 3D point for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + B3DPoint getB3DPoint() const + { + implTestAndHomogenize(); + return B3DPoint(maTuple.getX(), maTuple.getY(), maTuple.getZ()); + } + + /** get X-coordinate + + This method normalizes this homogen point if necessary and + returns the corresponding X-coordinate for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + double getX() const + { + implTestAndHomogenize(); + return maTuple.getX(); + } + + /** get Y-coordinate + + This method normalizes this homogen point if necessary and + returns the corresponding Y-coordinate for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + double getY() const + { + implTestAndHomogenize(); + return maTuple.getY(); + } + + /** get Z-coordinate + + This method normalizes this homogen point if necessary and + returns the corresponding Z-coordinate for this homogen point. + + @attention Even when this method is const it may change all + members of this instance. + */ + double getZ() const + { + implTestAndHomogenize(); + return maTuple.getY(); + } + + /** Set X-coordinate of the homogen point. + + This method sets the X-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. + + @param fX + The to-be-set X-coordinate without homogenous part. + */ + void setX(double fX) + { + maTuple.setX(implIsHomogenized() ? fX : fX * mfW ); + } + + /** Set Y-coordinate of the homogen point. + + This method sets the Y-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. + + @param fY + The to-be-set Y-coordinate without homogenous part. + */ + void setY(double fY) + { + maTuple.setY(implIsHomogenized() ? fY : fY * mfW ); + } + + /** Set Z-coordinate of the homogen point. + + This method sets the Z-coordinate of the homogen point. If + the point does have a homogenous part this is taken into account. + + @param fZ + The to-be-set Z-coordinate without homogenous part. + */ + void setZ(double fZ) + { + maTuple.setZ(implIsHomogenized() ? fZ : fZ * mfW ); + } + + // operators + ////////////////////////////////////////////////////////////////////// + + B3DHomPoint& operator+=( const B3DHomPoint& rPnt ) + { + maTuple.setX(getX() * rPnt.mfW + rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW + rPnt.getY() * mfW); + maTuple.setZ(getZ() * rPnt.mfW + rPnt.getZ() * mfW); + mfW = mfW * rPnt.mfW; + + return *this; + } + + B3DHomPoint& operator-=( const B3DHomPoint& rPnt ) + { + maTuple.setX(getX() * rPnt.mfW - rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW - rPnt.getY() * mfW); + maTuple.setZ(getZ() * rPnt.mfW - rPnt.getZ() * mfW); + mfW = mfW * rPnt.mfW; + + return *this; + } + + B3DHomPoint& operator*=(double t) + { + if(!::basegfx::fTools::equalZero(t)) + { + mfW /= t; + } + + return *this; + } + + B3DHomPoint& operator/=(double t) + { + mfW *= t; + return *this; + } + + B3DHomPoint& operator-(void) + { + mfW = -mfW; + return *this; + } + + bool operator==( const B3DHomPoint& rPnt ) const + { + implTestAndHomogenize(); + return (maTuple == rPnt.maTuple); + } + + bool operator!=( const B3DHomPoint& rPnt ) const + { + implTestAndHomogenize(); + return (maTuple != rPnt.maTuple); + } + + B3DHomPoint& operator=( const B3DHomPoint& rPnt ) + { + maTuple = rPnt.maTuple; + mfW = rPnt.mfW; + return *this; + } + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + inline B3DHomPoint minimum(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aMin( + (rVecB.getX() < rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() < rVecA.getY()) ? rVecB.getY() : rVecA.getY(), + (rVecB.getZ() < rVecA.getZ()) ? rVecB.getZ() : rVecA.getZ()); + return aMin; + } + + inline B3DHomPoint maximum(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aMax( + (rVecB.getX() > rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() > rVecA.getY()) ? rVecB.getY() : rVecA.getY(), + (rVecB.getZ() > rVecA.getZ()) ? rVecB.getZ() : rVecA.getZ()); + return aMax; + } + + inline B3DHomPoint absolute(const B3DHomPoint& rVec) + { + B3DHomPoint aAbs( + (0.0 > rVec.getX()) ? -rVec.getX() : rVec.getX(), + (0.0 > rVec.getY()) ? -rVec.getY() : rVec.getY(), + (0.0 > rVec.getZ()) ? -rVec.getZ() : rVec.getZ()); + return aAbs; + } + + inline B3DHomPoint interpolate(B3DHomPoint& rOld1, B3DHomPoint& rOld2, double t) + { + B3DHomPoint aInt( + ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), + ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(), + ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ()); + return aInt; + } + + inline B3DHomPoint average(B3DHomPoint& rOld1, B3DHomPoint& rOld2) + { + B3DHomPoint aAvg( + (rOld1.getX() + rOld2.getX()) * 0.5, + (rOld1.getY() + rOld2.getY()) * 0.5, + (rOld1.getZ() + rOld2.getZ()) * 0.5); + return aAvg; + } + + inline B3DHomPoint average(B3DHomPoint& rOld1, B3DHomPoint& rOld2, B3DHomPoint& rOld3) + { + B3DHomPoint aAvg( + (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), + (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0), + (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0)); + return aAvg; + } + + inline B3DHomPoint operator+(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aSum(rVecA); + aSum += rVecB; + return aSum; + } + + inline B3DHomPoint operator-(const B3DHomPoint& rVecA, const B3DHomPoint& rVecB) + { + B3DHomPoint aSub(rVecA); + aSub -= rVecB; + return aSub; + } + + inline B3DHomPoint operator*(const B3DHomPoint& rVec, double t) + { + B3DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + inline B3DHomPoint operator*(double t, const B3DHomPoint& rVec) + { + B3DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + inline B3DHomPoint operator/(const B3DHomPoint& rVec, double t) + { + B3DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } + + inline B3DHomPoint operator/(double t, const B3DHomPoint& rVec) + { + B3DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } +} // end of namespace basegfx + +#endif /* _BGFX_POINT_B3DHOMPOINT_HXX */ diff --git a/basegfx/inc/basegfx/point/b3dpoint.hxx b/basegfx/inc/basegfx/point/b3dpoint.hxx new file mode 100644 index 000000000000..15a78986f636 --- /dev/null +++ b/basegfx/inc/basegfx/point/b3dpoint.hxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: b3dpoint.hxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B3DPOINT_HXX +#define _BGFX_POINT_B3DPOINT_HXX + +#include <basegfx/tuple/b3dtuple.hxx> + +namespace basegfx +{ + // predeclaration + class B3DHomMatrix; + + /** Base Point class with three double values + + This class derives all operators and common handling for + a 3D data class from B3DTuple. All necessary extensions + which are special for points will be added here. + + @see B3DTuple + */ + class B3DPoint : public ::basegfx::B3DTuple + { + public: + /** Create a 3D Point + + The point is initialized to (0.0, 0.0, 0.0) + */ + B3DPoint() + : B3DTuple() + {} + + /** Create a 3D Point + + @param fX + This parameter is used to initialize the X-coordinate + of the 3D Point. + + @param fY + This parameter is used to initialize the Y-coordinate + of the 3D Point. + + @param fZ + This parameter is used to initialize the Z-coordinate + of the 3D Point. + */ + B3DPoint(double fX, double fY, double fZ) + : B3DTuple(fX, fY, fZ) + {} + + /** Create a copy of a 3D Point + + @param rVec + The 3D Point which will be copied. + */ + B3DPoint(const B3DPoint& rVec) + : B3DTuple(rVec) + {} + + /** constructor with tuple to allow copy-constructing + from B3DTuple-based classes + */ + B3DPoint(const ::basegfx::B3DTuple& rTuple) + : B3DTuple(rTuple) + {} + + ~B3DPoint() + {} + + /** *=operator to allow usage from B3DPoint, too + */ + B3DPoint& operator*=( const B3DPoint& rPnt ) + { + mfX *= rPnt.mfX; + mfY *= rPnt.mfY; + mfZ *= rPnt.mfZ; + return *this; + } + + /** *=operator to allow usage from B3DPoint, too + */ + B3DPoint& operator*=(double t) + { + mfX *= t; + mfY *= t; + mfZ *= t; + return *this; + } + + /** assignment operator to allow assigning the results + of B3DTuple calculations + */ + B3DPoint& operator=( const ::basegfx::B3DTuple& rVec ) + { + mfX = rVec.getX(); + mfY = rVec.getY(); + mfZ = rVec.getZ(); + return *this; + } + + /** Transform point by given transformation matrix. + + The translational components of the matrix are, in + contrast to B3DVector, applied. + */ + B3DPoint& operator*=( const ::basegfx::B3DHomMatrix& rMat ); + + static const B3DPoint& getEmptyPoint() + { + return (const B3DPoint&) ::basegfx::B3DTuple::getEmptyTuple(); + } + }; + + // external operators + ////////////////////////////////////////////////////////////////////////// + + /** Transform B3DPoint by given transformation matrix. + + Since this is a Point, translational components of the + matrix are used. + */ + B3DPoint operator*( const B3DHomMatrix& rMat, const B3DPoint& rPoint ); + +} // end of namespace basegfx + +#endif /* _BGFX_POINT_B3DPOINT_HXX */ diff --git a/basegfx/inc/basegfx/point/b3ipoint.hxx b/basegfx/inc/basegfx/point/b3ipoint.hxx new file mode 100644 index 000000000000..4d40e0becb37 --- /dev/null +++ b/basegfx/inc/basegfx/point/b3ipoint.hxx @@ -0,0 +1,142 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: b3ipoint.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B3IPOINT_HXX +#define _BGFX_POINT_B3IPOINT_HXX + +#include <basegfx/tuple/b3ituple.hxx> + +namespace basegfx +{ + // predeclaration + class B3DHomMatrix; + + /** Base Point class with three sal_Int32 values + + This class derives all operators and common handling for + a 3D data class from B3ITuple. All necessary extensions + which are special for points will be added here. + + @see B3ITuple + */ + class B3IPoint : public ::basegfx::B3ITuple + { + public: + /** Create a 3D Point + + The point is initialized to (0, 0, 0) + */ + B3IPoint() + : B3ITuple() + {} + + /** Create a 3D Point + + @param nX + This parameter is used to initialize the X-coordinate + of the 3D Point. + + @param nY + This parameter is used to initialize the Y-coordinate + of the 3D Point. + + @param nZ + This parameter is used to initialize the Z-coordinate + of the 3D Point. + */ + B3IPoint(sal_Int32 nX, sal_Int32 nY, sal_Int32 nZ) + : B3ITuple(nX, nY, nZ) + {} + + /** Create a copy of a 3D Point + + @param rVec + The 3D Point which will be copied. + */ + B3IPoint(const B3IPoint& rVec) + : B3ITuple(rVec) + {} + + /** constructor with tuple to allow copy-constructing + from B3ITuple-based classes + */ + B3IPoint(const ::basegfx::B3ITuple& rTuple) + : B3ITuple(rTuple) + {} + + ~B3IPoint() + {} + + /** *=operator to allow usage from B3IPoint, too + */ + B3IPoint& operator*=( const B3IPoint& rPnt ) + { + mnX *= rPnt.mnX; + mnY *= rPnt.mnY; + mnZ *= rPnt.mnZ; + return *this; + } + + /** *=operator to allow usage from B3IPoint, too + */ + B3IPoint& operator*=(sal_Int32 t) + { + mnX *= t; + mnY *= t; + mnZ *= t; + return *this; + } + + /** assignment operator to allow assigning the results + of B3ITuple calculations + */ + B3IPoint& operator=( const ::basegfx::B3ITuple& rVec ) + { + mnX = rVec.getX(); + mnY = rVec.getY(); + mnZ = rVec.getZ(); + return *this; + } + + /** Transform point by given transformation matrix. + + The translational components of the matrix are, in + contrast to B3DVector, applied. + */ + B3IPoint& operator*=( const ::basegfx::B3DHomMatrix& rMat ); + + static const B3IPoint& getEmptyPoint() + { + return (const B3IPoint&) ::basegfx::B3ITuple::getEmptyTuple(); + } + }; +} // end of namespace basegfx + +#endif /* _BGFX_POINT_B3IPOINT_HXX */ |