merge the formfield patch from ooo-build
[ooovba.git] / agg / source / agg_line_aa_basics.cpp
blob878811bc7ec3164b9139ef2f361a6bdaab135ccc
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #include <math.h>
17 #include "agg_line_aa_basics.h"
19 namespace agg
21 //-------------------------------------------------------------------------
22 // The number of the octant is determined as a 3-bit value as follows:
23 // bit 0 = vertical flag
24 // bit 1 = sx < 0
25 // bit 2 = sy < 0
27 // [N] shows the number of the orthogonal quadrant
28 // <M> shows the number of the diagonal quadrant
29 // <1>
30 // [1] | [0]
31 // . (3)011 | 001(1) .
32 // . | .
33 // . | .
34 // . | .
35 // (2)010 .|. 000(0)
36 // <2> ----------.+.----------- <0>
37 // (6)110 . | . 100(4)
38 // . | .
39 // . | .
40 // . | .
41 // (7)111 | 101(5)
42 // [2] | [3]
43 // <3>
44 // 0,1,2,3,4,5,6,7
45 int8u line_parameters::s_orthogonal_quadrant[8] = { 0,0,1,1,3,3,2,2 };
46 int8u line_parameters::s_diagonal_quadrant[8] = { 0,1,2,1,0,3,2,3 };
50 //-------------------------------------------------------------------------
51 void bisectrix(const line_parameters& l1,
52 const line_parameters& l2,
53 int* x, int* y)
55 double k = double(l2.len) / double(l1.len);
56 double tx = l2.x2 - (l2.x1 - l1.x1) * k;
57 double ty = l2.y2 - (l2.y1 - l1.y1) * k;
59 //All bisectrices must be on the right of the line
60 //If the next point is on the left (l1 => l2.2)
61 //then the bisectix should be rotated by 180 degrees.
62 if(double(l2.x2 - l2.x1) * double(l2.y1 - l1.y1) <
63 double(l2.y2 - l2.y1) * double(l2.x1 - l1.x1) + 100.0)
65 tx -= (tx - l2.x1) * 2.0;
66 ty -= (ty - l2.y1) * 2.0;
69 // Check if the bisectrix is too short
70 double dx = tx - l2.x1;
71 double dy = ty - l2.y1;
72 if((int)sqrt(dx * dx + dy * dy) < line_subpixel_size)
74 *x = (l2.x1 + l2.x1 + (l2.y1 - l1.y1) + (l2.y2 - l2.y1)) >> 1;
75 *y = (l2.y1 + l2.y1 - (l2.x1 - l1.x1) - (l2.x2 - l2.x1)) >> 1;
76 return;
78 *x = int(tx);
79 *y = int(ty);