Anti-Grain Geometry - AGG (libagg)
2.5
|
00001 //---------------------------------------------------------------------------- 00002 // Anti-Grain Geometry (AGG) - Version 2.5 00003 // A high quality rendering engine for C++ 00004 // Copyright (C) 2002-2006 Maxim Shemanarev 00005 // Contact: mcseem@antigrain.com 00006 // mcseemagg@yahoo.com 00007 // http://antigrain.com 00008 // 00009 // AGG is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // AGG is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with AGG; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 // MA 02110-1301, USA. 00023 //---------------------------------------------------------------------------- 00024 00025 #ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED 00026 #define AGG_ELLIPSE_BRESENHAM_INCLUDED 00027 00028 00029 #include "agg_basics.h" 00030 00031 00032 namespace agg 00033 { 00034 00035 //------------------------------------------ellipse_bresenham_interpolator 00036 class ellipse_bresenham_interpolator 00037 { 00038 public: 00039 ellipse_bresenham_interpolator(int rx, int ry) : 00040 m_rx2(rx * rx), 00041 m_ry2(ry * ry), 00042 m_two_rx2(m_rx2 << 1), 00043 m_two_ry2(m_ry2 << 1), 00044 m_dx(0), 00045 m_dy(0), 00046 m_inc_x(0), 00047 m_inc_y(-ry * m_two_rx2), 00048 m_cur_f(0) 00049 {} 00050 00051 int dx() const { return m_dx; } 00052 int dy() const { return m_dy; } 00053 00054 void operator++ () 00055 { 00056 int mx, my, mxy, min_m; 00057 int fx, fy, fxy; 00058 00059 mx = fx = m_cur_f + m_inc_x + m_ry2; 00060 if(mx < 0) mx = -mx; 00061 00062 my = fy = m_cur_f + m_inc_y + m_rx2; 00063 if(my < 0) my = -my; 00064 00065 mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2; 00066 if(mxy < 0) mxy = -mxy; 00067 00068 min_m = mx; 00069 bool flag = true; 00070 00071 if(min_m > my) 00072 { 00073 min_m = my; 00074 flag = false; 00075 } 00076 00077 m_dx = m_dy = 0; 00078 00079 if(min_m > mxy) 00080 { 00081 m_inc_x += m_two_ry2; 00082 m_inc_y += m_two_rx2; 00083 m_cur_f = fxy; 00084 m_dx = 1; 00085 m_dy = 1; 00086 return; 00087 } 00088 00089 if(flag) 00090 { 00091 m_inc_x += m_two_ry2; 00092 m_cur_f = fx; 00093 m_dx = 1; 00094 return; 00095 } 00096 00097 m_inc_y += m_two_rx2; 00098 m_cur_f = fy; 00099 m_dy = 1; 00100 } 00101 00102 private: 00103 int m_rx2; 00104 int m_ry2; 00105 int m_two_rx2; 00106 int m_two_ry2; 00107 int m_dx; 00108 int m_dy; 00109 int m_inc_x; 00110 int m_inc_y; 00111 int m_cur_f; 00112 00113 }; 00114 00115 } 00116 00117 #endif 00118