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
// 07.02.2006-Milano: Unit port establishment
25
{ agg_vpgen_clip_polygon.pas }
27
agg_vpgen_clip_polygon ;
36
agg_clip_liang_barsky ;
40
vpgen_clip_polygon_ptr = ^vpgen_clip_polygon;
41
vpgen_clip_polygon = object(vertex_source )
47
m_clip_flags : unsigned;
50
m_y : array[0..3 ] of double;
56
constructor Construct;
58
procedure clip_box_(x1 ,y1 ,x2 ,y2 : double );
60
function _x1 : double;
61
function _y1 : double;
62
function _x2 : double;
63
function _y2 : double;
65
function _auto_close : boolean;
66
function _auto_unclose : boolean;
69
procedure move_to(x ,y : double );
70
procedure line_to(x ,y : double );
72
function vertex(x ,y : double_ptr ) : unsigned; virtual;
74
function clipping_flags(x ,y : double ) : unsigned;
78
{ GLOBAL VARIABLES & CONSTANTS }
83
{ LOCAL VARIABLES & CONSTANTS }
84
{ UNIT IMPLEMENTATION }
86
constructor vpgen_clip_polygon.Construct;
88
m_clip_box.Construct(0 ,0 ,1 ,1 );
97
m_cmd :=path_cmd_move_to;
102
procedure vpgen_clip_polygon.clip_box_;
109
m_clip_box.normalize;
114
function vpgen_clip_polygon._x1;
116
result:=m_clip_box.x1;
121
function vpgen_clip_polygon._y1;
123
result:=m_clip_box.y1;
128
function vpgen_clip_polygon._x2;
130
result:=m_clip_box.x2;
135
function vpgen_clip_polygon._y2;
137
result:=m_clip_box.y2;
142
function vpgen_clip_polygon._auto_close;
149
function vpgen_clip_polygon._auto_unclose;
156
procedure vpgen_clip_polygon.reset;
164
procedure vpgen_clip_polygon.move_to;
168
m_clip_flags :=clipping_flags(x ,y );
170
if m_clip_flags = 0 then
181
m_cmd:=path_cmd_move_to;
186
procedure vpgen_clip_polygon.line_to;
194
flags:=clipping_flags(x ,y );
196
if m_clip_flags = flags then
209
m_x1 ,m_y1 ,x ,y ,@m_clip_box ,@m_x ,@m_y );
219
function vpgen_clip_polygon.vertex;
224
if m_vertex < m_num_vertices then
232
m_cmd:=path_cmd_line_to;
238
result:=path_cmd_stop;
243
// Determine the clipping code of the vertex according to the
244
// Cyrus-Beck line clipping algorithm
247
// 0110 | 0010 | 0011
249
// -------+--------+-------- clip_box.y2
251
// 0100 | 0000 | 0001
253
// -------+--------+-------- clip_box.y1
255
// 1100 | 1000 | 1001
257
// clip_box.x1 clip_box.x2
258
function vpgen_clip_polygon.clipping_flags;
260
if x < m_clip_box.x1 then
262
if y > m_clip_box.y2 then
270
if y < m_clip_box.y1 then
284
if x > m_clip_box.x2 then
286
if y > m_clip_box.y2 then
294
if y < m_clip_box.y1 then
308
if y > m_clip_box.y2 then
316
if y < m_clip_box.y1 then