Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/tools/source/generic/point.cxx
Line
Count
Source
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
22
void PointTemplateBase::RotateAround( PointTemplateBase& rPoint,
23
                          Degree10 nOrientation ) const
24
3.32M
{
25
3.32M
    tools::Long nX = rPoint.mnA;
26
3.32M
    tools::Long nY = rPoint.mnB;
27
3.32M
    RotateAround(nX, nY, nOrientation);
28
3.32M
    rPoint.mnA = nX;
29
3.32M
    rPoint.mnB = nY;
30
3.32M
}
31
32
void PointTemplateBase::RotateAround( tools::Long& rX, tools::Long& rY,
33
                          Degree10 nOrientation ) const
34
4.01M
{
35
4.01M
    const tools::Long nOriginX = mnA;
36
4.01M
    const tools::Long nOriginY = mnB;
37
38
4.01M
    if ( (nOrientation >= 0_deg10) && !(nOrientation % 900_deg10) )
39
22.6k
    {
40
22.6k
        if ( nOrientation >= 3600_deg10 )
41
632
            nOrientation %= 3600_deg10;
42
43
22.6k
        if ( nOrientation )
44
19.4k
        {
45
19.4k
            rX -= nOriginX;
46
19.4k
            rY -= nOriginY;
47
48
19.4k
            if ( nOrientation == 900_deg10 )
49
2.51k
            {
50
2.51k
                tools::Long nTemp = rX;
51
2.51k
                rX = rY;
52
2.51k
                rY = -nTemp;
53
2.51k
            }
54
16.9k
            else if ( nOrientation == 1800_deg10 )
55
3.15k
            {
56
3.15k
                rX = -rX;
57
3.15k
                rY = -rY;
58
3.15k
            }
59
13.8k
            else /* ( nOrientation == 2700 ) */
60
13.8k
            {
61
13.8k
                tools::Long nTemp = rX;
62
13.8k
                rX = -rY;
63
13.8k
                rY = nTemp;
64
13.8k
            }
65
66
19.4k
            rX += nOriginX;
67
19.4k
            rY += nOriginY;
68
19.4k
        }
69
22.6k
    }
70
3.99M
    else
71
3.99M
    {
72
3.99M
        double nRealOrientation = toRadians(nOrientation);
73
3.99M
        double nCos = cos( nRealOrientation );
74
3.99M
        double nSin = sin( nRealOrientation );
75
76
        // Translation...
77
3.99M
        tools::Long nX = rX-nOriginX;
78
3.99M
        tools::Long nY = rY-nOriginY;
79
80
        // Rotation...
81
3.99M
        rX = + static_cast<tools::Long>(nCos*nX + nSin*nY) + nOriginX;
82
3.99M
        rY = - static_cast<tools::Long>(nSin*nX - nCos*nY) + nOriginY;
83
3.99M
    }
84
4.01M
}
85
86
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */