QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
geomfunction.h
Go to the documentation of this file.
1 /*
2  * libpal - Automated Placement of Labels Library
3  *
4  * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5  * University of Applied Sciences, Western Switzerland
6  * http://www.hes-so.ch
7  *
8  * Contact:
9  * maxence.laurent <at> heig-vd <dot> ch
10  * or
11  * eric.taillard <at> heig-vd <dot> ch
12  *
13  * This file is part of libpal.
14  *
15  * libpal is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * libpal is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #ifndef _GEOM_FUNCTION_
35 #define _GEOM_FUNCTION_
36 
37 #include "util.h"
38 
39 namespace pal
40 {
41 
42  /*
43  * o(x2,y2)
44  * /
45  * cp > 0 /
46  * / cp < 0
47  * /
48  * /
49  * o (x1, y1)
50  */
51  inline double cross_product( double x1, double y1, double x2, double y2, double x3, double y3 )
52  {
53  return ( x2 - x1 ) *( y3 - y1 ) - ( x3 - x1 ) *( y2 - y1 );
54  }
55 
56  inline double dist_euc2d( double x1, double y1, double x2, double y2 )
57  {
58  return sqrt(( x2 - x1 ) *( x2 - x1 ) + ( y2 - y1 ) *( y2 - y1 ) );
59  }
60 
61  inline double dist_euc2d_sq( double x1, double y1, double x2, double y2 )
62  {
63  return ( x2 - x1 ) *( x2 - x1 ) + ( y2 - y1 ) *( y2 - y1 );
64  }
65 
66  bool isPointInPolygon( int npol, double *xp, double *yp, double x, double y );
67  /*
68  // code from Randolph Franklin (found at http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/)
69  int i, j;
70  bool c = false;
71 
72  for (i = 0, j = npol-1; i < npol; j = i++){
73  if ((( (yp[i] <= y) && (y < yp[j])) ||
74  ((yp[j] <= y) && (y < yp[i])))
75  && (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i])){
76  c = !c;
77  }
78  }
79  return c;
80  }*/
81 
82 
83 
84  void findLineCircleIntersection( double cx, double cy, double radius,
85  double x1, double y1, double x2, double y2,
86  double& xRes, double& yRes );
87 
88 
89  int convexHull( int *id, const double* const x, const double* const y, int n );
90 
91 
92  int convexHullId( int *id, const double* const x, const double* const y, int n, int *&cHull );
93 
94  bool isSegIntersects( double x1, double y1, double x2, double y2, // 1st segment
95  double x3, double y3, double x4, double y4 ); // 2nd segment
96 
97  bool computeSegIntersectionExt( double x1, double y1, double x2, double y2, double xs1, double ys1, // 1st (segment)
98  double x3, double y3, double x4, double y4, double xs2, double ys2, // 2nd segment
99  double *x, double *y );
100 
101 
102  /*
103  * \brief Intersection bw a line and a segment
104  * \return true if the point exist false otherwise
105  */
106  bool computeLineSegIntersection( double x1, double y1, double x2, double y2, // 1st line
107  double x3, double y3, double x4, double y4, // 2nd segment
108  double *x, double *y );
109 
110 
111 
112  /*
113  * \brief compute the point wherre two segmentss intersects
114  * \return true if the point exists
115  */
116  bool computeSegIntersection( double x1, double y1, double x2, double y2, // 1st line (segment)
117  double x3, double y3, double x4, double y4, // 2nd line segment
118  double *x, double *y );
119 
120 
121  /*
122  * \brief compute the point wherre two lines intersects
123  * \return true if the ok false if line are parallel
124  */
125  bool computeLineIntersection( double x1, double y1, double x2, double y2, // 1st line (segment)
126  double x3, double y3, double x4, double y4, // 2nd line segment
127  double *x, double *y );
128 
129 #ifdef _EXPORT_MAP_
130 
145  void toSVGPath( int nbPoints, int geomType,
146  double *x, double *y,
147  int dpi, double scale,
148  int xmin, int ymax,
149  char *layername,
150  char *objectID,
151  std::ostream &out );
152 #endif
153 
154  int reorderPolygon( int nbPoints, double *x, double *y );
155 
156 } // end namespace
157 
158 #endif