Avoid potential negative array index access to cached text.
[LibreOffice.git] / tools / source / generic / point.cxx
blobe71f60411a866021914b649541578b21bab43b23
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>
22 void PointTemplateBase::RotateAround( PointTemplateBase& rPoint,
23 Degree10 nOrientation ) const
25 tools::Long nX = rPoint.mnA;
26 tools::Long nY = rPoint.mnB;
27 RotateAround(nX, nY, nOrientation);
28 rPoint.mnA = nX;
29 rPoint.mnB = nY;
32 void PointTemplateBase::RotateAround( tools::Long& rX, tools::Long& rY,
33 Degree10 nOrientation ) const
35 const tools::Long nOriginX = mnA;
36 const tools::Long nOriginY = mnB;
38 if ( (nOrientation >= 0_deg10) && !(nOrientation % 900_deg10) )
40 if ( nOrientation >= 3600_deg10 )
41 nOrientation %= 3600_deg10;
43 if ( nOrientation )
45 rX -= nOriginX;
46 rY -= nOriginY;
48 if ( nOrientation == 900_deg10 )
50 tools::Long nTemp = rX;
51 rX = rY;
52 rY = -nTemp;
54 else if ( nOrientation == 1800_deg10 )
56 rX = -rX;
57 rY = -rY;
59 else /* ( nOrientation == 2700 ) */
61 tools::Long nTemp = rX;
62 rX = -rY;
63 rY = nTemp;
66 rX += nOriginX;
67 rY += nOriginY;
70 else
72 double nRealOrientation = toRadians(nOrientation);
73 double nCos = cos( nRealOrientation );
74 double nSin = sin( nRealOrientation );
76 // Translation...
77 tools::Long nX = rX-nOriginX;
78 tools::Long nY = rY-nOriginY;
80 // Rotation...
81 rX = + static_cast<tools::Long>(nCos*nX + nSin*nY) + nOriginX;
82 rY = - static_cast<tools::Long>(nSin*nX - nCos*nY) + nOriginY;
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */