1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.4 (Public License)
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
6
// Pascal Port By: Milan Marusinec alias Milano
8
// http://www.aggpas.org
9
// Copyright (c) 2005-2006
11
// Permission to copy, use, modify, sell and distribute this software
12
// is granted provided this copyright notice appears in all copies.
13
// This software is provided "as is" without express or implied
14
// warranty, and with no claim as to its suitability for any purpose.
16
//----------------------------------------------------------------------------
17
// Contact: mcseem@antigrain.com
18
// mcseemagg@yahoo.com
19
// http://www.antigrain.com
21
// [Pascal Port History] -----------------------------------------------------
23
// 19.01.2006-Milano: Complete Unit Port
24
// 18.01.2006-Milano: Unit port establishment
26
{ agg_vcgen_bspline.pas }
42
status_e = (initial ,ready ,polygon ,end_poly ,stop );
44
vcgen_bspline_ptr = ^vcgen_bspline;
45
vcgen_bspline = object(vertex_source )
46
m_src_vertices : pod_deque;
51
m_interpolation_step : double;
56
m_src_vertex : unsigned;
59
m_max_abscissa : double;
61
constructor Construct;
62
destructor Destruct; virtual;
64
procedure interpolation_step_(v : double );
65
function _interpolation_step : double;
67
// Vertex Generator Interface
68
procedure remove_all; virtual;
69
procedure add_vertex(x ,y : double; cmd : unsigned ); virtual;
71
// Vertex Source Interface
72
procedure rewind(path_id : unsigned ); virtual;
73
function vertex(x ,y : double_ptr ) : unsigned; virtual;
81
{ LOCAL VARIABLES & CONSTANTS }
82
{ UNIT IMPLEMENTATION }
84
constructor vcgen_bspline.Construct;
88
m_src_vertices.Construct(sizeof(point_type ) ,6 );
92
m_interpolation_step:=1.0 / 50.0;
102
destructor vcgen_bspline.Destruct;
106
m_src_vertices.Destruct;
112
{ INTERPOLATION_STEP_ }
113
procedure vcgen_bspline.interpolation_step_;
115
m_interpolation_step:=v;
119
{ _INTERPOLATION_STEP }
120
function vcgen_bspline._interpolation_step;
122
result:=m_interpolation_step;
127
procedure vcgen_bspline.remove_all;
129
m_src_vertices.remove_all;
139
procedure vcgen_bspline.add_vertex;
146
if is_move_to(cmd ) then
151
m_src_vertices.modify_last(@pt );
155
if is_vertex(cmd ) then
160
m_src_vertices.add(@pt );
164
m_closed:=get_close_flag(cmd );
169
procedure vcgen_bspline.rewind;
180
if (m_status = initial ) and
181
(m_src_vertices.size > 2 ) then
183
if m_closed <> 0 then
185
m_spline_x.init(m_src_vertices.size + 8 );
186
m_spline_y.init(m_src_vertices.size + 8 );
188
m_spline_x.add_point(0.0 ,point_type_ptr(m_src_vertices.prev(m_src_vertices.size - 3 ) )^.x );
189
m_spline_y.add_point(0.0 ,point_type_ptr(m_src_vertices.prev(m_src_vertices.size - 3 ) )^.y );
190
m_spline_x.add_point(1.0 ,point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 3 ) )^.x );
191
m_spline_y.add_point(1.0 ,point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 3 ) )^.y );
192
m_spline_x.add_point(2.0 ,point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 2 ) )^.x );
193
m_spline_y.add_point(2.0 ,point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 2 ) )^.y );
194
m_spline_x.add_point(3.0 ,point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 1 ) )^.x );
195
m_spline_y.add_point(3.0 ,point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 1 ) )^.y );
200
m_spline_x.init(m_src_vertices.size );
201
m_spline_y.init(m_src_vertices.size );
205
for i:=0 to m_src_vertices.size - 1 do
207
if m_closed <> 0 then
212
m_spline_x.add_point(x ,point_type_ptr(m_src_vertices.array_operator(i ) )^.x );
213
m_spline_y.add_point(x ,point_type_ptr(m_src_vertices.array_operator(i ) )^.y );
218
m_max_abscissa:=m_src_vertices.size - 1;
220
if m_closed <> 0 then
223
m_max_abscissa:=m_max_abscissa + 5.0;
225
m_spline_x.add_point(
226
m_src_vertices.size + 4 ,
227
point_type_ptr(m_src_vertices.array_operator(0 ) )^.x );
229
m_spline_y.add_point(
230
m_src_vertices.size + 4 ,
231
point_type_ptr(m_src_vertices.array_operator(0 ) )^.y );
233
m_spline_x.add_point(
234
m_src_vertices.size + 5 ,
235
point_type_ptr(m_src_vertices.array_operator(1 ) )^.x );
237
m_spline_y.add_point(
238
m_src_vertices.size + 5 ,
239
point_type_ptr(m_src_vertices.array_operator(1 ) )^.y );
241
m_spline_x.add_point(
242
m_src_vertices.size + 6 ,
243
point_type_ptr(m_src_vertices.array_operator(2 ) )^.x );
245
m_spline_y.add_point(
246
m_src_vertices.size + 6 ,
247
point_type_ptr(m_src_vertices.array_operator(2 ) )^.y );
249
m_spline_x.add_point(
250
m_src_vertices.size + 7 ,
251
point_type_ptr(m_src_vertices.next(2 ) )^.x );
253
m_spline_y.add_point(
254
m_src_vertices.size + 7 ,
255
point_type_ptr(m_src_vertices.next(2 ) )^.y );
269
function vcgen_bspline.vertex;
274
_next ,_ready ,_polygon ;
277
cmd:=path_cmd_line_to;
280
while not is_stop(cmd ) do
293
if m_src_vertices.size < 2 then
301
if m_src_vertices.size = 2 then
303
x^:=point_type_ptr(m_src_vertices.array_operator(m_src_vertex ) )^.x;
304
y^:=point_type_ptr(m_src_vertices.array_operator(m_src_vertex ) )^.y;
308
if m_src_vertex = 1 then
310
result:=path_cmd_move_to;
316
if m_src_vertex = 2 then
318
result:=path_cmd_line_to;
330
cmd:=path_cmd_move_to;
343
if m_cur_abscissa >= m_max_abscissa then
344
if m_closed <> 0 then
353
x^:=point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 1 ) )^.x;
354
y^:=point_type_ptr(m_src_vertices.array_operator(m_src_vertices.size - 1 ) )^.y;
357
result :=path_cmd_line_to;
363
x^:=m_spline_x.get_stateful(m_cur_abscissa );
364
y^:=m_spline_y.get_stateful(m_cur_abscissa );
368
m_cur_abscissa:=m_cur_abscissa + m_interpolation_step;
370
if m_src_vertex = 1 then
371
result:=path_cmd_move_to
373
result:=path_cmd_line_to;
382
result :=path_cmd_end_poly or m_closed;
390
result:=path_cmd_stop;