merge the formfield patch from ooo-build
[ooovba.git] / basegfx / source / vector / b2ivector.cxx
blobbda391f5fe29d8590c0d6eea8a414b578eacc7dc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b2ivector.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basegfx.hxx"
33 #include <basegfx/vector/b2ivector.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <basegfx/numeric/ftools.hxx>
37 namespace basegfx
39 B2IVector& B2IVector::operator=( const ::basegfx::B2ITuple& rVec )
41 mnX = rVec.getX();
42 mnY = rVec.getY();
43 return *this;
47 double B2IVector::getLength() const
49 return hypot( mnX, mnY );
52 double B2IVector::scalar( const B2IVector& rVec ) const
54 return((mnX * rVec.mnX) + (mnY * rVec.mnY));
57 double B2IVector::cross( const B2IVector& rVec ) const
59 return(mnX * rVec.getY() - mnY * rVec.getX());
62 double B2IVector::angle( const B2IVector& rVec ) const
64 return atan2(double( mnX * rVec.getY() - mnY * rVec.getX()),
65 double( mnX * rVec.getX() + mnY * rVec.getY()));
68 const B2IVector& B2IVector::getEmptyVector()
70 return (const B2IVector&) ::basegfx::B2ITuple::getEmptyTuple();
73 B2IVector& B2IVector::operator*=( const B2DHomMatrix& rMat )
75 mnX = fround( rMat.get(0,0)*mnX +
76 rMat.get(0,1)*mnY );
77 mnY = fround( rMat.get(1,0)*mnX +
78 rMat.get(1,1)*mnY );
80 return *this;
83 B2IVector& B2IVector::setLength(double fLen)
85 double fLenNow(scalar(*this));
87 if(!::basegfx::fTools::equalZero(fLenNow))
89 const double fOne(10.0);
91 if(!::basegfx::fTools::equal(fOne, fLenNow))
93 fLen /= sqrt(fLenNow);
96 mnX = fround( mnX*fLen );
97 mnY = fround( mnY*fLen );
100 return *this;
103 bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB )
105 double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
106 return ::basegfx::fTools::equalZero(fVal);
109 B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB )
111 double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
113 if(fVal > 0.0)
115 return ORIENTATION_POSITIVE;
118 if(fVal < 0.0)
120 return ORIENTATION_NEGATIVE;
123 return ORIENTATION_NEUTRAL;
126 B2IVector getPerpendicular( const B2IVector& rNormalizedVec )
128 B2IVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
129 return aPerpendicular;
132 B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec )
134 B2IVector aRes( rVec );
135 return aRes*=rMat;
138 B2VectorContinuity getContinuity(const B2IVector& rBackVector, const B2IVector& rForwardVector )
140 B2VectorContinuity eRetval(CONTINUITY_NONE);
142 if(!rBackVector.equalZero() && !rForwardVector.equalZero())
144 const B2IVector aInverseForwardVector(-rForwardVector.getX(), -rForwardVector.getY());
146 if(rBackVector == aInverseForwardVector)
148 // same direction and same length -> C2
149 eRetval = CONTINUITY_C2;
151 else if(areParallel(rBackVector, aInverseForwardVector))
153 // same direction -> C1
154 eRetval = CONTINUITY_C1;
158 return eRetval;
160 } // end of namespace basegfx
162 // eof