109dbbe93SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 309dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 409dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file 509dbbe93SAndrew Rist * distributed with this work for additional information 609dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file 709dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the 809dbbe93SAndrew Rist * "License"); you may not use this file except in compliance 909dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1109dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1309dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing, 1409dbbe93SAndrew Rist * software distributed under the License is distributed on an 1509dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1609dbbe93SAndrew Rist * KIND, either express or implied. See the License for the 1709dbbe93SAndrew Rist * specific language governing permissions and limitations 1809dbbe93SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2009dbbe93SAndrew Rist *************************************************************/ 2109dbbe93SAndrew Rist 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 24cdf0e10cSrcweir #include <basegfx/vector/b2ivector.hxx> 25cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 26cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir namespace basegfx 29cdf0e10cSrcweir { operator =(const::basegfx::B2ITuple & rVec)30cdf0e10cSrcweir B2IVector& B2IVector::operator=( const ::basegfx::B2ITuple& rVec ) 31cdf0e10cSrcweir { 32cdf0e10cSrcweir mnX = rVec.getX(); 33cdf0e10cSrcweir mnY = rVec.getY(); 34cdf0e10cSrcweir return *this; 35cdf0e10cSrcweir } 36cdf0e10cSrcweir getLength() const37cdf0e10cSrcweir double B2IVector::getLength() const 38cdf0e10cSrcweir { 39cdf0e10cSrcweir return hypot( mnX, mnY ); 40cdf0e10cSrcweir } 41cdf0e10cSrcweir scalar(const B2IVector & rVec) const42cdf0e10cSrcweir double B2IVector::scalar( const B2IVector& rVec ) const 43cdf0e10cSrcweir { 44cdf0e10cSrcweir return((mnX * rVec.mnX) + (mnY * rVec.mnY)); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir cross(const B2IVector & rVec) const47cdf0e10cSrcweir double B2IVector::cross( const B2IVector& rVec ) const 48cdf0e10cSrcweir { 49cdf0e10cSrcweir return(mnX * rVec.getY() - mnY * rVec.getX()); 50cdf0e10cSrcweir } 51cdf0e10cSrcweir angle(const B2IVector & rVec) const52cdf0e10cSrcweir double B2IVector::angle( const B2IVector& rVec ) const 53cdf0e10cSrcweir { 54cdf0e10cSrcweir return atan2(double( mnX * rVec.getY() - mnY * rVec.getX()), 55cdf0e10cSrcweir double( mnX * rVec.getX() + mnY * rVec.getY())); 56cdf0e10cSrcweir } 57cdf0e10cSrcweir getEmptyVector()58cdf0e10cSrcweir const B2IVector& B2IVector::getEmptyVector() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir return (const B2IVector&) ::basegfx::B2ITuple::getEmptyTuple(); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir operator *=(const B2DHomMatrix & rMat)63cdf0e10cSrcweir B2IVector& B2IVector::operator*=( const B2DHomMatrix& rMat ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir mnX = fround( rMat.get(0,0)*mnX + 66cdf0e10cSrcweir rMat.get(0,1)*mnY ); 67cdf0e10cSrcweir mnY = fround( rMat.get(1,0)*mnX + 68cdf0e10cSrcweir rMat.get(1,1)*mnY ); 69cdf0e10cSrcweir 70cdf0e10cSrcweir return *this; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir setLength(double fLen)73cdf0e10cSrcweir B2IVector& B2IVector::setLength(double fLen) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir double fLenNow(scalar(*this)); 76cdf0e10cSrcweir 77cdf0e10cSrcweir if(!::basegfx::fTools::equalZero(fLenNow)) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir const double fOne(10.0); 80cdf0e10cSrcweir 81cdf0e10cSrcweir if(!::basegfx::fTools::equal(fOne, fLenNow)) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir fLen /= sqrt(fLenNow); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir mnX = fround( mnX*fLen ); 87cdf0e10cSrcweir mnY = fround( mnY*fLen ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir return *this; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir areParallel(const B2IVector & rVecA,const B2IVector & rVecB)93cdf0e10cSrcweir bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); 96cdf0e10cSrcweir return ::basegfx::fTools::equalZero(fVal); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir getOrientation(const B2IVector & rVecA,const B2IVector & rVecB)99cdf0e10cSrcweir B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX()); 102cdf0e10cSrcweir 103cdf0e10cSrcweir if(fVal > 0.0) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir return ORIENTATION_POSITIVE; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir if(fVal < 0.0) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir return ORIENTATION_NEGATIVE; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir return ORIENTATION_NEUTRAL; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir getPerpendicular(const B2IVector & rNormalizedVec)116cdf0e10cSrcweir B2IVector getPerpendicular( const B2IVector& rNormalizedVec ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir B2IVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX()); 119cdf0e10cSrcweir return aPerpendicular; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir operator *(const B2DHomMatrix & rMat,const B2IVector & rVec)122cdf0e10cSrcweir B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir B2IVector aRes( rVec ); 125cdf0e10cSrcweir return aRes*=rMat; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir getContinuity(const B2IVector & rBackVector,const B2IVector & rForwardVector)128cdf0e10cSrcweir B2VectorContinuity getContinuity(const B2IVector& rBackVector, const B2IVector& rForwardVector ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir B2VectorContinuity eRetval(CONTINUITY_NONE); 131cdf0e10cSrcweir 132cdf0e10cSrcweir if(!rBackVector.equalZero() && !rForwardVector.equalZero()) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir const B2IVector aInverseForwardVector(-rForwardVector.getX(), -rForwardVector.getY()); 135cdf0e10cSrcweir 136cdf0e10cSrcweir if(rBackVector == aInverseForwardVector) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir // same direction and same length -> C2 139cdf0e10cSrcweir eRetval = CONTINUITY_C2; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir else if(areParallel(rBackVector, aInverseForwardVector)) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir // same direction -> C1 144cdf0e10cSrcweir eRetval = CONTINUITY_C1; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir return eRetval; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } // end of namespace basegfx 151cdf0e10cSrcweir 152*18e39f1bSmseidel /* vim: set noet sw=4 ts=4: */ 153