OLD | NEW |
1 | 1 |
2 //---------------------------------------------------------------------------- | 2 //---------------------------------------------------------------------------- |
3 // Anti-Grain Geometry - Version 2.3 | 3 // Anti-Grain Geometry - Version 2.3 |
4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) | 4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) |
5 // | 5 // |
6 // Permission to copy, use, modify, sell and distribute this software | 6 // Permission to copy, use, modify, sell and distribute this software |
7 // is granted provided this copyright notice appears in all copies. | 7 // is granted provided this copyright notice appears in all copies. |
8 // This software is provided "as is" without express or implied | 8 // This software is provided "as is" without express or implied |
9 // warranty, and with no claim as to its suitability for any purpose. | 9 // warranty, and with no claim as to its suitability for any purpose. |
10 // | 10 // |
11 //---------------------------------------------------------------------------- | 11 //---------------------------------------------------------------------------- |
12 // Contact: mcseem@antigrain.com | 12 // Contact: mcseem@antigrain.com |
13 // mcseemagg@yahoo.com | 13 // mcseemagg@yahoo.com |
14 // http://www.antigrain.com | 14 // http://www.antigrain.com |
15 //---------------------------------------------------------------------------- | 15 //---------------------------------------------------------------------------- |
16 // Bessel function (besj) was adapted for use in AGG library by Andy Wilk | 16 // Bessel function (besj) was adapted for use in AGG library by Andy Wilk |
17 // Contact: castor.vulgaris@gmail.com | 17 // Contact: castor.vulgaris@gmail.com |
18 //---------------------------------------------------------------------------- | 18 //---------------------------------------------------------------------------- |
19 #ifndef AGG_MATH_INCLUDED | 19 #ifndef AGG_MATH_INCLUDED |
20 #define AGG_MATH_INCLUDED | 20 #define AGG_MATH_INCLUDED |
21 #include "agg_basics.h" | 21 #include "agg_basics.h" |
22 namespace agg | 22 namespace agg |
23 { | 23 { |
24 const FX_FLOAT intersection_epsilon = 1.0e-30f; | 24 const FX_FLOAT intersection_epsilon = 1.0e-30f; |
25 AGG_INLINE FX_FLOAT calc_point_location(FX_FLOAT x1, FX_FLOAT y1, | 25 AGG_INLINE FX_FLOAT calc_point_location(FX_FLOAT x1, FX_FLOAT y1, |
26 FX_FLOAT x2, FX_FLOAT y2, | 26 FX_FLOAT x2, FX_FLOAT y2, |
27 FX_FLOAT x, FX_FLOAT y) | 27 FX_FLOAT x, FX_FLOAT y) |
28 { | 28 { |
29 return FXSYS_Mul(x - x2, y2 - y1) - FXSYS_Mul(y - y2, x2 - x1); | 29 return ((x - x2) * (y2 - y1)) - ((y - y2) * (x2 - x1)); |
30 } | 30 } |
31 AGG_INLINE FX_FLOAT calc_distance(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOA
T y2) | 31 AGG_INLINE FX_FLOAT calc_distance(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOA
T y2) |
32 { | 32 { |
33 FX_FLOAT dx = x2 - x1; | 33 FX_FLOAT dx = x2 - x1; |
34 FX_FLOAT dy = y2 - y1; | 34 FX_FLOAT dy = y2 - y1; |
35 return FXSYS_sqrt2(dx, dy); | 35 return FXSYS_sqrt2(dx, dy); |
36 } | 36 } |
37 AGG_INLINE FX_FLOAT calc_line_point_distance(FX_FLOAT x1, FX_FLOAT y1, | 37 AGG_INLINE FX_FLOAT calc_line_point_distance(FX_FLOAT x1, FX_FLOAT y1, |
38 FX_FLOAT x2, FX_FLOAT y2, | 38 FX_FLOAT x2, FX_FLOAT y2, |
39 FX_FLOAT x, FX_FLOAT y) | 39 FX_FLOAT x, FX_FLOAT y) |
40 { | 40 { |
41 FX_FLOAT dx = x2 - x1; | 41 FX_FLOAT dx = x2 - x1; |
42 FX_FLOAT dy = y2 - y1; | 42 FX_FLOAT dy = y2 - y1; |
43 FX_FLOAT d = FXSYS_sqrt2(dx, dy); | 43 FX_FLOAT d = FXSYS_sqrt2(dx, dy); |
44 if(d < intersection_epsilon) { | 44 if(d < intersection_epsilon) { |
45 return calc_distance(x1, y1, x, y); | 45 return calc_distance(x1, y1, x, y); |
46 } | 46 } |
47 return FXSYS_MulDiv(x - x2, dy, d) - FXSYS_MulDiv(y - y2, dx, d); | 47 return FXSYS_MulDiv(x - x2, dy, d) - FXSYS_MulDiv(y - y2, dx, d); |
48 } | 48 } |
49 AGG_INLINE bool calc_intersection(FX_FLOAT ax, FX_FLOAT ay, FX_FLOAT bx, FX_FLOA
T by, | 49 AGG_INLINE bool calc_intersection(FX_FLOAT ax, FX_FLOAT ay, FX_FLOAT bx, FX_FLOA
T by, |
50 FX_FLOAT cx, FX_FLOAT cy, FX_FLOAT dx, FX_FLOA
T dy, | 50 FX_FLOAT cx, FX_FLOAT cy, FX_FLOAT dx, FX_FLOA
T dy, |
51 FX_FLOAT* x, FX_FLOAT* y) | 51 FX_FLOAT* x, FX_FLOAT* y) |
52 { | 52 { |
53 FX_FLOAT num = FXSYS_Mul(ay - cy, dx - cx) - FXSYS_Mul(ax - cx, dy - cy); | 53 FX_FLOAT num = ((ay - cy) * (dx - cx)) - ((ax - cx) * (dy - cy)); |
54 FX_FLOAT den = FXSYS_Mul(bx - ax, dy - cy) - FXSYS_Mul(by - ay, dx - cx); | 54 FX_FLOAT den = ((bx - ax) * (dy - cy)) - ((by - ay) * (dx - cx)); |
55 if (FXSYS_fabs(den) < intersection_epsilon) { | 55 if (FXSYS_fabs(den) < intersection_epsilon) { |
56 return false; | 56 return false; |
57 } | 57 } |
58 *x = ax + FXSYS_MulDiv(bx - ax, num, den); | 58 *x = ax + FXSYS_MulDiv(bx - ax, num, den); |
59 *y = ay + FXSYS_MulDiv(by - ay, num, den); | 59 *y = ay + FXSYS_MulDiv(by - ay, num, den); |
60 return true; | 60 return true; |
61 } | 61 } |
62 } | 62 } |
63 #endif | 63 #endif |
OLD | NEW |