xref: /trunk/main/basegfx/source/point/b2dpoint.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basegfx.hxx"
30 #include <basegfx/point/b2dpoint.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <basegfx/numeric/ftools.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace basegfx
37 {
38     B2DPoint& B2DPoint::operator=( const ::basegfx::B2DTuple& rPoint )
39     {
40         mfX = rPoint.getX();
41         mfY = rPoint.getY();
42         return *this;
43     }
44 
45     B2DPoint& B2DPoint::operator*=( const ::basegfx::B2DHomMatrix& rMat )
46     {
47         double fTempX(
48             rMat.get(0, 0) * mfX +
49             rMat.get(0, 1) * mfY +
50             rMat.get(0, 2));
51         double fTempY(
52             rMat.get(1, 0) * mfX +
53             rMat.get(1, 1) * mfY +
54             rMat.get(1, 2));
55 
56         if(!rMat.isLastLineDefault())
57         {
58             const double fOne(1.0);
59             const double fTempM(
60                 rMat.get(2, 0) * mfX +
61                 rMat.get(2, 1) * mfY +
62                 rMat.get(2, 2));
63 
64             if(!fTools::equalZero(fTempM) && !fTools::equal(fOne, fTempM))
65             {
66                 fTempX /= fTempM;
67                 fTempY /= fTempM;
68             }
69         }
70 
71         mfX = fTempX;
72         mfY = fTempY;
73 
74         return *this;
75     }
76 
77     B2DPoint operator*( const ::basegfx::B2DHomMatrix& rMat, const B2DPoint& rPoint )
78     {
79         B2DPoint aRes( rPoint );
80         return aRes *= rMat;
81     }
82 } // end of namespace basegfx
83 
84 //////////////////////////////////////////////////////////////////////////////
85 // eof
86