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