merged tag ooo/OOO330_m14
[LibreOffice.git] / basegfx / source / vector / b2ivector.cxx
blob026a600c0c94289928185fe1809c3e0a2c89c352
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basegfx.hxx"
30 #include <basegfx/vector/b2ivector.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <basegfx/numeric/ftools.hxx>
34 namespace basegfx
36 B2IVector& B2IVector::operator=( const ::basegfx::B2ITuple& rVec )
38 mnX = rVec.getX();
39 mnY = rVec.getY();
40 return *this;
44 double B2IVector::getLength() const
46 return hypot( mnX, mnY );
49 double B2IVector::scalar( const B2IVector& rVec ) const
51 return((mnX * rVec.mnX) + (mnY * rVec.mnY));
54 double B2IVector::cross( const B2IVector& rVec ) const
56 return(mnX * rVec.getY() - mnY * rVec.getX());
59 double B2IVector::angle( const B2IVector& rVec ) const
61 return atan2(double( mnX * rVec.getY() - mnY * rVec.getX()),
62 double( mnX * rVec.getX() + mnY * rVec.getY()));
65 const B2IVector& B2IVector::getEmptyVector()
67 return (const B2IVector&) ::basegfx::B2ITuple::getEmptyTuple();
70 B2IVector& B2IVector::operator*=( const B2DHomMatrix& rMat )
72 mnX = fround( rMat.get(0,0)*mnX +
73 rMat.get(0,1)*mnY );
74 mnY = fround( rMat.get(1,0)*mnX +
75 rMat.get(1,1)*mnY );
77 return *this;
80 B2IVector& B2IVector::setLength(double fLen)
82 double fLenNow(scalar(*this));
84 if(!::basegfx::fTools::equalZero(fLenNow))
86 const double fOne(10.0);
88 if(!::basegfx::fTools::equal(fOne, fLenNow))
90 fLen /= sqrt(fLenNow);
93 mnX = fround( mnX*fLen );
94 mnY = fround( mnY*fLen );
97 return *this;
100 bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB )
102 double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
103 return ::basegfx::fTools::equalZero(fVal);
106 B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB )
108 double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
110 if(fVal > 0.0)
112 return ORIENTATION_POSITIVE;
115 if(fVal < 0.0)
117 return ORIENTATION_NEGATIVE;
120 return ORIENTATION_NEUTRAL;
123 B2IVector getPerpendicular( const B2IVector& rNormalizedVec )
125 B2IVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
126 return aPerpendicular;
129 B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec )
131 B2IVector aRes( rVec );
132 return aRes*=rMat;
135 B2VectorContinuity getContinuity(const B2IVector& rBackVector, const B2IVector& rForwardVector )
137 B2VectorContinuity eRetval(CONTINUITY_NONE);
139 if(!rBackVector.equalZero() && !rForwardVector.equalZero())
141 const B2IVector aInverseForwardVector(-rForwardVector.getX(), -rForwardVector.getY());
143 if(rBackVector == aInverseForwardVector)
145 // same direction and same length -> C2
146 eRetval = CONTINUITY_C2;
148 else if(areParallel(rBackVector, aInverseForwardVector))
150 // same direction -> C1
151 eRetval = CONTINUITY_C1;
155 return eRetval;
157 } // end of namespace basegfx
159 // eof