Anti-Grain Geometry Tutorial
path.h
1 /*
2  * Copyright (c) 2018 Heng Yuan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef TUTORIAL_PATH_H
17 #define TUTORIAL_PATH_H
18 
19 #include <agg_basics.h>
20 #include <agg_trans_affine.h>
21 
26 {
27 public:
28  SimplePath(const double* points, int size)
29  : m_points (points),
30  m_size (size),
31  m_pos (0)
32  {
33  }
34 
41  void rewind (int path = 0)
42  {
43  m_pos = 0;
44  }
45 
56  unsigned vertex(double* x, double* y)
57  {
58  if (m_pos < m_size)
59  {
60  *x = m_points[m_pos++];
61  *y = m_points[m_pos++];
62  return (m_pos == 2 ? agg::path_cmd_move_to : agg::path_cmd_line_to);
63  }
64  return agg::path_cmd_stop;
65  }
66 
67 private:
68  const double *m_points;
69  int m_size;
70  int m_pos;
71 };
72 
76 struct CmdVertex
77 {
78  agg::path_commands_e cmd;
79  double x;
80  double y;
81 };
82 
87 {
88 public:
89  CmdVertexPath(const CmdVertex* vertices, int size)
90  : m_vertices (vertices),
91  m_size (size),
92  m_pos (0)
93  {
94  }
95 
102  void rewind (int path = 0)
103  {
104  m_pos = 0;
105  }
106 
117  unsigned vertex(double* x, double* y)
118  {
119  if (m_pos < m_size)
120  {
121  *x = m_vertices[m_pos].x;
122  *y = m_vertices[m_pos].y;
123  agg::path_commands_e cmd = m_vertices[m_pos].cmd;
124 
125  ++m_pos;
126  return cmd;
127  }
128  return agg::path_cmd_stop;
129  }
130 
131  int size () const { return m_size; }
132 
133 private:
134  const CmdVertex *m_vertices;
135  int m_size;
136  int m_pos;
137 };
138 
139 #endif /* TUTORIAL_PATH_H */
void rewind(int path=0)
Definition: path.h:102
Definition: path.h:76
void rewind(int path=0)
Definition: path.h:41
unsigned vertex(double *x, double *y)
Definition: path.h:56
unsigned vertex(double *x, double *y)
Definition: path.h:117