1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
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.
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
17 #include "agg_line_aa_basics.h"
21 //-------------------------------------------------------------------------
22 // The number of the octant is determined as a 3-bit value as follows:
23 // bit 0 = vertical flag
27 // [N] shows the number of the orthogonal quadrant
28 // <M> shows the number of the diagonal quadrant
31 // . (3)011 | 001(1) .
36 // <2> ----------.+.----------- <0>
37 // (6)110 . | . 100(4)
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
,
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;