Coverage Report

Created: 2026-07-14 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/MapServer/src/renderers/agg/src/agg_arc.cpp
Line
Count
Source
1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.4
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
//
5
// Permission to copy, use, modify, sell and distribute this software 
6
// is granted provided this copyright notice appears in all copies. 
7
// This software is provided "as is" without express or implied
8
// warranty, and with no claim as to its suitability for any purpose.
9
//
10
//----------------------------------------------------------------------------
11
// Contact: mcseem@antigrain.com
12
//          mcseemagg@yahoo.com
13
//          http://www.antigrain.com
14
//----------------------------------------------------------------------------
15
//
16
// Arc vertex generator
17
//
18
//----------------------------------------------------------------------------
19
20
#include <math.h>
21
#include "../include/agg_arc.h"
22
23
24
namespace mapserver
25
{
26
    //------------------------------------------------------------------------
27
    arc::arc(double x,  double y, 
28
             double rx, double ry, 
29
             double a1, double a2, 
30
             bool ccw) :
31
0
        m_x(x), m_y(y), m_rx(rx), m_ry(ry), m_scale(1.0)
32
0
    {
33
0
        normalize(a1, a2, ccw);
34
0
    }
35
36
    //------------------------------------------------------------------------
37
    void arc::init(double x,  double y, 
38
                   double rx, double ry, 
39
                   double a1, double a2, 
40
                   bool ccw)
41
0
    {
42
0
        m_x   = x;  m_y  = y;
43
0
        m_rx  = rx; m_ry = ry; 
44
0
        normalize(a1, a2, ccw);
45
0
    }
46
    
47
    //------------------------------------------------------------------------
48
    void arc::approximation_scale(double s)
49
0
    {
50
0
        m_scale = s;
51
0
        if(m_initialized)
52
0
        {
53
0
            normalize(m_start, m_end, m_ccw);
54
0
        }
55
0
    }
56
57
    //------------------------------------------------------------------------
58
    void arc::rewind(unsigned)
59
0
    {
60
0
        m_path_cmd = path_cmd_move_to; 
61
0
        m_angle = m_start;
62
0
    }
63
64
    //------------------------------------------------------------------------
65
    unsigned arc::vertex(double* x, double* y)
66
0
    {
67
0
        if(is_stop(m_path_cmd)) return path_cmd_stop;
68
0
        if((m_angle < m_end - m_da/4) != m_ccw)
69
0
        {
70
0
            *x = m_x + cos(m_end) * m_rx;
71
0
            *y = m_y + sin(m_end) * m_ry;
72
0
            m_path_cmd = path_cmd_stop;
73
0
            return path_cmd_line_to;
74
0
        }
75
76
0
        *x = m_x + cos(m_angle) * m_rx;
77
0
        *y = m_y + sin(m_angle) * m_ry;
78
79
0
        m_angle += m_da;
80
81
0
        unsigned pf = m_path_cmd;
82
0
        m_path_cmd = path_cmd_line_to;
83
0
        return pf;
84
0
    }
85
86
    //------------------------------------------------------------------------
87
    void arc::normalize(double a1, double a2, bool ccw)
88
0
    {
89
0
        double ra = (fabs(m_rx) + fabs(m_ry)) / 2;
90
0
        m_da = acos(ra / (ra + 0.125 / m_scale)) * 2;
91
0
        if(ccw)
92
0
        {
93
0
            while(a2 < a1) a2 += pi * 2.0;
94
0
        }
95
0
        else
96
0
        {
97
0
            while(a1 < a2) a1 += pi * 2.0;
98
0
            m_da = -m_da;
99
0
        }
100
0
        m_ccw   = ccw;
101
0
        m_start = a1;
102
0
        m_end   = a2;
103
0
        m_initialized = true;
104
0
    }
105
106
}