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