1
2 //----------------------------------------------------------------------------
3 // Anti-Grain Geometry - Version 2.3
4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 //
6 // Permission to copy, use, modify, sell and distribute this software
7 // is granted provided this copyright notice appears in all copies.
8 // This software is provided "as is" without express or implied
9 // warranty, and with no claim as to its suitability for any purpose.
10 //
11 //----------------------------------------------------------------------------
12 // Contact: [email protected]
13 // [email protected]
14 // http://www.antigrain.com
15 //----------------------------------------------------------------------------
16 //
17 // vertex_sequence container and vertex_dist struct
18 //
19 //----------------------------------------------------------------------------
20 #ifndef AGG_VERTEX_SEQUENCE_INCLUDED
21 #define AGG_VERTEX_SEQUENCE_INCLUDED
22 #include "agg_basics.h"
23 #include "agg_array.h"
24 #include "agg_math.h"
25 namespace pdfium
26 {
27 namespace agg
28 {
29 template<class T, unsigned S = 6>
30 class vertex_sequence : public pod_deque<T, S>
31 {
32 public:
33 typedef pod_deque<T, S> base_type;
34 void add(const T& val);
35 void modify_last(const T& val);
36 void close(bool closed);
37 };
38 template<class T, unsigned S>
add(const T & val)39 void vertex_sequence<T, S>::add(const T& val)
40 {
41 if(base_type::size() > 1) {
42 if(!(*this)[base_type::size() - 2]((*this)[base_type::size() - 1])) {
43 base_type::remove_last();
44 }
45 }
46 base_type::add(val);
47 }
48 template<class T, unsigned S>
modify_last(const T & val)49 void vertex_sequence<T, S>::modify_last(const T& val)
50 {
51 base_type::remove_last();
52 add(val);
53 }
54 template<class T, unsigned S>
close(bool closed)55 void vertex_sequence<T, S>::close(bool closed)
56 {
57 while(base_type::size() > 1) {
58 if((*this)[base_type::size() - 2]((*this)[base_type::size() - 1])) {
59 break;
60 }
61 T t = (*this)[base_type::size() - 1];
62 base_type::remove_last();
63 modify_last(t);
64 }
65 if(closed) {
66 while(base_type::size() > 1) {
67 if((*this)[base_type::size() - 1]((*this)[0])) {
68 break;
69 }
70 base_type::remove_last();
71 }
72 }
73 }
74 const float vertex_dist_epsilon = 1e-14f;
75 struct vertex_dist {
76 float x;
77 float y;
78 float dist;
vertex_distvertex_dist79 vertex_dist() {}
vertex_distvertex_dist80 vertex_dist(float x_, float y_) :
81 x(x_),
82 y(y_),
83 dist(0)
84 {
85 }
operatorvertex_dist86 bool operator () (const vertex_dist& val)
87 {
88 bool ret = (dist = calc_distance(x, y, val.x, val.y)) > vertex_dist_epsilon;
89 return ret;
90 }
91 };
92 struct vertex_dist_cmd : public vertex_dist {
93 unsigned cmd;
vertex_dist_cmdvertex_dist_cmd94 vertex_dist_cmd() {}
vertex_dist_cmdvertex_dist_cmd95 vertex_dist_cmd(float x_, float y_, unsigned cmd_) :
96 vertex_dist(x_, y_),
97 cmd(cmd_)
98 {
99 }
100 };
101 }
102 } // namespace pdfium
103 #endif
104