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 // Simple Bresenham interpolator for ellipsees
17 //
18 //----------------------------------------------------------------------------
19 
20 #ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED
21 #define AGG_ELLIPSE_BRESENHAM_INCLUDED
22 
23 
24 #include "agg_basics.h"
25 
26 
27 namespace mapserver
28 {
29 
30     //------------------------------------------ellipse_bresenham_interpolator
31     class ellipse_bresenham_interpolator
32     {
33     public:
ellipse_bresenham_interpolator(int rx,int ry)34         ellipse_bresenham_interpolator(int rx, int ry) :
35             m_rx2(rx * rx),
36             m_ry2(ry * ry),
37             m_two_rx2(m_rx2 << 1),
38             m_two_ry2(m_ry2 << 1),
39             m_dx(0),
40             m_dy(0),
41             m_inc_x(0),
42             m_inc_y(-ry * m_two_rx2),
43             m_cur_f(0)
44         {}
45 
dx()46         int dx() const { return m_dx; }
dy()47         int dy() const { return m_dy; }
48 
49         void operator++ ()
50         {
51             int  mx, my, mxy, min_m;
52             int  fx, fy, fxy;
53 
54             mx = fx = m_cur_f + m_inc_x + m_ry2;
55             if(mx < 0) mx = -mx;
56 
57             my = fy = m_cur_f + m_inc_y + m_rx2;
58             if(my < 0) my = -my;
59 
60             mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2;
61             if(mxy < 0) mxy = -mxy;
62 
63             min_m = mx;
64             bool flag = true;
65 
66             if(min_m > my)
67             {
68                 min_m = my;
69                 flag = false;
70             }
71 
72             m_dx = m_dy = 0;
73 
74             if(min_m > mxy)
75             {
76                 m_inc_x += m_two_ry2;
77                 m_inc_y += m_two_rx2;
78                 m_cur_f = fxy;
79                 m_dx = 1;
80                 m_dy = 1;
81                 return;
82             }
83 
84             if(flag)
85             {
86                 m_inc_x += m_two_ry2;
87                 m_cur_f = fx;
88                 m_dx = 1;
89                 return;
90             }
91 
92             m_inc_y += m_two_rx2;
93             m_cur_f = fy;
94             m_dy = 1;
95         }
96 
97     private:
98         int m_rx2;
99         int m_ry2;
100         int m_two_rx2;
101         int m_two_ry2;
102         int m_dx;
103         int m_dy;
104         int m_inc_x;
105         int m_inc_y;
106         int m_cur_f;
107 
108     };
109 
110 }
111 
112 #endif
113 
114