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_CONV_CLOSE_POLYGON_INCLUDED 00026 #define AGG_CONV_CLOSE_POLYGON_INCLUDED 00027 00028 #include "agg_basics.h" 00029 00030 namespace agg 00031 { 00032 00033 //======================================================conv_close_polygon 00034 template<class VertexSource> class conv_close_polygon 00035 { 00036 public: 00037 explicit conv_close_polygon(VertexSource& vs) : m_source(&vs) {} 00038 void attach(VertexSource& source) { m_source = &source; } 00039 00040 void rewind(unsigned path_id); 00041 unsigned vertex(double* x, double* y); 00042 00043 private: 00044 conv_close_polygon(const conv_close_polygon<VertexSource>&); 00045 const conv_close_polygon<VertexSource>& 00046 operator = (const conv_close_polygon<VertexSource>&); 00047 00048 VertexSource* m_source; 00049 unsigned m_cmd[2]; 00050 double m_x[2]; 00051 double m_y[2]; 00052 unsigned m_vertex; 00053 bool m_line_to; 00054 }; 00055 00056 00057 00058 //------------------------------------------------------------------------ 00059 template<class VertexSource> 00060 void conv_close_polygon<VertexSource>::rewind(unsigned path_id) 00061 { 00062 m_source->rewind(path_id); 00063 m_vertex = 2; 00064 m_line_to = false; 00065 } 00066 00067 00068 00069 //------------------------------------------------------------------------ 00070 template<class VertexSource> 00071 unsigned conv_close_polygon<VertexSource>::vertex(double* x, double* y) 00072 { 00073 unsigned cmd = path_cmd_stop; 00074 for(;;) 00075 { 00076 if(m_vertex < 2) 00077 { 00078 *x = m_x[m_vertex]; 00079 *y = m_y[m_vertex]; 00080 cmd = m_cmd[m_vertex]; 00081 ++m_vertex; 00082 break; 00083 } 00084 00085 cmd = m_source->vertex(x, y); 00086 00087 if(is_end_poly(cmd)) 00088 { 00089 cmd |= path_flags_close; 00090 break; 00091 } 00092 00093 if(is_stop(cmd)) 00094 { 00095 if(m_line_to) 00096 { 00097 m_cmd[0] = path_cmd_end_poly | path_flags_close; 00098 m_cmd[1] = path_cmd_stop; 00099 m_vertex = 0; 00100 m_line_to = false; 00101 continue; 00102 } 00103 break; 00104 } 00105 00106 if(is_move_to(cmd)) 00107 { 00108 if(m_line_to) 00109 { 00110 m_x[0] = 0.0; 00111 m_y[0] = 0.0; 00112 m_cmd[0] = path_cmd_end_poly | path_flags_close; 00113 m_x[1] = *x; 00114 m_y[1] = *y; 00115 m_cmd[1] = cmd; 00116 m_vertex = 0; 00117 m_line_to = false; 00118 continue; 00119 } 00120 break; 00121 } 00122 00123 if(is_vertex(cmd)) 00124 { 00125 m_line_to = true; 00126 break; 00127 } 00128 } 00129 return cmd; 00130 } 00131 00132 } 00133 00134 #endif