1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.4 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 //---------------------------------------------------------------------------- 15 16 #include "agg_vpgen_clip_polyline.h" 17 #include "agg_clip_liang_barsky.h" 18 19 namespace agg 20 { 21 //---------------------------------------------------------------------------- reset()22 void vpgen_clip_polyline::reset() 23 { 24 m_vertex = 0; 25 m_num_vertices = 0; 26 m_move_to = false; 27 } 28 29 //---------------------------------------------------------------------------- move_to(double x,double y)30 void vpgen_clip_polyline::move_to(double x, double y) 31 { 32 m_vertex = 0; 33 m_num_vertices = 0; 34 m_x1 = x; 35 m_y1 = y; 36 m_move_to = true; 37 } 38 39 //---------------------------------------------------------------------------- line_to(double x,double y)40 void vpgen_clip_polyline::line_to(double x, double y) 41 { 42 double x2 = x; 43 double y2 = y; 44 unsigned flags = clip_line_segment(&m_x1, &m_y1, &x2, &y2, m_clip_box); 45 46 m_vertex = 0; 47 m_num_vertices = 0; 48 if((flags & 4) == 0) 49 { 50 if((flags & 1) != 0 || m_move_to) 51 { 52 m_x[0] = m_x1; 53 m_y[0] = m_y1; 54 m_cmd[0] = path_cmd_move_to; 55 m_num_vertices = 1; 56 } 57 m_x[m_num_vertices] = x2; 58 m_y[m_num_vertices] = y2; 59 m_cmd[m_num_vertices++] = path_cmd_line_to; 60 m_move_to = (flags & 2) != 0; 61 } 62 m_x1 = x; 63 m_y1 = y; 64 } 65 66 //---------------------------------------------------------------------------- vertex(double * x,double * y)67 unsigned vpgen_clip_polyline::vertex(double* x, double* y) 68 { 69 if(m_vertex < m_num_vertices) 70 { 71 *x = m_x[m_vertex]; 72 *y = m_y[m_vertex]; 73 return m_cmd[m_vertex++]; 74 } 75 return path_cmd_stop; 76 } 77 } 78