John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 1 | |
| 2 | //---------------------------------------------------------------------------- |
| 3 | // Anti-Grain Geometry - Version 2.3 |
| 4 | // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) |
| 5 | // Copyright (C) 2005 Tony Juricic (tonygeek@yahoo.com) |
| 6 | // |
| 7 | // Permission to copy, use, modify, sell and distribute this software |
| 8 | // is granted provided this copyright notice appears in all copies. |
| 9 | // This software is provided "as is" without express or implied |
| 10 | // warranty, and with no claim as to its suitability for any purpose. |
| 11 | // |
| 12 | //---------------------------------------------------------------------------- |
| 13 | // Contact: mcseem@antigrain.com |
| 14 | // mcseemagg@yahoo.com |
| 15 | // http://www.antigrain.com |
| 16 | //---------------------------------------------------------------------------- |
| 17 | #ifndef AGG_CURVES_INCLUDED |
| 18 | #define AGG_CURVES_INCLUDED |
| 19 | #include "agg_array.h" |
| 20 | namespace agg |
| 21 | { |
Tom Sepez | 6fc8cbb | 2015-04-14 13:50:34 -0700 | [diff] [blame] | 22 | struct curve4_points { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 23 | float cp[8]; |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 24 | curve4_points() {} |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 25 | curve4_points(float x1, float y1, |
| 26 | float x2, float y2, |
| 27 | float x3, float y3, |
| 28 | float x4, float y4) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 29 | { |
| 30 | cp[0] = x1; |
| 31 | cp[1] = y1; |
| 32 | cp[2] = x2; |
| 33 | cp[3] = y2; |
| 34 | cp[4] = x3; |
| 35 | cp[5] = y3; |
| 36 | cp[6] = x4; |
| 37 | cp[7] = y4; |
| 38 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 39 | void init(float x1, float y1, |
| 40 | float x2, float y2, |
| 41 | float x3, float y3, |
| 42 | float x4, float y4) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 43 | { |
| 44 | cp[0] = x1; |
| 45 | cp[1] = y1; |
| 46 | cp[2] = x2; |
| 47 | cp[3] = y2; |
| 48 | cp[4] = x3; |
| 49 | cp[5] = y3; |
| 50 | cp[6] = x4; |
| 51 | cp[7] = y4; |
| 52 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 53 | float operator [] (unsigned i) const |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 54 | { |
| 55 | return cp[i]; |
| 56 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 57 | float& operator [] (unsigned i) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 58 | { |
| 59 | return cp[i]; |
| 60 | } |
| 61 | }; |
Tom Sepez | 6fc8cbb | 2015-04-14 13:50:34 -0700 | [diff] [blame] | 62 | class curve4_div |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 63 | { |
| 64 | public: |
| 65 | curve4_div() : |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 66 | m_count(0) |
| 67 | {} |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 68 | curve4_div(float x1, float y1, |
| 69 | float x2, float y2, |
| 70 | float x3, float y3, |
| 71 | float x4, float y4) : |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 72 | m_count(0) |
| 73 | { |
| 74 | init(x1, y1, x2, y2, x3, y3, x4, y4); |
| 75 | } |
| 76 | curve4_div(const curve4_points& cp) : |
| 77 | m_count(0) |
| 78 | { |
| 79 | init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); |
| 80 | } |
| 81 | void reset() |
| 82 | { |
| 83 | m_points.remove_all(); |
| 84 | m_count = 0; |
| 85 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 86 | void init(float x1, float y1, |
| 87 | float x2, float y2, |
| 88 | float x3, float y3, |
| 89 | float x4, float y4); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 90 | void init(const curve4_points& cp) |
| 91 | { |
| 92 | init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); |
| 93 | } |
| 94 | void rewind(unsigned) |
| 95 | { |
| 96 | m_count = 0; |
| 97 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 98 | unsigned vertex(float* x, float* y) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 99 | { |
| 100 | if(m_count >= m_points.size()) { |
| 101 | return path_cmd_stop; |
| 102 | } |
| 103 | const point_type& p = m_points[m_count++]; |
| 104 | *x = p.x; |
| 105 | *y = p.y; |
| 106 | return (m_count == 1) ? path_cmd_move_to : path_cmd_line_to; |
| 107 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 108 | unsigned vertex_flag(float* x, float* y, int& flag) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 109 | { |
| 110 | if(m_count >= m_points.size()) { |
| 111 | return path_cmd_stop; |
| 112 | } |
| 113 | const point_type& p = m_points[m_count++]; |
| 114 | *x = p.x; |
| 115 | *y = p.y; |
| 116 | flag = p.flag; |
| 117 | return (m_count == 1) ? path_cmd_move_to : path_cmd_line_to; |
| 118 | } |
| 119 | int count() |
| 120 | { |
| 121 | return m_points.size(); |
| 122 | } |
| 123 | private: |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 124 | void bezier(float x1, float y1, |
| 125 | float x2, float y2, |
| 126 | float x3, float y3, |
| 127 | float x4, float y4); |
| 128 | void recursive_bezier(float x1, float y1, |
| 129 | float x2, float y2, |
| 130 | float x3, float y3, |
| 131 | float x4, float y4, |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 132 | unsigned level); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 133 | float m_distance_tolerance_square; |
| 134 | float m_distance_tolerance_manhattan; |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 135 | unsigned m_count; |
| 136 | pod_deque<point_type> m_points; |
| 137 | }; |
Tom Sepez | 6fc8cbb | 2015-04-14 13:50:34 -0700 | [diff] [blame] | 138 | class curve4 |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 139 | { |
| 140 | public: |
| 141 | curve4() {} |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 142 | curve4(float x1, float y1, |
| 143 | float x2, float y2, |
| 144 | float x3, float y3, |
| 145 | float x4, float y4) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 146 | { |
| 147 | init(x1, y1, x2, y2, x3, y3, x4, y4); |
| 148 | } |
| 149 | curve4(const curve4_points& cp) |
| 150 | { |
| 151 | init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); |
| 152 | } |
| 153 | void reset() |
| 154 | { |
| 155 | m_curve_div.reset(); |
| 156 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 157 | void init(float x1, float y1, |
| 158 | float x2, float y2, |
| 159 | float x3, float y3, |
| 160 | float x4, float y4) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 161 | { |
| 162 | m_curve_div.init(x1, y1, x2, y2, x3, y3, x4, y4); |
| 163 | } |
| 164 | void init(const curve4_points& cp) |
| 165 | { |
| 166 | init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]); |
| 167 | } |
| 168 | void rewind(unsigned path_id) |
| 169 | { |
| 170 | m_curve_div.rewind(path_id); |
| 171 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 172 | unsigned vertex(float* x, float* y) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 173 | { |
| 174 | return m_curve_div.vertex(x, y); |
| 175 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 176 | unsigned vertex_curve_flag(float* x, float* y, int& flag) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 177 | { |
| 178 | return m_curve_div.vertex_flag(x, y, flag); |
| 179 | } |
| 180 | int count() |
| 181 | { |
| 182 | return m_curve_div.count(); |
| 183 | } |
| 184 | private: |
| 185 | curve4_div m_curve_div; |
| 186 | }; |
| 187 | } |
| 188 | #endif |