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

« back to all changes in this revision

Viewing changes to components/aggpas/src/agg_line_aa_basics.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
 
// [Pascal Port History] -----------------------------------------------------
22
 
//
23
 
// 31.10.2006-Milano: Unit port establishment
24
 
//
25
 
{ agg_line_aa_basics.pas }
26
 
unit
27
 
 agg_line_aa_basics ;
28
 
 
29
 
INTERFACE
30
 
 
31
 
{$I agg_mode.inc }
32
 
 
33
 
uses
34
 
 agg_basics ;
35
 
 
36
 
{ TYPES DEFINITION }
37
 
const
38
 
 line_subpixel_shift = 8;                         //----line_subpixel_shift
39
 
 line_subpixel_size  = 1 shl line_subpixel_shift; //----line_subpixel_size
40
 
 line_subpixel_mask  = line_subpixel_size - 1;    //----line_subpixel_mask
41
 
 
42
 
 line_mr_subpixel_shift = 4;                            //----line_mr_subpixel_shift
43
 
 line_mr_subpixel_size  = 1 shl line_mr_subpixel_shift; //----line_mr_subpixel_size
44
 
 line_mr_subpixel_mask  = line_mr_subpixel_size - 1;    //----line_mr_subpixel_mask
45
 
 
46
 
type
47
 
 line_parameters_ptr = ^line_parameters;
48
 
 line_parameters = object
49
 
   x1, y1, x2, y2, dx, dy, sx, sy : int;
50
 
 
51
 
   vertical : boolean;
52
 
 
53
 
   inc_ ,len ,octant : int;
54
 
 
55
 
   constructor Construct; overload;
56
 
   constructor Construct(x1_ ,y1_ ,x2_ ,y2_ ,len_ : int ); overload;
57
 
 
58
 
   function  orthogonal_quadrant : unsigned;
59
 
   function  diagonal_quadrant : unsigned;
60
 
 
61
 
   function  same_orthogonal_quadrant(lp : line_parameters_ptr ) : boolean;
62
 
   function  same_diagonal_quadrant  (lp : line_parameters_ptr ) : boolean;
63
 
 
64
 
  end;
65
 
 
66
 
{ GLOBAL PROCEDURES }
67
 
 function  line_mr(x : int ) : int;
68
 
 function  line_hr(x : int ) : int;
69
 
 
70
 
 function  line_dbl_hr(x : int ) : int;
71
 
 function  line_coord (x : double ) : int;
72
 
 
73
 
 procedure bisectrix(l1 ,l2 : line_parameters_ptr; x ,y : int_ptr );
74
 
 
75
 
 procedure fix_degenerate_bisectrix_start(lp : line_parameters_ptr; x ,y : int_ptr );
76
 
 procedure fix_degenerate_bisectrix_end  (lp : line_parameters_ptr; x ,y : int_ptr );
77
 
 
78
 
 
79
 
IMPLEMENTATION
80
 
{ LOCAL VARIABLES & CONSTANTS }
81
 
const
82
 
// The number of the octant is determined as a 3-bit value as follows:
83
 
// bit 0 = vertical flag
84
 
// bit 1 = sx < 0
85
 
// bit 2 = sy < 0
86
 
//
87
 
// [N] shows the number of the orthogonal quadrant
88
 
// <M> shows the number of the diagonal quadrant
89
 
//               <1>
90
 
//   [1]          |          [0]
91
 
//       . (3)011 | 001(1) .
92
 
//         .      |      .
93
 
//           .    |    .
94
 
//             .  |  .
95
 
//    (2)010     .|.     000(0)
96
 
// <2> ----------.+.----------- <0>
97
 
//    (6)110   .  |  .   100(4)
98
 
//           .    |    .
99
 
//         .      |      .
100
 
//       .        |        .
101
 
//         (7)111 | 101(5)
102
 
//   [2]          |          [3]
103
 
//               <3>
104
 
//                                                0 ,1 ,2 ,3 ,4 ,5 ,6 ,7
105
 
 s_orthogonal_quadrant : array[0..7 ] of int8u = (0 ,0 ,1 ,1 ,3 ,3 ,2 ,2 );
106
 
 s_diagonal_quadrant   : array[0..7 ] of int8u = (0 ,1 ,2 ,1 ,0 ,3 ,2 ,3 );
107
 
 
108
 
{ UNIT IMPLEMENTATION }
109
 
{ CONSTRUCT }
110
 
constructor line_parameters.Construct;
111
 
begin
112
 
end;
113
 
 
114
 
{ CONSTRUCT }
115
 
constructor line_parameters.Construct(x1_ ,y1_ ,x2_ ,y2_ ,len_ : int );
116
 
begin
117
 
 x1:=x1_;
118
 
 y1:=y1_;
119
 
 x2:=x2_;
120
 
 y2:=y2_;
121
 
 dx:=Abs(x2_ - x1_ );
122
 
 dy:=Abs(y2_ - y1_ );
123
 
 
124
 
 if x2_ > x1_ then
125
 
  sx:=1
126
 
 else
127
 
  sx:=-1;
128
 
 
129
 
 if y2_ > y1_ then
130
 
  sy:=1
131
 
 else
132
 
  sy:=-1;
133
 
 
134
 
 vertical:=dy >= dx;
135
 
 
136
 
 if vertical then
137
 
  inc_:=sy
138
 
 else
139
 
  inc_:=sx;
140
 
 
141
 
 len:=len_;
142
 
 
143
 
 octant:=(sy and 4 ) or (sx and 2 ) or int(vertical );
144
 
 
145
 
end;
146
 
 
147
 
{ ORTHOGONAL_QUADRANT }
148
 
function line_parameters.orthogonal_quadrant;
149
 
begin
150
 
 result:=s_orthogonal_quadrant[octant ];
151
 
 
152
 
end;
153
 
 
154
 
{ DIAGONAL_QUADRANT }
155
 
function line_parameters.diagonal_quadrant;
156
 
begin
157
 
 result:=s_diagonal_quadrant[octant ];
158
 
 
159
 
end;
160
 
 
161
 
{ SAME_ORTHOGONAL_QUADRANT }
162
 
function line_parameters.same_orthogonal_quadrant;
163
 
begin
164
 
 result:=s_orthogonal_quadrant[octant ] = s_orthogonal_quadrant[lp.octant ];
165
 
 
166
 
end;
167
 
 
168
 
{ SAME_DIAGONAL_QUADRANT }
169
 
function line_parameters.same_diagonal_quadrant;
170
 
begin
171
 
 result:=s_diagonal_quadrant[octant ] = s_diagonal_quadrant[lp.octant ];
172
 
 
173
 
end;
174
 
 
175
 
{ LINE_MR }
176
 
function line_mr;
177
 
begin
178
 
 result:=shr_int32(x ,line_subpixel_shift - line_mr_subpixel_shift ); 
179
 
 
180
 
end;
181
 
 
182
 
{ LINE_HR }
183
 
function line_hr;
184
 
begin
185
 
 result:=x shl (line_subpixel_shift - line_mr_subpixel_shift );
186
 
 
187
 
end;
188
 
 
189
 
{ LINE_DBL_HR }
190
 
function line_dbl_hr;
191
 
begin
192
 
 result:=x shl line_subpixel_shift;
193
 
 
194
 
end;
195
 
 
196
 
{ LINE_COORD }
197
 
function line_coord;
198
 
begin
199
 
 result:=trunc(x * line_subpixel_size );
200
 
 
201
 
end;
202
 
 
203
 
{ BISECTRIX }
204
 
procedure bisectrix;
205
 
var
206
 
 k ,tx ,ty ,dx ,dy : double;
207
 
 
208
 
begin
209
 
 k :=l2.len / l1.len;
210
 
 tx:=l2.x2 - (l2.x1 - l1.x1 ) * k;
211
 
 ty:=l2.y2 - (l2.y1 - l1.y1 ) * k;
212
 
 
213
 
//All bisectrices must be on the right of the line
214
 
//If the next point is on the left (l1 => l2.2)
215
 
//then the bisectix should be rotated by 180 degrees.
216
 
 if intdbl(l2.x2 - l2.x1 ) * intdbl(l2.y1 - l1.y1 ) <
217
 
    intdbl(l2.y2 - l2.y1 ) * intdbl(l2.x1 - l1.x1 ) + 100.0 then
218
 
  begin
219
 
   tx:=tx - ((tx - l2.x1 ) * 2.0 );
220
 
   ty:=ty - ((ty - l2.y1 ) * 2.0 );
221
 
 
222
 
  end;
223
 
 
224
 
// Check if the bisectrix is too short
225
 
 dx:=tx - l2.x1;
226
 
 dy:=ty - l2.y1;
227
 
 
228
 
 if trunc(Sqrt(dx * dx + dy * dy ) ) < line_subpixel_size then
229
 
  begin
230
 
   x^:=shr_int32(l2.x1 + l2.x1 + (l2.y1 - l1.y1 ) + (l2.y2 - l2.y1 ) ,1 );
231
 
   y^:=shr_int32(l2.y1 + l2.y1 - (l2.x1 - l1.x1 ) - (l2.x2 - l2.x1 ) ,1 );
232
 
 
233
 
   exit;
234
 
 
235
 
  end;
236
 
 
237
 
 x^:=trunc(tx );
238
 
 y^:=trunc(ty );
239
 
 
240
 
end;
241
 
 
242
 
{ FIX_DEGENERATE_BISECTRIX_START }
243
 
procedure fix_degenerate_bisectrix_start;
244
 
var
245
 
 d : int;
246
 
 
247
 
begin
248
 
 d:=trunc(
249
 
  (intdbl(x^ - lp.x2 ) * intdbl(lp.y2 - lp.y1 ) -
250
 
   intdbl(y^ - lp.y2 ) * intdbl(lp.x2 - lp.x1 ) ) / lp.len );
251
 
 
252
 
 if d < line_subpixel_size then
253
 
  begin
254
 
   x^:=lp.x1 + (lp.y2 - lp.y1 );
255
 
   y^:=lp.y1 - (lp.x2 - lp.x1 );
256
 
 
257
 
  end;
258
 
 
259
 
end;
260
 
 
261
 
{ FIX_DEGENERATE_BISECTRIX_END }
262
 
procedure fix_degenerate_bisectrix_end;
263
 
var
264
 
 d : int;
265
 
 
266
 
begin
267
 
 d:=trunc(
268
 
  (intdbl(x^ - lp.x2 ) * intdbl(lp.y2 - lp.y1 ) -
269
 
   intdbl(y^ - lp.y2 ) * intdbl(lp.x2 - lp.x1 ) ) / lp.len );
270
 
 
271
 
 if d < line_subpixel_size then
272
 
  begin
273
 
   x^:=lp.x2 + (lp.y2 - lp.y1 );
274
 
   y^:=lp.y2 - (lp.x2 - lp.x1 );
275
 
 
276
 
  end;
277
 
 
278
 
end;
279
 
 
280
 
END.
281