update dev300-m58
[ooovba.git] / agg / source / agg_vpgen_segmentator.cpp
blob85301efa340d0b72aa0628589f4ff21c4fa7c509
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
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 //----------------------------------------------------------------------------
16 #include <math.h>
17 #include "agg_vpgen_segmentator.h"
19 namespace agg
22 void vpgen_segmentator::move_to(double x, double y)
24 m_x1 = x;
25 m_y1 = y;
26 m_dx = 0.0;
27 m_dy = 0.0;
28 m_dl = 2.0;
29 m_ddl = 2.0;
30 m_cmd = path_cmd_move_to;
33 void vpgen_segmentator::line_to(double x, double y)
35 m_x1 += m_dx;
36 m_y1 += m_dy;
37 m_dx = x - m_x1;
38 m_dy = y - m_y1;
39 double len = sqrt(m_dx * m_dx + m_dy * m_dy) * m_approximation_scale;
40 if(len < 1e-30) len = 1e-30;
41 m_ddl = 1.0 / len;
42 m_dl = (m_cmd == path_cmd_move_to) ? 0.0 : m_ddl;
43 if(m_cmd == path_cmd_stop) m_cmd = path_cmd_line_to;
46 unsigned vpgen_segmentator::vertex(double* x, double* y)
48 if(m_cmd == path_cmd_stop) return path_cmd_stop;
50 unsigned cmd = m_cmd;
51 m_cmd = path_cmd_line_to;
52 if(m_dl >= 1.0 - m_ddl)
54 m_dl = 1.0;
55 m_cmd = path_cmd_stop;
56 *x = m_x1 + m_dx;
57 *y = m_y1 + m_dy;
58 return cmd;
60 *x = m_x1 + m_dx * m_dl;
61 *y = m_y1 + m_dy * m_dl;
62 m_dl += m_ddl;
63 return cmd;