xref: /haiku/headers/libs/agg/agg_ellipse_bresenham.h (revision e39da397f5ff79f2db9f9a3ddf1852b6710578af)
139241fe2SDarkWyrm //----------------------------------------------------------------------------
2*e39da397SStephan Aßmus // Anti-Grain Geometry - Version 2.4
3*e39da397SStephan Aßmus // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
439241fe2SDarkWyrm //
539241fe2SDarkWyrm // Permission to copy, use, modify, sell and distribute this software
639241fe2SDarkWyrm // is granted provided this copyright notice appears in all copies.
739241fe2SDarkWyrm // This software is provided "as is" without express or implied
839241fe2SDarkWyrm // warranty, and with no claim as to its suitability for any purpose.
939241fe2SDarkWyrm //
1039241fe2SDarkWyrm //----------------------------------------------------------------------------
1139241fe2SDarkWyrm // Contact: mcseem@antigrain.com
1239241fe2SDarkWyrm //          mcseemagg@yahoo.com
1339241fe2SDarkWyrm //          http://www.antigrain.com
1439241fe2SDarkWyrm //----------------------------------------------------------------------------
1539241fe2SDarkWyrm //
1639241fe2SDarkWyrm // Simple Bresenham interpolator for ellipsees
1739241fe2SDarkWyrm //
1839241fe2SDarkWyrm //----------------------------------------------------------------------------
1939241fe2SDarkWyrm 
2039241fe2SDarkWyrm #ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED
2139241fe2SDarkWyrm #define AGG_ELLIPSE_BRESENHAM_INCLUDED
2239241fe2SDarkWyrm 
2339241fe2SDarkWyrm 
2439241fe2SDarkWyrm #include "agg_basics.h"
2539241fe2SDarkWyrm 
2639241fe2SDarkWyrm 
2739241fe2SDarkWyrm namespace agg
2839241fe2SDarkWyrm {
2939241fe2SDarkWyrm 
3039241fe2SDarkWyrm     //------------------------------------------ellipse_bresenham_interpolator
3139241fe2SDarkWyrm     class ellipse_bresenham_interpolator
3239241fe2SDarkWyrm     {
3339241fe2SDarkWyrm     public:
ellipse_bresenham_interpolator(int rx,int ry)3439241fe2SDarkWyrm         ellipse_bresenham_interpolator(int rx, int ry) :
3539241fe2SDarkWyrm             m_rx2(rx * rx),
3639241fe2SDarkWyrm             m_ry2(ry * ry),
3739241fe2SDarkWyrm             m_two_rx2(m_rx2 << 1),
3839241fe2SDarkWyrm             m_two_ry2(m_ry2 << 1),
3939241fe2SDarkWyrm             m_dx(0),
4039241fe2SDarkWyrm             m_dy(0),
4139241fe2SDarkWyrm             m_inc_x(0),
4239241fe2SDarkWyrm             m_inc_y(-ry * m_two_rx2),
4339241fe2SDarkWyrm             m_cur_f(0)
4439241fe2SDarkWyrm         {}
4539241fe2SDarkWyrm 
dx()4639241fe2SDarkWyrm         int dx() const { return m_dx; }
dy()4739241fe2SDarkWyrm         int dy() const { return m_dy; }
4839241fe2SDarkWyrm 
4939241fe2SDarkWyrm         void operator++ ()
5039241fe2SDarkWyrm         {
5139241fe2SDarkWyrm             int  mx, my, mxy, min_m;
5239241fe2SDarkWyrm             int  fx, fy, fxy;
5339241fe2SDarkWyrm 
5439241fe2SDarkWyrm             mx = fx = m_cur_f + m_inc_x + m_ry2;
5539241fe2SDarkWyrm             if(mx < 0) mx = -mx;
5639241fe2SDarkWyrm 
5739241fe2SDarkWyrm             my = fy = m_cur_f + m_inc_y + m_rx2;
5839241fe2SDarkWyrm             if(my < 0) my = -my;
5939241fe2SDarkWyrm 
6039241fe2SDarkWyrm             mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2;
6139241fe2SDarkWyrm             if(mxy < 0) mxy = -mxy;
6239241fe2SDarkWyrm 
6339241fe2SDarkWyrm             min_m = mx;
6439241fe2SDarkWyrm             bool flag = true;
6539241fe2SDarkWyrm 
6639241fe2SDarkWyrm             if(min_m > my)
6739241fe2SDarkWyrm             {
6839241fe2SDarkWyrm                 min_m = my;
6939241fe2SDarkWyrm                 flag = false;
7039241fe2SDarkWyrm             }
7139241fe2SDarkWyrm 
7239241fe2SDarkWyrm             m_dx = m_dy = 0;
7339241fe2SDarkWyrm 
7439241fe2SDarkWyrm             if(min_m > mxy)
7539241fe2SDarkWyrm             {
7639241fe2SDarkWyrm                 m_inc_x += m_two_ry2;
7739241fe2SDarkWyrm                 m_inc_y += m_two_rx2;
7839241fe2SDarkWyrm                 m_cur_f = fxy;
7939241fe2SDarkWyrm                 m_dx = 1;
8039241fe2SDarkWyrm                 m_dy = 1;
8139241fe2SDarkWyrm                 return;
8239241fe2SDarkWyrm             }
8339241fe2SDarkWyrm 
8439241fe2SDarkWyrm             if(flag)
8539241fe2SDarkWyrm             {
8639241fe2SDarkWyrm                 m_inc_x += m_two_ry2;
8739241fe2SDarkWyrm                 m_cur_f = fx;
8839241fe2SDarkWyrm                 m_dx = 1;
8939241fe2SDarkWyrm                 return;
9039241fe2SDarkWyrm             }
9139241fe2SDarkWyrm 
9239241fe2SDarkWyrm             m_inc_y += m_two_rx2;
9339241fe2SDarkWyrm             m_cur_f = fy;
9439241fe2SDarkWyrm             m_dy = 1;
9539241fe2SDarkWyrm         }
9639241fe2SDarkWyrm 
9739241fe2SDarkWyrm     private:
9839241fe2SDarkWyrm         int m_rx2;
9939241fe2SDarkWyrm         int m_ry2;
10039241fe2SDarkWyrm         int m_two_rx2;
10139241fe2SDarkWyrm         int m_two_ry2;
10239241fe2SDarkWyrm         int m_dx;
10339241fe2SDarkWyrm         int m_dy;
10439241fe2SDarkWyrm         int m_inc_x;
10539241fe2SDarkWyrm         int m_inc_y;
10639241fe2SDarkWyrm         int m_cur_f;
10739241fe2SDarkWyrm 
10839241fe2SDarkWyrm     };
10939241fe2SDarkWyrm 
11039241fe2SDarkWyrm }
11139241fe2SDarkWyrm 
11239241fe2SDarkWyrm #endif
11339241fe2SDarkWyrm 
114