vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / agg / agg_vcgen_vertex_sequence.h
blob5adc671597088a680c9632ec2975811a90d4a6d4
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #ifndef AGG_VCGEN_VERTEX_SEQUENCE_INCLUDED
17 #define AGG_VCGEN_VERTEX_SEQUENCE_INCLUDED
19 #include "agg_basics.h"
20 #include "agg_vertex_sequence.h"
21 #include "agg_shorten_path.h"
23 namespace agg
26 //===================================================vcgen_vertex_sequence
27 class vcgen_vertex_sequence
29 public:
30 typedef vertex_dist_cmd vertex_type;
31 typedef vertex_sequence<vertex_type, 6> vertex_storage;
33 vcgen_vertex_sequence() :
34 m_flags(0),
35 m_cur_vertex(0),
36 m_shorten(0.0),
37 m_ready(false)
41 // Vertex Generator Interface
42 void remove_all();
43 void add_vertex(double x, double y, unsigned cmd);
45 // Vertex Source Interface
46 void rewind(unsigned path_id);
47 unsigned vertex(double* x, double* y);
49 void shorten(double s) { m_shorten = s; }
50 double shorten() const { return m_shorten; }
52 private:
53 vcgen_vertex_sequence(const vcgen_vertex_sequence&);
54 const vcgen_vertex_sequence& operator = (const vcgen_vertex_sequence&);
56 vertex_storage m_src_vertices;
57 unsigned m_flags;
58 unsigned m_cur_vertex;
59 double m_shorten;
60 bool m_ready;
64 //------------------------------------------------------------------------
65 inline void vcgen_vertex_sequence::remove_all()
67 m_ready = false;
68 m_src_vertices.remove_all();
69 m_cur_vertex = 0;
70 m_flags = 0;
73 //------------------------------------------------------------------------
74 inline void vcgen_vertex_sequence::add_vertex(double x, double y, unsigned cmd)
76 m_ready = false;
77 if(is_move_to(cmd))
79 m_src_vertices.modify_last(vertex_dist_cmd(x, y, cmd));
81 else
83 if(is_vertex(cmd))
85 m_src_vertices.add(vertex_dist_cmd(x, y, cmd));
87 else
89 m_flags = cmd & path_flags_mask;
95 //------------------------------------------------------------------------
96 inline void vcgen_vertex_sequence::rewind(unsigned)
98 if(!m_ready)
100 m_src_vertices.close(is_closed(m_flags));
101 shorten_path(m_src_vertices, m_shorten, get_close_flag(m_flags));
103 m_ready = true;
104 m_cur_vertex = 0;
107 //------------------------------------------------------------------------
108 inline unsigned vcgen_vertex_sequence::vertex(double* x, double* y)
110 if(!m_ready)
112 rewind(0);
115 if(m_cur_vertex == m_src_vertices.size())
117 ++m_cur_vertex;
118 return path_cmd_end_poly | m_flags;
121 if(m_cur_vertex > m_src_vertices.size())
123 return path_cmd_stop;
126 vertex_type& v = m_src_vertices[m_cur_vertex++];
127 *x = v.x;
128 *y = v.y;
129 return v.cmd;
135 #endif