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