GEOS  3.14.0dev
CGAlgorithmsDD.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2014 Mateusz Loskot <mateusz@loskot.net>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: algorithm/CGAlgorithmsDD.java r789 (JTS-1.14)
16  *
17  **********************************************************************/
18 
19 #pragma once
20 
21 #include <geos/export.h>
22 #include <geos/math/DD.h>
23 
24 // Forward declarations
25 namespace geos {
26 namespace geom {
27 class CoordinateXY;
28 class CoordinateSequence;
29 }
30 }
31 
32 namespace geos {
33 namespace algorithm { // geos::algorithm
34 
36 class GEOS_DLL CGAlgorithmsDD {
37  using DD = geos::math::DD;
38 
39 public:
40 
41  enum {
42  CLOCKWISE = -1,
43  COLLINEAR = 0,
44  COUNTERCLOCKWISE = 1
45  };
46 
47  enum {
48  RIGHT = -1,
49  LEFT = 1,
50  STRAIGHT = 0,
51  FAILURE = 2
52  };
53 
66  static int orientationIndex(const geom::CoordinateXY& p1,
67  const geom::CoordinateXY& p2,
68  const geom::CoordinateXY& q);
69 
70 
71  static int orientationIndex(double p1x, double p1y,
72  double p2x, double p2y,
73  double qx, double qy);
74 
89  static inline int orientationIndexFilter(
90  double pax, double pay,
91  double pbx, double pby,
92  double pcx, double pcy)
93  {
98  double constexpr DP_SAFE_EPSILON = 1e-15;
99 
100  double detsum;
101  double const detleft = (pax - pcx) * (pby - pcy);
102  double const detright = (pay - pcy) * (pbx - pcx);
103  double const det = detleft - detright;
104 
105  if(detleft > 0.0) {
106  if(detright <= 0.0) {
107  return orientation(det);
108  }
109  else {
110  detsum = detleft + detright;
111  }
112  }
113  else if(detleft < 0.0) {
114  if(detright >= 0.0) {
115  return orientation(det);
116  }
117  else {
118  detsum = -detleft - detright;
119  }
120  }
121  else {
122  return orientation(det);
123  }
124 
125  double const errbound = DP_SAFE_EPSILON * detsum;
126  if((det >= errbound) || (-det >= errbound)) {
127  return orientation(det);
128  }
129  return CGAlgorithmsDD::FAILURE;
130  };
131 
132  static int
133  orientation(double x)
134  {
135  if(x < 0) {
136  return CGAlgorithmsDD::RIGHT;
137  }
138  if(x > 0) {
139  return CGAlgorithmsDD::LEFT;
140  }
141  return CGAlgorithmsDD::STRAIGHT;
142  };
143 
153  static geom::CoordinateXY intersection(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2,
154  const geom::CoordinateXY& q1, const geom::CoordinateXY& q2);
155 
156  static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2);
157 
158  static DD detDD(double x1, double y1, double x2, double y2);
159  static DD detDD(const DD& x1, const DD& y1, const DD& x2, const DD& y2);
160 
180  static geom::CoordinateXY circumcentreDD(const geom::CoordinateXY& a, const geom::CoordinateXY& b, const geom::CoordinateXY& c);
181 
182 protected:
183 
184  static int signOfDet2x2(const DD& x1, const DD& y1, const DD& x2, const DD& y2);
185 
186 };
187 
188 } // namespace geos::algorithm
189 } // namespace geos
190 
191 
192 
Implements basic computational geometry algorithms using extended precision float-point arithmetic.
Definition: CGAlgorithmsDD.h:36
static int orientationIndexFilter(double pax, double pay, double pbx, double pby, double pcx, double pcy)
Definition: CGAlgorithmsDD.h:89
static int orientationIndex(const geom::CoordinateXY &p1, const geom::CoordinateXY &p2, const geom::CoordinateXY &q)
Returns the index of the direction of the point q relative to a vector specified by p1-p2.
static geom::CoordinateXY circumcentreDD(const geom::CoordinateXY &a, const geom::CoordinateXY &b, const geom::CoordinateXY &c)
Computes the circumcentre of a triangle.
static geom::CoordinateXY intersection(const geom::CoordinateXY &p1, const geom::CoordinateXY &p2, const geom::CoordinateXY &q1, const geom::CoordinateXY &q2)
Wrapper for DoubleDouble higher precision mathematics operations.
Definition: DD.h:108
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25