1ce9c7ef7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ce9c7ef7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ce9c7ef7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5ce9c7ef7SAndrew Rist * distributed with this work for additional information 6ce9c7ef7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ce9c7ef7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8ce9c7ef7SAndrew Rist * "License"); you may not use this file except in compliance 9ce9c7ef7SAndrew Rist * with the License. You may obtain a copy of the License at 10ce9c7ef7SAndrew Rist * 11ce9c7ef7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ce9c7ef7SAndrew Rist * 13ce9c7ef7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14ce9c7ef7SAndrew Rist * software distributed under the License is distributed on an 15ce9c7ef7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ce9c7ef7SAndrew Rist * KIND, either express or implied. See the License for the 17ce9c7ef7SAndrew Rist * specific language governing permissions and limitations 18ce9c7ef7SAndrew Rist * under the License. 19ce9c7ef7SAndrew Rist * 20ce9c7ef7SAndrew Rist *************************************************************/ 21ce9c7ef7SAndrew Rist 22ce9c7ef7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _BGFX_VECTOR_B2IVECTOR_HXX 25cdf0e10cSrcweir #define _BGFX_VECTOR_B2IVECTOR_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <basegfx/tuple/b2ituple.hxx> 28cdf0e10cSrcweir #include <basegfx/vector/b2enums.hxx> 29*b63233d8Sdamjan #include <basegfx/basegfxdllapi.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace basegfx 32cdf0e10cSrcweir { 33cdf0e10cSrcweir // predeclaration 34cdf0e10cSrcweir class B2DHomMatrix; 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** Base Point class with two sal_Int32 values 37cdf0e10cSrcweir 38cdf0e10cSrcweir This class derives all operators and common handling for 39cdf0e10cSrcweir a 2D data class from B2ITuple. All necessary extensions 40cdf0e10cSrcweir which are special for 2D Vectors are added here. 41cdf0e10cSrcweir 42cdf0e10cSrcweir @see B2ITuple 43cdf0e10cSrcweir */ 44*b63233d8Sdamjan class BASEGFX_DLLPUBLIC B2IVector : public ::basegfx::B2ITuple 45cdf0e10cSrcweir { 46cdf0e10cSrcweir public: 47cdf0e10cSrcweir /** Create a 2D Vector 48cdf0e10cSrcweir 49cdf0e10cSrcweir The vector is initialized to (0, 0) 50cdf0e10cSrcweir */ B2IVector()51cdf0e10cSrcweir B2IVector() 52cdf0e10cSrcweir : B2ITuple() 53cdf0e10cSrcweir {} 54cdf0e10cSrcweir 55cdf0e10cSrcweir /** Create a 2D Vector 56cdf0e10cSrcweir 57cdf0e10cSrcweir @param nX 58cdf0e10cSrcweir This parameter is used to initialize the X-coordinate 59cdf0e10cSrcweir of the 2D Vector. 60cdf0e10cSrcweir 61cdf0e10cSrcweir @param nY 62cdf0e10cSrcweir This parameter is used to initialize the Y-coordinate 63cdf0e10cSrcweir of the 2D Vector. 64cdf0e10cSrcweir */ B2IVector(sal_Int32 nX,sal_Int32 nY)65cdf0e10cSrcweir B2IVector(sal_Int32 nX, sal_Int32 nY) 66cdf0e10cSrcweir : B2ITuple(nX, nY) 67cdf0e10cSrcweir {} 68cdf0e10cSrcweir 69cdf0e10cSrcweir /** Create a copy of a 2D Vector 70cdf0e10cSrcweir 71cdf0e10cSrcweir @param rVec 72cdf0e10cSrcweir The 2D Vector which will be copied. 73cdf0e10cSrcweir */ B2IVector(const B2IVector & rVec)74cdf0e10cSrcweir B2IVector(const B2IVector& rVec) 75cdf0e10cSrcweir : B2ITuple(rVec) 76cdf0e10cSrcweir {} 77cdf0e10cSrcweir 78cdf0e10cSrcweir /** constructor with tuple to allow copy-constructing 79cdf0e10cSrcweir from B2ITuple-based classes 80cdf0e10cSrcweir */ B2IVector(const::basegfx::B2ITuple & rTuple)81cdf0e10cSrcweir B2IVector(const ::basegfx::B2ITuple& rTuple) 82cdf0e10cSrcweir : B2ITuple(rTuple) 83cdf0e10cSrcweir {} 84cdf0e10cSrcweir ~B2IVector()85cdf0e10cSrcweir ~B2IVector() 86cdf0e10cSrcweir {} 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** *=operator to allow usage from B2IVector, too 89cdf0e10cSrcweir */ operator *=(const B2IVector & rPnt)90cdf0e10cSrcweir B2IVector& operator*=( const B2IVector& rPnt ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir mnX *= rPnt.mnX; 93cdf0e10cSrcweir mnY *= rPnt.mnY; 94cdf0e10cSrcweir return *this; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** *=operator to allow usage from B2IVector, too 98cdf0e10cSrcweir */ operator *=(sal_Int32 t)99cdf0e10cSrcweir B2IVector& operator*=(sal_Int32 t) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir mnX *= t; 102cdf0e10cSrcweir mnY *= t; 103cdf0e10cSrcweir return *this; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir /** assignment operator to allow assigning the results 107cdf0e10cSrcweir of B2ITuple calculations 108cdf0e10cSrcweir */ 109cdf0e10cSrcweir B2IVector& operator=( const ::basegfx::B2ITuple& rVec ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir /** Calculate the length of this 2D Vector 112cdf0e10cSrcweir 113cdf0e10cSrcweir @return The Length of the 2D Vector 114cdf0e10cSrcweir */ 115cdf0e10cSrcweir double getLength() const; 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** Set the length of this 2D Vector 118cdf0e10cSrcweir 119cdf0e10cSrcweir @param fLen 120cdf0e10cSrcweir The to be achieved length of the 2D Vector 121cdf0e10cSrcweir */ 122cdf0e10cSrcweir B2IVector& setLength(double fLen); 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** Calculate the Scalar with another 2D Vector 125cdf0e10cSrcweir 126cdf0e10cSrcweir @param rVec 127cdf0e10cSrcweir The second 2D Vector 128cdf0e10cSrcweir 129cdf0e10cSrcweir @return 130cdf0e10cSrcweir The Scalar value of the two involved 2D Vectors 131cdf0e10cSrcweir */ 132cdf0e10cSrcweir double scalar( const B2IVector& rVec ) const; 133cdf0e10cSrcweir 134cdf0e10cSrcweir /** Calculate the length of the cross product with another 2D Vector 135cdf0e10cSrcweir 136cdf0e10cSrcweir In 2D, returning an actual vector does not make much 137cdf0e10cSrcweir sense here. The magnitude, although, can be readily 138cdf0e10cSrcweir used for tasks such as angle calculations, since for 139cdf0e10cSrcweir the returned value, the following equation holds: 140cdf0e10cSrcweir retVal = getLength(this)*getLength(rVec)*sin(theta), 141cdf0e10cSrcweir with theta being the angle between the two vectors. 142cdf0e10cSrcweir 143cdf0e10cSrcweir @param rVec 144cdf0e10cSrcweir The second 2D Vector 145cdf0e10cSrcweir 146cdf0e10cSrcweir @return 147cdf0e10cSrcweir The length of the cross product of the two involved 2D Vectors 148cdf0e10cSrcweir */ 149cdf0e10cSrcweir double cross( const B2IVector& rVec ) const; 150cdf0e10cSrcweir 151cdf0e10cSrcweir /** Calculate the Angle with another 2D Vector 152cdf0e10cSrcweir 153cdf0e10cSrcweir @param rVec 154cdf0e10cSrcweir The second 2D Vector 155cdf0e10cSrcweir 156cdf0e10cSrcweir @return 157cdf0e10cSrcweir The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2 158cdf0e10cSrcweir */ 159cdf0e10cSrcweir double angle( const B2IVector& rVec ) const; 160cdf0e10cSrcweir 161cdf0e10cSrcweir /** Transform vector by given transformation matrix. 162cdf0e10cSrcweir 163cdf0e10cSrcweir Since this is a vector, translational components of the 164cdf0e10cSrcweir matrix are disregarded. 165cdf0e10cSrcweir */ 166cdf0e10cSrcweir B2IVector& operator*=( const B2DHomMatrix& rMat ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir static const B2IVector& getEmptyVector(); 169cdf0e10cSrcweir }; 170cdf0e10cSrcweir 171cdf0e10cSrcweir // external operators 172cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 173cdf0e10cSrcweir 174cdf0e10cSrcweir /** Calculate the orientation to another 2D Vector 175cdf0e10cSrcweir 176cdf0e10cSrcweir @param rVecA 177cdf0e10cSrcweir The first 2D Vector 178cdf0e10cSrcweir 179cdf0e10cSrcweir @param rVecB 180cdf0e10cSrcweir The second 2D Vector 181cdf0e10cSrcweir 182cdf0e10cSrcweir @return 183cdf0e10cSrcweir The mathematical Orientation of the two involved 2D Vectors 184cdf0e10cSrcweir */ 185*b63233d8Sdamjan BASEGFX_DLLPUBLIC B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir /** Calculate a perpendicular 2D Vector to the given one 188cdf0e10cSrcweir 189cdf0e10cSrcweir @param rVec 190cdf0e10cSrcweir The source 2D Vector 191cdf0e10cSrcweir 192cdf0e10cSrcweir @return 193cdf0e10cSrcweir A 2D Vector perpendicular to the one given in parameter rVec 194cdf0e10cSrcweir */ 195*b63233d8Sdamjan BASEGFX_DLLPUBLIC B2IVector getPerpendicular( const B2IVector& rVec ); 196cdf0e10cSrcweir 197cdf0e10cSrcweir /** Test two vectors which need not to be normalized for parallelism 198cdf0e10cSrcweir 199cdf0e10cSrcweir @param rVecA 200cdf0e10cSrcweir The first 2D Vector 201cdf0e10cSrcweir 202cdf0e10cSrcweir @param rVecB 203cdf0e10cSrcweir The second 2D Vector 204cdf0e10cSrcweir 205cdf0e10cSrcweir @return 206cdf0e10cSrcweir bool if the two values are parallel. Also true if 207cdf0e10cSrcweir one of the vectors is empty. 208cdf0e10cSrcweir */ 209*b63233d8Sdamjan BASEGFX_DLLPUBLIC bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir /** Transform vector by given transformation matrix. 212cdf0e10cSrcweir 213cdf0e10cSrcweir Since this is a vector, translational components of the 214cdf0e10cSrcweir matrix are disregarded. 215cdf0e10cSrcweir */ 216*b63233d8Sdamjan BASEGFX_DLLPUBLIC B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir /** Test continuity between given vectors. 219cdf0e10cSrcweir 220cdf0e10cSrcweir The two given vectors are assumed to describe control points on a 221cdf0e10cSrcweir common point. Calculate if there is a continuity between them. 222cdf0e10cSrcweir */ 223*b63233d8Sdamjan BASEGFX_DLLPUBLIC B2VectorContinuity getContinuity( const B2IVector& rBackVector, const B2IVector& rForwardVector ); 224cdf0e10cSrcweir 225cdf0e10cSrcweir } // end of namespace basegfx 226cdf0e10cSrcweir 227cdf0e10cSrcweir #endif /* _BGFX_VECTOR_B2IVECTOR_HXX */ 228