Anti-Grain Geometry Tutorial
agg_trans_single_path.h
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 //----------------------------------------------------------------------------
15 
16 #ifndef AGG_TRANS_SINGLE_PATH_INCLUDED
17 #define AGG_TRANS_SINGLE_PATH_INCLUDED
18 
19 #include "agg_basics.h"
20 #include "agg_vertex_sequence.h"
21 
22 namespace agg
23 {
24 
25  // See also: agg_trans_single_path.cpp
26  //
27  //-------------------------------------------------------trans_single_path
29  {
30  enum status_e
31  {
32  initial,
33  making_path,
34  ready
35  };
36 
37  public:
39 
41 
42  //--------------------------------------------------------------------
43  void base_length(double v) { m_base_length = v; }
44  double base_length() const { return m_base_length; }
45 
46  //--------------------------------------------------------------------
47  void preserve_x_scale(bool f) { m_preserve_x_scale = f; }
48  bool preserve_x_scale() const { return m_preserve_x_scale; }
49 
50  //--------------------------------------------------------------------
51  void reset();
52  void move_to(double x, double y);
53  void line_to(double x, double y);
54  void finalize_path();
55 
56  //--------------------------------------------------------------------
57  template<class VertexSource>
58  void add_path(VertexSource& vs, unsigned path_id=0)
59  {
60  double x;
61  double y;
62 
63  unsigned cmd;
64  vs.rewind(path_id);
65  while(!is_stop(cmd = vs.vertex(&x, &y)))
66  {
67  if(is_move_to(cmd))
68  {
69  move_to(x, y);
70  }
71  else
72  {
73  if(is_vertex(cmd))
74  {
75  line_to(x, y);
76  }
77  }
78  }
79  finalize_path();
80  }
81 
82  //--------------------------------------------------------------------
83  double total_length() const;
84  void transform(double *x, double *y) const;
85 
86  private:
87  vertex_storage m_src_vertices;
88  double m_base_length;
89  double m_kindex;
90  status_e m_status;
91  bool m_preserve_x_scale;
92  };
93 
94 
95 }
96 
97 #endif
Definition: agg_arc.cpp:24