• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 float intersection_epsilon = 1.0e-30f;
calc_point_location(float x1,float y1,float x2,float y2,float x,float y)25 AGG_INLINE float calc_point_location(float x1, float y1,
26                                         float x2, float y2,
27                                         float x,  float y)
28 {
29   return ((x - x2) * (y2 - y1)) - ((y - y2) * (x2 - x1));
30 }
calc_distance(float x1,float y1,float x2,float y2)31 AGG_INLINE float calc_distance(float x1, float y1, float x2, float y2)
32 {
33     float dx = x2 - x1;
34     float dy = y2 - y1;
35     return FXSYS_sqrt2(dx, dy);
36 }
calc_line_point_distance(float x1,float y1,float x2,float y2,float x,float y)37 AGG_INLINE float calc_line_point_distance(float x1, float y1,
38         float x2, float y2,
39         float x,  float y)
40 {
41     float dx = x2 - x1;
42     float dy = y2 - y1;
43     float d = FXSYS_sqrt2(dx, dy);
44     if(d < intersection_epsilon) {
45         return calc_distance(x1, y1, x, y);
46     }
47     return ((x - x2) * dy / d) - ((y - y2) * dx / d);
48 }
calc_intersection(float ax,float ay,float bx,float by,float cx,float cy,float dx,float dy,float * x,float * y)49 AGG_INLINE bool calc_intersection(float ax, float ay, float bx, float by,
50                                   float cx, float cy, float dx, float dy,
51                                   float* x, float* y)
52 {
53   float num = ((ay - cy) * (dx - cx)) - ((ax - cx) * (dy - cy));
54   float den = ((bx - ax) * (dy - cy)) - ((by - ay) * (dx - cx));
55   if (fabs(den) < intersection_epsilon) {
56     return false;
57     }
58     *x = ax + ((bx - ax) * num / den);
59     *y = ay + ((by - ay) * num / den);
60     return true;
61 }
62 }
63 #endif
64