xref: /trunk/main/basegfx/source/point/b2ipoint.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/b2ipoint.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <basegfx/numeric/ftools.hxx>
33 
34 namespace basegfx
35 {
36     B2IPoint& B2IPoint::operator=( const ::basegfx::B2ITuple& rPoint )
37     {
38         mnX = rPoint.getX();
39         mnY = rPoint.getY();
40         return *this;
41     }
42 
43     B2IPoint& B2IPoint::operator*=( const ::basegfx::B2DHomMatrix& rMat )
44     {
45         double fTempX(
46             rMat.get(0, 0) * mnX +
47             rMat.get(0, 1) * mnY +
48             rMat.get(0, 2));
49         double fTempY(
50             rMat.get(1, 0) * mnX +
51             rMat.get(1, 1) * mnY +
52             rMat.get(1, 2));
53 
54         if(!rMat.isLastLineDefault())
55         {
56             const double fOne(1.0);
57             const double fTempM(
58                 rMat.get(2, 0) * mnX +
59                 rMat.get(2, 1) * mnY +
60                 rMat.get(2, 2));
61 
62             if(!fTools::equalZero(fTempM) && !fTools::equal(fOne, fTempM))
63             {
64                 fTempX /= fTempM;
65                 fTempY /= fTempM;
66             }
67         }
68 
69         mnX = fround(fTempX);
70         mnY = fround(fTempY);
71 
72         return *this;
73     }
74 } // end of namespace basegfx
75 
76 // eof
77