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