Bump version to 6.4-15
[LibreOffice.git] / tools / source / generic / point.cxx
blobf33fe9a28803502b1c0df2a240523677c9fab78f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/gen.hxx>
21 #include <basegfx/numeric/ftools.hxx>
23 void Point::RotateAround( Point& rPoint,
24 short nOrientation ) const
26 long nX = rPoint.X();
27 long nY = rPoint.Y();
28 RotateAround(nX, nY, nOrientation);
29 rPoint.setX(nX);
30 rPoint.setY(nY);
33 void Point::RotateAround( long& rX, long& rY,
34 short nOrientation ) const
36 const long nOriginX = X();
37 const long nOriginY = Y();
39 if ( (nOrientation >= 0) && !(nOrientation % 900) )
41 if ( nOrientation >= 3600 )
42 nOrientation %= 3600;
44 if ( nOrientation )
46 rX -= nOriginX;
47 rY -= nOriginY;
49 if ( nOrientation == 900 )
51 long nTemp = rX;
52 rX = rY;
53 rY = -nTemp;
55 else if ( nOrientation == 1800 )
57 rX = -rX;
58 rY = -rY;
60 else /* ( nOrientation == 2700 ) */
62 long nTemp = rX;
63 rX = -rY;
64 rY = nTemp;
67 rX += nOriginX;
68 rY += nOriginY;
71 else
73 double nRealOrientation = nOrientation*F_PI1800;
74 double nCos = cos( nRealOrientation );
75 double nSin = sin( nRealOrientation );
77 // Translation...
78 long nX = rX-nOriginX;
79 long nY = rY-nOriginY;
81 // Rotation...
82 rX = + static_cast<long>(nCos*nX + nSin*nY) + nOriginX;
83 rY = - static_cast<long>(nSin*nX - nCos*nY) + nOriginY;
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */