~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/aggpas/src/agg_conv_gpc.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//----------------------------------------------------------------------------
2
 
// Anti-Grain Geometry - Version 2.4 (Public License)
3
 
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
 
//
5
 
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
6
 
// Pascal Port By: Milan Marusinec alias Milano
7
 
//                 milan@marusinec.sk
8
 
//                 http://www.aggpas.org
9
 
// Copyright (c) 2005-2006
10
 
//
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.
15
 
//
16
 
//----------------------------------------------------------------------------
17
 
// Contact: mcseem@antigrain.com
18
 
//          mcseemagg@yahoo.com
19
 
//          http://www.antigrain.com
20
 
//
21
 
//----------------------------------------------------------------------------
22
 
//
23
 
// General Polygon Clipper based on the GPC library by Alan Murta 
24
 
// Union, Intersection, XOR, A-B, B-A
25
 
// Contact the author if you intend to use it in commercial applications!
26
 
// http://www.cs.man.ac.uk/aig/staff/alan/software/
27
 
// Alan Murta (email: gpc@cs.man.ac.uk)
28
 
//
29
 
// [Pascal Port History] -----------------------------------------------------
30
 
//
31
 
// 23.06.2006-Milano: ptrcomp adjustments
32
 
// 22.02.2006-Milano: Unit port establishment
33
 
//
34
 
{ agg_conv_gpc.pas }
35
 
unit
36
 
 agg_conv_gpc ;
37
 
 
38
 
INTERFACE
39
 
 
40
 
{$I agg_mode.inc }
41
 
 
42
 
uses
43
 
 gpc ,
44
 
 agg_basics ,
45
 
 agg_array ,
46
 
 agg_vertex_source ;
47
 
 
48
 
{ TYPES DEFINITION }
49
 
type
50
 
 gpc_op_e = (
51
 
 
52
 
  gpc_or ,
53
 
  gpc_and ,
54
 
  gpc_xor ,
55
 
  gpc_a_minus_b ,
56
 
  gpc_b_minus_a
57
 
 
58
 
  );
59
 
 
60
 
 status = (status_move_to ,status_line_to ,status_stop );
61
 
 
62
 
 gpc_vertex_ptr = ^Tgpc_vertex;
63
 
 
64
 
 contour_header_type_ptr = ^contour_header_type;
65
 
 contour_header_type = record
66
 
   num_vertices ,
67
 
   hole_flag    : int;
68
 
 
69
 
   vertices : gpc_vertex_ptr;
70
 
 
71
 
  end;
72
 
 
73
 
 conv_gpc_ptr = ^conv_gpc;
74
 
 conv_gpc = object(vertex_source )
75
 
   m_src_a ,
76
 
   m_src_b : vertex_source_ptr;
77
 
 
78
 
   m_status    : status;
79
 
   m_vertex    ,
80
 
   m_contour   : int;
81
 
   m_operation : gpc_op_e;
82
 
 
83
 
   m_vertex_accumulator  ,
84
 
   m_contour_accumulator : pod_deque;
85
 
 
86
 
   m_poly_a ,
87
 
   m_poly_b ,
88
 
   m_result : Tgpc_polygon;
89
 
 
90
 
   constructor Construct(a ,b : vertex_source_ptr; op : gpc_op_e = gpc_or );
91
 
   destructor  Destruct; virtual;
92
 
 
93
 
   procedure set_source1(source : vertex_source_ptr );
94
 
   procedure set_source2(source : vertex_source_ptr );
95
 
 
96
 
   procedure operation(v : gpc_op_e );
97
 
 
98
 
  // Vertex Source Interface
99
 
   procedure rewind(path_id : unsigned ); virtual;
100
 
   function  vertex(x ,y : double_ptr ) : unsigned; virtual;
101
 
 
102
 
  // Private
103
 
   procedure free_polygon(p : Pgpc_polygon );
104
 
   procedure free_result;
105
 
   procedure free_gpc_data;
106
 
   procedure start_contour;
107
 
   procedure add_vertex_ (x ,y : double );
108
 
   procedure end_contour (orientation : unsigned );
109
 
   procedure make_polygon(p : Pgpc_polygon );
110
 
   procedure start_extracting;
111
 
 
112
 
   function  next_contour : boolean;
113
 
   function  next_vertex(x ,y : double_ptr ) : boolean;
114
 
 
115
 
   procedure add(src : vertex_source_ptr; p : Pgpc_polygon );
116
 
 
117
 
  end;
118
 
 
119
 
{ GLOBAL PROCEDURES }
120
 
 
121
 
 
122
 
IMPLEMENTATION
123
 
{ LOCAL VARIABLES & CONSTANTS }
124
 
{ UNIT IMPLEMENTATION }
125
 
{ CONSTRUCT }
126
 
constructor conv_gpc.Construct;
127
 
begin
128
 
 m_vertex_accumulator.Construct (sizeof(Tgpc_vertex ) ,8 );
129
 
 m_contour_accumulator.Construct(sizeof(contour_header_type ) ,6 );
130
 
 
131
 
 m_src_a:=a;
132
 
 m_src_b:=b;
133
 
 
134
 
 m_status   :=status_move_to;
135
 
 m_vertex   :=-1;
136
 
 m_contour  :=-1;
137
 
 m_operation:=op;
138
 
 
139
 
 fillchar(m_poly_a ,sizeof(m_poly_a ) ,0 );
140
 
 fillchar(m_poly_b ,sizeof(m_poly_b ) ,0 );
141
 
 fillchar(m_result ,sizeof(m_result ) ,0 );
142
 
 
143
 
end;
144
 
 
145
 
{ DESTRUCT }
146
 
destructor conv_gpc.Destruct;
147
 
begin
148
 
 free_gpc_data;
149
 
 
150
 
 m_vertex_accumulator.Destruct;
151
 
 m_contour_accumulator.Destruct;
152
 
 
153
 
end;
154
 
 
155
 
{ SET_SOURCE1 }
156
 
procedure conv_gpc.set_source1;
157
 
begin
158
 
 m_src_a:=source;
159
 
 
160
 
end;
161
 
 
162
 
{ SET_SOURCE2 }
163
 
procedure conv_gpc.set_source2;
164
 
begin
165
 
 m_src_b:=source;
166
 
 
167
 
end;
168
 
 
169
 
{ OPERATION }
170
 
procedure conv_gpc.operation;
171
 
begin
172
 
 m_operation:=v;
173
 
 
174
 
end;
175
 
 
176
 
{ REWIND }
177
 
procedure conv_gpc.rewind;
178
 
begin
179
 
 free_result;
180
 
 
181
 
 m_src_a.rewind(path_id );
182
 
 m_src_b.rewind(path_id );
183
 
 
184
 
 add(m_src_a ,@m_poly_a );
185
 
 add(m_src_b ,@m_poly_b );
186
 
 
187
 
 case m_operation of
188
 
  gpc_or :
189
 
   gpc_polygon_clip(gpc.GPC_UNION ,@m_poly_a ,@m_poly_b ,@m_result );
190
 
 
191
 
  gpc_and :
192
 
   gpc_polygon_clip(gpc.GPC_INT ,@m_poly_a ,@m_poly_b ,@m_result );
193
 
 
194
 
  gpc_xor :
195
 
   gpc_polygon_clip(gpc.GPC_XOR ,@m_poly_a ,@m_poly_b ,@m_result );
196
 
 
197
 
  gpc_a_minus_b :
198
 
   gpc_polygon_clip(gpc.GPC_DIFF ,@m_poly_a ,@m_poly_b ,@m_result );
199
 
 
200
 
  gpc_b_minus_a :
201
 
   gpc_polygon_clip(gpc.GPC_DIFF ,@m_poly_b ,@m_poly_a ,@m_result );
202
 
 
203
 
 end;
204
 
 
205
 
 start_extracting;
206
 
 
207
 
end;
208
 
 
209
 
{ VERTEX }
210
 
function conv_gpc.vertex;
211
 
begin
212
 
 if m_status = status_move_to then
213
 
  if next_contour then
214
 
   begin
215
 
    if next_vertex(x ,y ) then
216
 
     begin
217
 
      m_status:=status_line_to;
218
 
      result  :=path_cmd_move_to;
219
 
 
220
 
      exit;
221
 
 
222
 
     end;
223
 
 
224
 
    m_status:=status_stop;
225
 
    result  :=path_cmd_end_poly or path_flags_close;
226
 
 
227
 
    exit;
228
 
 
229
 
   end
230
 
  else
231
 
 else
232
 
  begin
233
 
   if next_vertex(x ,y ) then
234
 
    begin
235
 
     result:=path_cmd_line_to;
236
 
 
237
 
     exit;
238
 
 
239
 
    end
240
 
   else
241
 
    m_status:=status_move_to;
242
 
 
243
 
   result:=path_cmd_end_poly or path_flags_close;
244
 
 
245
 
   exit;
246
 
 
247
 
  end;
248
 
 
249
 
 result:=path_cmd_stop;
250
 
 
251
 
end;
252
 
 
253
 
{ FREE_POLYGON }
254
 
procedure conv_gpc.free_polygon;
255
 
var
256
 
 i : int;
257
 
 
258
 
begin
259
 
 i:=0;
260
 
 
261
 
 while i < p.num_contours do
262
 
  begin
263
 
   agg_freemem(pointer(p.contour[i ].vertex ) ,p.contour[i].num_vertices * sizeof(Tgpc_vertex ) );
264
 
 
265
 
   inc(i );
266
 
 
267
 
  end;
268
 
 
269
 
 //agg_freemem(pointer(p.hole ) ,? );
270
 
 agg_freemem(pointer(p.contour ) ,p.num_contours * sizeof(Tgpc_vertex_list ) );
271
 
 
272
 
 fillchar(p^ ,sizeof(Tgpc_polygon ) ,0 );
273
 
 
274
 
end;
275
 
 
276
 
{ FREE_RESULT }
277
 
procedure conv_gpc.free_result;
278
 
begin
279
 
 if m_result.contour <> NIL then
280
 
  gpc_free_polygon(@m_result );
281
 
 
282
 
 fillchar(m_result ,sizeof(m_result ) ,0 );
283
 
 
284
 
end;
285
 
 
286
 
{ FREE_GPC_DATA }
287
 
procedure conv_gpc.free_gpc_data;
288
 
begin
289
 
 free_polygon(@m_poly_a );
290
 
 free_polygon(@m_poly_b );
291
 
 free_result;
292
 
 
293
 
end;
294
 
 
295
 
{ START_CONTOUR }
296
 
procedure conv_gpc.start_contour;
297
 
var
298
 
 h : contour_header_type;
299
 
 
300
 
begin
301
 
 fillchar(h ,sizeof(h ) ,0 );
302
 
 m_contour_accumulator.add(@h );
303
 
 m_vertex_accumulator.remove_all;
304
 
 
305
 
end;
306
 
 
307
 
{ ADD_VERTEX_ }
308
 
procedure conv_gpc.add_vertex_;
309
 
var
310
 
 v : Tgpc_vertex;
311
 
 
312
 
begin
313
 
 v.x:=x;
314
 
 v.y:=y;
315
 
 
316
 
 m_vertex_accumulator.add(@v );
317
 
 
318
 
end;
319
 
 
320
 
{ END_CONTOUR }
321
 
procedure conv_gpc.end_contour;
322
 
var
323
 
 h : contour_header_type_ptr;
324
 
 d ,
325
 
 s : gpc_vertex_ptr;
326
 
 i : int;
327
 
 
328
 
begin
329
 
 if m_contour_accumulator.size <> 0 then
330
 
  if m_vertex_accumulator.size > 2 then
331
 
   begin
332
 
    h:=m_contour_accumulator.array_operator(m_contour_accumulator.size - 1 ); 
333
 
 
334
 
    h.num_vertices:=m_vertex_accumulator.size;
335
 
    h.hole_flag   :=0;
336
 
 
337
 
    // TO DO: Clarify the "holes"
338
 
    // if is_cw(orientation ) then h.hole_flag:=1;
339
 
 
340
 
    agg_getmem(pointer(h.vertices ) ,h.num_vertices * sizeof(Tgpc_vertex ) );
341
 
 
342
 
    d:=h.vertices;
343
 
 
344
 
    for i:=0 to h.num_vertices - 1 do
345
 
     begin
346
 
      s:=m_vertex_accumulator.array_operator(i );
347
 
 
348
 
      d.x:=s.x;
349
 
      d.y:=s.y;
350
 
 
351
 
      inc(ptrcomp(d ) ,sizeof(Tgpc_vertex ) );
352
 
 
353
 
     end;
354
 
 
355
 
   end
356
 
  else
357
 
   m_vertex_accumulator.remove_last;
358
 
 
359
 
end;
360
 
 
361
 
{ MAKE_POLYGON }
362
 
procedure conv_gpc.make_polygon;
363
 
var
364
 
 i : int;
365
 
 h : contour_header_type_ptr;
366
 
 
367
 
//ph : int_ptr;
368
 
 pv : Pgpc_vertex_list;
369
 
 
370
 
begin
371
 
 free_polygon(p );
372
 
 
373
 
 if m_contour_accumulator.size <> 0 then
374
 
  begin
375
 
   p.num_contours:=m_contour_accumulator.size;
376
 
 
377
 
   // TO DO: Clarify the "holes"
378
 
   // p.hole = new int[p.num_contours];
379
 
 
380
 
   p.hole:=NIL;
381
 
 
382
 
   agg_getmem(pointer(p.contour ) ,p.num_contours * sizeof(Tgpc_vertex_list ) );
383
 
 
384
 
   //ph:=p.hole;
385
 
   pv:=Pgpc_vertex_list(p.contour );
386
 
 
387
 
   if p.num_contours > 0 then
388
 
    for i:=0 to p.num_contours - 1 do
389
 
     begin
390
 
      h:=m_contour_accumulator.array_operator(i );
391
 
 
392
 
      //*ph++ = h.hole_flag;
393
 
      pv.num_vertices:=h.num_vertices;
394
 
      pv.vertex      :=Pgpc_vertex_array(h.vertices );
395
 
 
396
 
      inc(ptrcomp(pv ) ,sizeof(Tgpc_vertex_list ) );
397
 
 
398
 
     end;
399
 
 
400
 
  end;
401
 
 
402
 
end;
403
 
 
404
 
{ START_EXTRACTING }
405
 
procedure conv_gpc.start_extracting;
406
 
begin
407
 
 m_status :=status_move_to;
408
 
 m_contour:=-1;
409
 
 m_vertex :=-1;
410
 
 
411
 
end;
412
 
 
413
 
{ NEXT_CONTOUR }
414
 
function conv_gpc.next_contour;
415
 
begin
416
 
 inc(m_contour );
417
 
 
418
 
 if m_contour < m_result.num_contours then
419
 
  begin
420
 
   m_vertex:=-1;
421
 
 
422
 
   result:=true;
423
 
 
424
 
  end
425
 
 else
426
 
  result:=false;
427
 
 
428
 
end;
429
 
 
430
 
{ NEXT_VERTEX }
431
 
function conv_gpc.next_vertex;
432
 
var
433
 
 vlist : Pgpc_vertex_list;
434
 
 
435
 
 v : gpc_vertex_ptr;
436
 
 
437
 
begin
438
 
 vlist:=@m_result.contour[m_contour ];
439
 
 
440
 
 inc(m_vertex );
441
 
 
442
 
 if m_vertex < vlist.num_vertices then
443
 
  begin
444
 
   v:=@vlist.vertex[m_vertex ];
445
 
 
446
 
   x^:=v.x;
447
 
   y^:=v.y;
448
 
 
449
 
   result:=true;
450
 
 
451
 
  end
452
 
 else
453
 
  result:=false; 
454
 
 
455
 
end;
456
 
 
457
 
{ ADD }
458
 
procedure conv_gpc.add;
459
 
var
460
 
 cmd ,orientation : unsigned;
461
 
 
462
 
 x ,y ,start_x ,start_y : double;
463
 
 
464
 
 line_to : boolean;
465
 
 
466
 
begin
467
 
 start_x:=0.0;
468
 
 start_y:=0.0;
469
 
 line_to:=false;
470
 
 
471
 
 orientation:=0;
472
 
 
473
 
 m_contour_accumulator.remove_all;
474
 
 
475
 
 cmd:=src.vertex(@x ,@y );
476
 
 
477
 
 while not is_stop(cmd ) do
478
 
  begin
479
 
   if is_vertex(cmd ) then
480
 
    begin
481
 
     if is_move_to(cmd ) then
482
 
      begin
483
 
       if line_to then
484
 
        begin
485
 
         end_contour(orientation );
486
 
 
487
 
         orientation:=0;
488
 
 
489
 
        end;
490
 
 
491
 
       start_contour;
492
 
 
493
 
       start_x:=x;
494
 
       start_y:=y;
495
 
 
496
 
      end;
497
 
 
498
 
     add_vertex_(x ,y );
499
 
 
500
 
     line_to:=true;
501
 
 
502
 
    end
503
 
   else
504
 
    if is_end_poly(cmd ) then
505
 
     begin
506
 
      orientation:=get_orientation(cmd );
507
 
 
508
 
      if line_to and
509
 
         is_closed(cmd ) then
510
 
       add_vertex_(start_x ,start_y );  
511
 
 
512
 
     end;
513
 
 
514
 
   cmd:=src.vertex(@x ,@y );
515
 
 
516
 
  end;
517
 
 
518
 
 if line_to then
519
 
  end_contour(orientation );
520
 
 
521
 
 make_polygon(p );
522
 
 
523
 
end;
524
 
 
525
 
END.
526