btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / libs / agg / agg_ellipse_bresenham.h
blobee3b9c4638f78be265984f96d85e678fa9553bdc
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 //----------------------------------------------------------------------------
16 // Simple Bresenham interpolator for ellipsees
18 //----------------------------------------------------------------------------
20 #ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED
21 #define AGG_ELLIPSE_BRESENHAM_INCLUDED
24 #include "agg_basics.h"
27 namespace agg
30 //------------------------------------------ellipse_bresenham_interpolator
31 class ellipse_bresenham_interpolator
33 public:
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)
46 int dx() const { return m_dx; }
47 int dy() const { return m_dy; }
49 void operator++ ()
51 int mx, my, mxy, min_m;
52 int fx, fy, fxy;
54 mx = fx = m_cur_f + m_inc_x + m_ry2;
55 if(mx < 0) mx = -mx;
57 my = fy = m_cur_f + m_inc_y + m_rx2;
58 if(my < 0) my = -my;
60 mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2;
61 if(mxy < 0) mxy = -mxy;
63 min_m = mx;
64 bool flag = true;
66 if(min_m > my)
68 min_m = my;
69 flag = false;
72 m_dx = m_dy = 0;
74 if(min_m > mxy)
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;
84 if(flag)
86 m_inc_x += m_two_ry2;
87 m_cur_f = fx;
88 m_dx = 1;
89 return;
92 m_inc_y += m_two_rx2;
93 m_cur_f = fy;
94 m_dy = 1;
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;
112 #endif