1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4 (Public License)
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
// Pascal Port By: Milan Marusinec alias Milano
// milan@marusinec.sk
// http://www.aggpas.org
// Copyright (c) 2005-2006
//
// 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
//
// [Pascal Port History] -----------------------------------------------------
//
// 25.01.2006-Milano: Unit port establishment
//
{ agg_vpgen_segmentator.pas }
unit
agg_vpgen_segmentator ;
INTERFACE
{$I agg_mode.inc }
uses
agg_basics ,
agg_vertex_source ;
{ TYPES DEFINITION }
type
vpgen_segmentator_ptr = ^vpgen_segmentator;
vpgen_segmentator = object(vertex_source )
m_approximation_scale ,
m_x1 ,
m_y1 ,
m_dx ,
m_dy ,
m_dl ,
m_ddl : double;
m_cmd : unsigned;
constructor Construct;
procedure approximation_scale_(s : double );
function _approximation_scale : double;
function _auto_close : boolean;
function _auto_unclose : boolean;
procedure reset;
procedure move_to(x ,y : double );
procedure line_to(x ,y : double );
function vertex(x ,y : double_ptr ) : unsigned; virtual;
end;
{ GLOBAL PROCEDURES }
IMPLEMENTATION
{ LOCAL VARIABLES & CONSTANTS }
{ UNIT IMPLEMENTATION }
{ CONSTRUCT }
constructor vpgen_segmentator.Construct;
begin
m_approximation_scale:=1.0;
m_x1 :=0;
m_y1 :=0;
m_dx :=0;
m_dy :=0;
m_dl :=0;
m_ddl:=0;
m_cmd:=0;
end;
{ APPROXIMATION_SCALE_ }
procedure vpgen_segmentator.approximation_scale_;
begin
m_approximation_scale:=s;
end;
{ _APPROXIMATION_SCALE }
function vpgen_segmentator._approximation_scale;
begin
result:=m_approximation_scale;
end;
{ _AUTO_CLOSE }
function vpgen_segmentator._auto_close;
begin
result:=false
end;
{ _AUTO_UNCLOSE }
function vpgen_segmentator._auto_unclose;
begin
result:=false
end;
{ RESET }
procedure vpgen_segmentator.reset;
begin
m_cmd:=path_cmd_stop;
end;
{ MOVE_TO }
procedure vpgen_segmentator.move_to;
begin
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;
end;
{ LINE_TO }
procedure vpgen_segmentator.line_to;
var
len : double;
begin
m_x1:=m_x1 + m_dx;
m_y1:=m_y1 + m_dy;
m_dx:=x - m_x1;
m_dy:=y - m_y1;
len:=Sqrt(m_dx * m_dx + m_dy * m_dy ) * m_approximation_scale;
if len < 1e-30 then
len:=1e-30;
m_ddl:=1.0 / len;
if m_cmd = path_cmd_move_to then
m_dl:=0.0
else
m_dl:=m_ddl;
if m_cmd = path_cmd_stop then
m_cmd:=path_cmd_line_to;
end;
{ VERTEX }
function vpgen_segmentator.vertex;
var
cmd : unsigned;
begin
if m_cmd = path_cmd_stop then
result:=path_cmd_stop
else
begin
cmd :=m_cmd;
m_cmd:=path_cmd_line_to;
if m_dl >= 1.0 - m_ddl then
begin
m_dl :=1.0;
m_cmd:=path_cmd_stop;
x^:=m_x1 + m_dx;
y^:=m_y1 + m_dy;
result:=cmd;
end
else
begin
x^:=m_x1 + m_dx * m_dl;
y^:=m_y1 + m_dy * m_dl;
m_dl:=m_dl + m_ddl;
result:=cmd;
end;
end;
end;
END.
|