1*39241fe2SDarkWyrm //---------------------------------------------------------------------------- 2*39241fe2SDarkWyrm // Anti-Grain Geometry - Version 2.2 3*39241fe2SDarkWyrm // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com) 4*39241fe2SDarkWyrm // 5*39241fe2SDarkWyrm // Permission to copy, use, modify, sell and distribute this software 6*39241fe2SDarkWyrm // is granted provided this copyright notice appears in all copies. 7*39241fe2SDarkWyrm // This software is provided "as is" without express or implied 8*39241fe2SDarkWyrm // warranty, and with no claim as to its suitability for any purpose. 9*39241fe2SDarkWyrm // 10*39241fe2SDarkWyrm //---------------------------------------------------------------------------- 11*39241fe2SDarkWyrm // Contact: mcseem@antigrain.com 12*39241fe2SDarkWyrm // mcseemagg@yahoo.com 13*39241fe2SDarkWyrm // http://www.antigrain.com 14*39241fe2SDarkWyrm //---------------------------------------------------------------------------- 15*39241fe2SDarkWyrm // 16*39241fe2SDarkWyrm // Simple Bresenham interpolator for ellipsees 17*39241fe2SDarkWyrm // 18*39241fe2SDarkWyrm //---------------------------------------------------------------------------- 19*39241fe2SDarkWyrm 20*39241fe2SDarkWyrm #ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED 21*39241fe2SDarkWyrm #define AGG_ELLIPSE_BRESENHAM_INCLUDED 22*39241fe2SDarkWyrm 23*39241fe2SDarkWyrm 24*39241fe2SDarkWyrm #include "agg_basics.h" 25*39241fe2SDarkWyrm 26*39241fe2SDarkWyrm 27*39241fe2SDarkWyrm namespace agg 28*39241fe2SDarkWyrm { 29*39241fe2SDarkWyrm 30*39241fe2SDarkWyrm //------------------------------------------ellipse_bresenham_interpolator 31*39241fe2SDarkWyrm class ellipse_bresenham_interpolator 32*39241fe2SDarkWyrm { 33*39241fe2SDarkWyrm public: 34*39241fe2SDarkWyrm ellipse_bresenham_interpolator(int rx, int ry) : 35*39241fe2SDarkWyrm m_rx2(rx * rx), 36*39241fe2SDarkWyrm m_ry2(ry * ry), 37*39241fe2SDarkWyrm m_two_rx2(m_rx2 << 1), 38*39241fe2SDarkWyrm m_two_ry2(m_ry2 << 1), 39*39241fe2SDarkWyrm m_dx(0), 40*39241fe2SDarkWyrm m_dy(0), 41*39241fe2SDarkWyrm m_inc_x(0), 42*39241fe2SDarkWyrm m_inc_y(-ry * m_two_rx2), 43*39241fe2SDarkWyrm m_cur_f(0) 44*39241fe2SDarkWyrm {} 45*39241fe2SDarkWyrm 46*39241fe2SDarkWyrm int dx() const { return m_dx; } 47*39241fe2SDarkWyrm int dy() const { return m_dy; } 48*39241fe2SDarkWyrm 49*39241fe2SDarkWyrm void operator++ () 50*39241fe2SDarkWyrm { 51*39241fe2SDarkWyrm int mx, my, mxy, min_m; 52*39241fe2SDarkWyrm int fx, fy, fxy; 53*39241fe2SDarkWyrm 54*39241fe2SDarkWyrm mx = fx = m_cur_f + m_inc_x + m_ry2; 55*39241fe2SDarkWyrm if(mx < 0) mx = -mx; 56*39241fe2SDarkWyrm 57*39241fe2SDarkWyrm my = fy = m_cur_f + m_inc_y + m_rx2; 58*39241fe2SDarkWyrm if(my < 0) my = -my; 59*39241fe2SDarkWyrm 60*39241fe2SDarkWyrm mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2; 61*39241fe2SDarkWyrm if(mxy < 0) mxy = -mxy; 62*39241fe2SDarkWyrm 63*39241fe2SDarkWyrm min_m = mx; 64*39241fe2SDarkWyrm bool flag = true; 65*39241fe2SDarkWyrm 66*39241fe2SDarkWyrm if(min_m > my) 67*39241fe2SDarkWyrm { 68*39241fe2SDarkWyrm min_m = my; 69*39241fe2SDarkWyrm flag = false; 70*39241fe2SDarkWyrm } 71*39241fe2SDarkWyrm 72*39241fe2SDarkWyrm m_dx = m_dy = 0; 73*39241fe2SDarkWyrm 74*39241fe2SDarkWyrm if(min_m > mxy) 75*39241fe2SDarkWyrm { 76*39241fe2SDarkWyrm m_inc_x += m_two_ry2; 77*39241fe2SDarkWyrm m_inc_y += m_two_rx2; 78*39241fe2SDarkWyrm m_cur_f = fxy; 79*39241fe2SDarkWyrm m_dx = 1; 80*39241fe2SDarkWyrm m_dy = 1; 81*39241fe2SDarkWyrm return; 82*39241fe2SDarkWyrm } 83*39241fe2SDarkWyrm 84*39241fe2SDarkWyrm if(flag) 85*39241fe2SDarkWyrm { 86*39241fe2SDarkWyrm m_inc_x += m_two_ry2; 87*39241fe2SDarkWyrm m_cur_f = fx; 88*39241fe2SDarkWyrm m_dx = 1; 89*39241fe2SDarkWyrm return; 90*39241fe2SDarkWyrm } 91*39241fe2SDarkWyrm 92*39241fe2SDarkWyrm m_inc_y += m_two_rx2; 93*39241fe2SDarkWyrm m_cur_f = fy; 94*39241fe2SDarkWyrm m_dy = 1; 95*39241fe2SDarkWyrm } 96*39241fe2SDarkWyrm 97*39241fe2SDarkWyrm private: 98*39241fe2SDarkWyrm int m_rx2; 99*39241fe2SDarkWyrm int m_ry2; 100*39241fe2SDarkWyrm int m_two_rx2; 101*39241fe2SDarkWyrm int m_two_ry2; 102*39241fe2SDarkWyrm int m_dx; 103*39241fe2SDarkWyrm int m_dy; 104*39241fe2SDarkWyrm int m_inc_x; 105*39241fe2SDarkWyrm int m_inc_y; 106*39241fe2SDarkWyrm int m_cur_f; 107*39241fe2SDarkWyrm 108*39241fe2SDarkWyrm }; 109*39241fe2SDarkWyrm 110*39241fe2SDarkWyrm } 111*39241fe2SDarkWyrm 112*39241fe2SDarkWyrm #endif 113*39241fe2SDarkWyrm 114