| 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: [email protected] |
| 12 |
// [email protected] |
| 13 |
// http://www.antigrain.com |
| 14 |
//---------------------------------------------------------------------------- |
| 15 |
|
| 16 |
#include <math.h> |
| 17 |
#include "agg_vpgen_segmentator.h" |
| 18 |
|
| 19 |
namespace agg |
| 20 |
{ |
| 21 |
|
| 22 |
void vpgen_segmentator::move_to(double x, double y) |
| 23 |
{ |
| 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; |
| 31 |
} |
| 32 |
|
| 33 |
void vpgen_segmentator::line_to(double x, double y) |
| 34 |
{ |
| 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; |
| 44 |
} |
| 45 |
|
| 46 |
unsigned vpgen_segmentator::vertex(double* x, double* y) |
| 47 |
{ |
| 48 |
if(m_cmd == path_cmd_stop) return path_cmd_stop; |
| 49 |
|
| 50 |
unsigned cmd = m_cmd; |
| 51 |
m_cmd = path_cmd_line_to; |
| 52 |
if(m_dl >= 1.0 - m_ddl) |
| 53 |
{ |
| 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; |
| 59 |
} |
| 60 |
*x = m_x1 + m_dx * m_dl; |
| 61 |
*y = m_y1 + m_dy * m_dl; |
| 62 |
m_dl += m_ddl; |
| 63 |
return cmd; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|