Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <numeric>
21 :
22 : #include <tools/gen.hxx>
23 : #include <basegfx/numeric/ftools.hxx>
24 :
25 129816 : void Point::RotateAround( long& rX, long& rY,
26 : short nOrientation ) const
27 : {
28 129816 : const long nOriginX = X();
29 129816 : const long nOriginY = Y();
30 :
31 129816 : if ( (nOrientation >= 0) && !(nOrientation % 900) )
32 : {
33 17861 : if ( (nOrientation >= 3600) )
34 0 : nOrientation %= 3600;
35 :
36 17861 : if ( nOrientation )
37 : {
38 17861 : rX -= nOriginX;
39 17861 : rY -= nOriginY;
40 :
41 17861 : if ( nOrientation == 900 )
42 : {
43 14793 : long nTemp = rX;
44 14793 : rX = rY;
45 14793 : rY = -nTemp;
46 : }
47 3068 : else if ( nOrientation == 1800 )
48 : {
49 0 : rX = -rX;
50 0 : rY = -rY;
51 : }
52 : else /* ( nOrientation == 2700 ) */
53 : {
54 3068 : long nTemp = rX;
55 3068 : rX = -rY;
56 3068 : rY = nTemp;
57 : }
58 :
59 17861 : rX += nOriginX;
60 17861 : rY += nOriginY;
61 17861 : }
62 : }
63 : else
64 : {
65 111955 : double nRealOrientation = nOrientation*F_PI1800;
66 111955 : double nCos = cos( nRealOrientation );
67 111955 : double nSin = sin( nRealOrientation );
68 :
69 : // Translation...
70 111955 : long nX = rX-nOriginX;
71 111955 : long nY = rY-nOriginY;
72 :
73 : // Rotation...
74 111955 : rX = +((long)(nCos*nX + nSin*nY)) + nOriginX;
75 111955 : rY = -((long)(nSin*nX - nCos*nY)) + nOriginY;
76 : }
77 129816 : }
78 :
79 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|