summaryrefslogtreecommitdiff
path: root/agg/source/agg_vpgen_segmentator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'agg/source/agg_vpgen_segmentator.cpp')
-rwxr-xr-xagg/source/agg_vpgen_segmentator.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/agg/source/agg_vpgen_segmentator.cpp b/agg/source/agg_vpgen_segmentator.cpp
new file mode 100755
index 000000000000..97e76707c1cb
--- /dev/null
+++ b/agg/source/agg_vpgen_segmentator.cpp
@@ -0,0 +1,67 @@
+//----------------------------------------------------------------------------
+// Anti-Grain Geometry - Version 2.3
+// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
+//
+// Permission to copy, use, modify, sell and distribute this software
+// is granted provided this copyright notice appears in all copies.
+// This software is provided "as is" without express or implied
+// warranty, and with no claim as to its suitability for any purpose.
+//
+//----------------------------------------------------------------------------
+// Contact: mcseem@antigrain.com
+// mcseemagg@yahoo.com
+// http://www.antigrain.com
+//----------------------------------------------------------------------------
+
+#include <math.h>
+#include "agg_vpgen_segmentator.h"
+
+namespace agg
+{
+
+ void vpgen_segmentator::move_to(double x, double y)
+ {
+ m_x1 = x;
+ m_y1 = y;
+ m_dx = 0.0;
+ m_dy = 0.0;
+ m_dl = 2.0;
+ m_ddl = 2.0;
+ m_cmd = path_cmd_move_to;
+ }
+
+ void vpgen_segmentator::line_to(double x, double y)
+ {
+ m_x1 += m_dx;
+ m_y1 += m_dy;
+ m_dx = x - m_x1;
+ m_dy = y - m_y1;
+ double len = sqrt(m_dx * m_dx + m_dy * m_dy) * m_approximation_scale;
+ if(len < 1e-30) len = 1e-30;
+ m_ddl = 1.0 / len;
+ m_dl = (m_cmd == path_cmd_move_to) ? 0.0 : m_ddl;
+ if(m_cmd == path_cmd_stop) m_cmd = path_cmd_line_to;
+ }
+
+ unsigned vpgen_segmentator::vertex(double* x, double* y)
+ {
+ if(m_cmd == path_cmd_stop) return path_cmd_stop;
+
+ unsigned cmd = m_cmd;
+ m_cmd = path_cmd_line_to;
+ if(m_dl >= 1.0 - m_ddl)
+ {
+ m_dl = 1.0;
+ m_cmd = path_cmd_stop;
+ *x = m_x1 + m_dx;
+ *y = m_y1 + m_dy;
+ return cmd;
+ }
+ *x = m_x1 + m_dx * m_dl;
+ *y = m_y1 + m_dy * m_dl;
+ m_dl += m_ddl;
+ return cmd;
+ }
+
+}
+