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: b2dhompoint.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/point/b2dhompoint.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <basegfx/numeric/ftools.hxx>
39 bool B2DHomPoint::implIsHomogenized() const
41 const double fOne(1.0);
42 return ::basegfx::fTools::equal(fOne
, mfW
);
45 void B2DHomPoint::implHomogenize()
47 const double fFactor(1.0 / mfW
);
48 maTuple
.setX(maTuple
.getX() * fFactor
);
49 maTuple
.setY(maTuple
.getY() * fFactor
);
53 void B2DHomPoint::implTestAndHomogenize() const
55 if(!implIsHomogenized())
56 ((B2DHomPoint
*)this)->implHomogenize();
59 B2DPoint
B2DHomPoint::getB2DPoint() const
61 implTestAndHomogenize();
62 return B2DPoint(maTuple
.getX(), maTuple
.getY());
65 double B2DHomPoint::getX() const
67 implTestAndHomogenize();
68 return maTuple
.getX();
71 double B2DHomPoint::getY() const
73 implTestAndHomogenize();
74 return maTuple
.getY();
77 void B2DHomPoint::setX(double fX
)
79 maTuple
.setX(implIsHomogenized() ? fX
: fX
* mfW
);
82 void B2DHomPoint::setY(double fY
)
84 maTuple
.setY(implIsHomogenized() ? fY
: fY
* mfW
);
87 B2DHomPoint
& B2DHomPoint::operator+=( const B2DHomPoint
& rPnt
)
89 maTuple
.setX(getX() * rPnt
.mfW
+ rPnt
.getX() * mfW
);
90 maTuple
.setY(getY() * rPnt
.mfW
+ rPnt
.getY() * mfW
);
96 B2DHomPoint
& B2DHomPoint::operator-=( const B2DHomPoint
& rPnt
)
98 maTuple
.setX(getX() * rPnt
.mfW
- rPnt
.getX() * mfW
);
99 maTuple
.setY(getY() * rPnt
.mfW
- rPnt
.getY() * mfW
);
100 mfW
= mfW
* rPnt
.mfW
;
105 B2DHomPoint
& B2DHomPoint::operator*=(double t
)
107 if(!::basegfx::fTools::equalZero(t
))
115 B2DHomPoint
& B2DHomPoint::operator*=( const B2DHomMatrix
& rMat
)
117 const double fTempX( rMat
.get(0,0)*maTuple
.getX() +
118 rMat
.get(0,1)*maTuple
.getY() +
121 const double fTempY( rMat
.get(1,0)*maTuple
.getX() +
122 rMat
.get(1,1)*maTuple
.getY() +
125 const double fTempZ( rMat
.get(2,0)*maTuple
.getX() +
126 rMat
.get(2,1)*maTuple
.getY() +
128 maTuple
.setX( fTempX
);
129 maTuple
.setY( fTempY
);
135 B2DHomPoint
& B2DHomPoint::operator/=(double t
)
141 B2DHomPoint
& B2DHomPoint::operator-(void)
147 bool B2DHomPoint::operator==( const B2DHomPoint
& rPnt
) const
149 implTestAndHomogenize();
150 return (maTuple
== rPnt
.maTuple
);
153 bool B2DHomPoint::operator!=( const B2DHomPoint
& rPnt
) const
155 implTestAndHomogenize();
156 return (maTuple
!= rPnt
.maTuple
);
159 B2DHomPoint
& B2DHomPoint::operator=( const B2DHomPoint
& rPnt
)
161 maTuple
= rPnt
.maTuple
;
166 B2DHomPoint
minimum(const B2DHomPoint
& rVecA
, const B2DHomPoint
& rVecB
)
169 (rVecB
.getX() < rVecA
.getX()) ? rVecB
.getX() : rVecA
.getX(),
170 (rVecB
.getY() < rVecA
.getY()) ? rVecB
.getY() : rVecA
.getY());
174 B2DHomPoint
maximum(const B2DHomPoint
& rVecA
, const B2DHomPoint
& rVecB
)
177 (rVecB
.getX() > rVecA
.getX()) ? rVecB
.getX() : rVecA
.getX(),
178 (rVecB
.getY() > rVecA
.getY()) ? rVecB
.getY() : rVecA
.getY());
181 B2DHomPoint
absolute(const B2DHomPoint
& rVec
)
184 (0.0 > rVec
.getX()) ? -rVec
.getX() : rVec
.getX(),
185 (0.0 > rVec
.getY()) ? -rVec
.getY() : rVec
.getY());
189 B2DHomPoint
interpolate(B2DHomPoint
& rOld1
, B2DHomPoint
& rOld2
, double t
)
192 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
193 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY());
197 B2DHomPoint
average(B2DHomPoint
& rOld1
, B2DHomPoint
& rOld2
)
200 (rOld1
.getX() + rOld2
.getX()) * 0.5,
201 (rOld1
.getY() + rOld2
.getY()) * 0.5);
205 B2DHomPoint
average(B2DHomPoint
& rOld1
, B2DHomPoint
& rOld2
, B2DHomPoint
& rOld3
)
208 (rOld1
.getX() + rOld2
.getX() + rOld3
.getX()) * (1.0 / 3.0),
209 (rOld1
.getY() + rOld2
.getY() + rOld3
.getY()) * (1.0 / 3.0));
213 B2DHomPoint
operator+(const B2DHomPoint
& rVecA
, const B2DHomPoint
& rVecB
)
215 B2DHomPoint
aSum(rVecA
);
220 B2DHomPoint
operator-(const B2DHomPoint
& rVecA
, const B2DHomPoint
& rVecB
)
222 B2DHomPoint
aSub(rVecA
);
227 B2DHomPoint
operator*(const B2DHomPoint
& rVec
, double t
)
229 B2DHomPoint
aNew(rVec
);
234 B2DHomPoint
operator*(double t
, const B2DHomPoint
& rVec
)
236 B2DHomPoint
aNew(rVec
);
241 B2DHomPoint
operator*( const B2DHomMatrix
& rMat
, const B2DHomPoint
& rPoint
)
243 B2DHomPoint
aNew(rPoint
);
247 B2DHomPoint
operator/(const B2DHomPoint
& rVec
, double t
)
249 B2DHomPoint
aNew(rVec
);
254 B2DHomPoint
operator/(double t
, const B2DHomPoint
& rVec
)
256 B2DHomPoint
aNew(rVec
);
260 } // end of namespace basegfx