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_VCGEN_VERTEX_SEQUENCE_INCLUDED 00026 #define AGG_VCGEN_VERTEX_SEQUENCE_INCLUDED 00027 00028 #include "agg_basics.h" 00029 #include "agg_vertex_sequence.h" 00030 #include "agg_shorten_path.h" 00031 00032 namespace agg 00033 { 00034 00035 //===================================================vcgen_vertex_sequence 00036 class vcgen_vertex_sequence 00037 { 00038 public: 00039 typedef vertex_dist_cmd vertex_type; 00040 typedef vertex_sequence<vertex_type, 6> vertex_storage; 00041 00042 vcgen_vertex_sequence() : 00043 m_flags(0), 00044 m_cur_vertex(0), 00045 m_shorten(0.0), 00046 m_ready(false) 00047 { 00048 } 00049 00050 // Vertex Generator Interface 00051 void remove_all(); 00052 void add_vertex(double x, double y, unsigned cmd); 00053 00054 // Vertex Source Interface 00055 void rewind(unsigned path_id); 00056 unsigned vertex(double* x, double* y); 00057 00058 void shorten(double s) { m_shorten = s; } 00059 double shorten() const { return m_shorten; } 00060 00061 private: 00062 vcgen_vertex_sequence(const vcgen_vertex_sequence&); 00063 const vcgen_vertex_sequence& operator = (const vcgen_vertex_sequence&); 00064 00065 vertex_storage m_src_vertices; 00066 unsigned m_flags; 00067 unsigned m_cur_vertex; 00068 double m_shorten; 00069 bool m_ready; 00070 }; 00071 00072 00073 //------------------------------------------------------------------------ 00074 inline void vcgen_vertex_sequence::remove_all() 00075 { 00076 m_ready = false; 00077 m_src_vertices.remove_all(); 00078 m_cur_vertex = 0; 00079 m_flags = 0; 00080 } 00081 00082 //------------------------------------------------------------------------ 00083 inline void vcgen_vertex_sequence::add_vertex(double x, double y, unsigned cmd) 00084 { 00085 m_ready = false; 00086 if(is_move_to(cmd)) 00087 { 00088 m_src_vertices.modify_last(vertex_dist_cmd(x, y, cmd)); 00089 } 00090 else 00091 { 00092 if(is_vertex(cmd)) 00093 { 00094 m_src_vertices.add(vertex_dist_cmd(x, y, cmd)); 00095 } 00096 else 00097 { 00098 m_flags = cmd & path_flags_mask; 00099 } 00100 } 00101 } 00102 00103 00104 //------------------------------------------------------------------------ 00105 inline void vcgen_vertex_sequence::rewind(unsigned) 00106 { 00107 if(!m_ready) 00108 { 00109 m_src_vertices.close(is_closed(m_flags)); 00110 shorten_path(m_src_vertices, m_shorten, get_close_flag(m_flags)); 00111 } 00112 m_ready = true; 00113 m_cur_vertex = 0; 00114 } 00115 00116 //------------------------------------------------------------------------ 00117 inline unsigned vcgen_vertex_sequence::vertex(double* x, double* y) 00118 { 00119 if(!m_ready) 00120 { 00121 rewind(0); 00122 } 00123 00124 if(m_cur_vertex == m_src_vertices.size()) 00125 { 00126 ++m_cur_vertex; 00127 return path_cmd_end_poly | m_flags; 00128 } 00129 00130 if(m_cur_vertex > m_src_vertices.size()) 00131 { 00132 return path_cmd_stop; 00133 } 00134 00135 vertex_type& v = m_src_vertices[m_cur_vertex++]; 00136 *x = v.x; 00137 *y = v.y; 00138 return v.cmd; 00139 } 00140 00141 00142 } 00143 00144 #endif