1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <Linear3DTransformation.hxx>
22 using namespace ::com::sun::star
;
24 using ::com::sun::star::uno::Sequence
;
29 Linear3DTransformation::Linear3DTransformation( const drawing::HomogenMatrix
& rHomMatrix
, bool bSwapXAndY
)
30 : m_Matrix(rHomMatrix
)
31 , m_bSwapXAndY(bSwapXAndY
)
34 Linear3DTransformation::~Linear3DTransformation()
37 // ____ XTransformation2 ____
38 css::drawing::Position3D
Linear3DTransformation::transform(
39 const Sequence
< double >& rSourceValues
) const
41 double fX
= rSourceValues
[0];
42 double fY
= rSourceValues
[1];
43 double fZ
= rSourceValues
[2];
46 css::drawing::Position3D aNewVec
;
49 fZwi
= m_Matrix
.Line1
.Column1
* fX
50 + m_Matrix
.Line1
.Column2
* fY
51 + m_Matrix
.Line1
.Column3
* fZ
52 + m_Matrix
.Line1
.Column4
;
53 aNewVec
.PositionX
= fZwi
;
55 fZwi
= m_Matrix
.Line2
.Column1
* fX
56 + m_Matrix
.Line2
.Column2
* fY
57 + m_Matrix
.Line2
.Column3
* fZ
58 + m_Matrix
.Line2
.Column4
;
59 aNewVec
.PositionY
= fZwi
;
61 fZwi
= m_Matrix
.Line3
.Column1
* fX
62 + m_Matrix
.Line3
.Column2
* fY
63 + m_Matrix
.Line3
.Column3
* fZ
64 + m_Matrix
.Line3
.Column4
;
65 aNewVec
.PositionZ
= fZwi
;
67 fZwi
= m_Matrix
.Line4
.Column1
* fX
68 + m_Matrix
.Line4
.Column2
* fY
69 + m_Matrix
.Line4
.Column3
* fZ
70 + m_Matrix
.Line4
.Column4
;
71 if(fZwi
!= 1.0 && fZwi
!= 0.0)
73 aNewVec
.PositionX
/= fZwi
;
74 aNewVec
.PositionY
/= fZwi
;
75 aNewVec
.PositionZ
/= fZwi
;
80 css::drawing::Position3D
Linear3DTransformation::transform(
81 const css::drawing::Position3D
& rSourceValues
) const
83 double fX
= rSourceValues
.PositionX
;
84 double fY
= rSourceValues
.PositionY
;
85 double fZ
= rSourceValues
.PositionZ
;
88 css::drawing::Position3D aNewVec
;
91 fZwi
= m_Matrix
.Line1
.Column1
* fX
92 + m_Matrix
.Line1
.Column2
* fY
93 + m_Matrix
.Line1
.Column3
* fZ
94 + m_Matrix
.Line1
.Column4
;
95 aNewVec
.PositionX
= fZwi
;
97 fZwi
= m_Matrix
.Line2
.Column1
* fX
98 + m_Matrix
.Line2
.Column2
* fY
99 + m_Matrix
.Line2
.Column3
* fZ
100 + m_Matrix
.Line2
.Column4
;
101 aNewVec
.PositionY
= fZwi
;
103 fZwi
= m_Matrix
.Line3
.Column1
* fX
104 + m_Matrix
.Line3
.Column2
* fY
105 + m_Matrix
.Line3
.Column3
* fZ
106 + m_Matrix
.Line3
.Column4
;
107 aNewVec
.PositionZ
= fZwi
;
109 fZwi
= m_Matrix
.Line4
.Column1
* fX
110 + m_Matrix
.Line4
.Column2
* fY
111 + m_Matrix
.Line4
.Column3
* fZ
112 + m_Matrix
.Line4
.Column4
;
113 if(fZwi
!= 1.0 && fZwi
!= 0.0)
115 aNewVec
.PositionX
/= fZwi
;
116 aNewVec
.PositionY
/= fZwi
;
117 aNewVec
.PositionZ
/= fZwi
;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */