1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b2ivector.cxx,v $
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>
39 B2IVector
& B2IVector::operator=( const ::basegfx::B2ITuple
& rVec
)
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
+
77 mnY
= fround( rMat
.get(1,0)*mnX
+
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
);
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());
115 return ORIENTATION_POSITIVE
;
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
);
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
;
160 } // end of namespace basegfx