LibreOffice Module tools (master) 1
point.cxx
Go to the documentation of this file.
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 <tools/gen.hxx>
21
23 Degree10 nOrientation ) const
24{
25 tools::Long nX = rPoint.X();
26 tools::Long nY = rPoint.Y();
27 RotateAround(nX, nY, nOrientation);
28 rPoint.setX(nX);
29 rPoint.setY(nY);
30}
31
33 Degree10 nOrientation ) const
34{
35 const tools::Long nOriginX = X();
36 const tools::Long nOriginY = Y();
37
38 if ( (nOrientation >= 0_deg10) && !(nOrientation % 900_deg10) )
39 {
40 if ( nOrientation >= 3600_deg10 )
41 nOrientation %= 3600_deg10;
42
43 if ( nOrientation )
44 {
45 rX -= nOriginX;
46 rY -= nOriginY;
47
48 if ( nOrientation == 900_deg10 )
49 {
50 tools::Long nTemp = rX;
51 rX = rY;
52 rY = -nTemp;
53 }
54 else if ( nOrientation == 1800_deg10 )
55 {
56 rX = -rX;
57 rY = -rY;
58 }
59 else /* ( nOrientation == 2700 ) */
60 {
61 tools::Long nTemp = rX;
62 rX = -rY;
63 rY = nTemp;
64 }
65
66 rX += nOriginX;
67 rY += nOriginY;
68 }
69 }
70 else
71 {
72 double nRealOrientation = toRadians(nOrientation);
73 double nCos = cos( nRealOrientation );
74 double nSin = sin( nRealOrientation );
75
76 // Translation...
77 tools::Long nX = rX-nOriginX;
78 tools::Long nY = rY-nOriginY;
79
80 // Rotation...
81 rX = + static_cast<tools::Long>(nCos*nX + nSin*nY) + nOriginX;
82 rY = - static_cast<tools::Long>(nSin*nX - nCos*nY) + nOriginY;
83 }
84}
85
86/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: gen.hxx:78
constexpr tools::Long Y() const
Definition: gen.hxx:84
void setX(tools::Long nX)
Definition: gen.hxx:107
void RotateAround(tools::Long &rX, tools::Long &rY, Degree10 nOrientation) const
Definition: point.cxx:32
void setY(tools::Long nY)
Definition: gen.hxx:108
constexpr tools::Long X() const
Definition: gen.hxx:83
double toRadians(D x)
Definition: degree.hxx:57
long Long
Definition: long.hxx:34