CGAlgorithmsDD.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2014 Mateusz Loskot <mateusz@loskot.net>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: algorithm/CGAlgorithmsDD.java r789 (JTS-1.14)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/math/DD.h>
#include <cmath>
// Forward declarations
namespace geos {
namespace geom {
class CoordinateXY;
class CoordinateSequence;
}
}
namespace geos {
namespace algorithm { // geos::algorithm
class GEOS_DLL CGAlgorithmsDD {
using DD = geos::math::DD;
public:
enum {
CLOCKWISE = -1,
COLLINEAR = 0,
COUNTERCLOCKWISE = 1
};
enum {
RIGHT = -1,
LEFT = 1,
STRAIGHT = 0,
FAILURE = 2
};
static int orientationIndex(const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2,
const geom::CoordinateXY& q);
static int orientationIndex(double p1x, double p1y,
double p2x, double p2y,
double qx, double qy);
static inline int orientationIndexFilter(
double pax, double pay,
double pbx, double pby,
double pcx, double pcy)
{
double const detleft = (pax - pcx) * (pby - pcy);
double const detright = (pay - pcy) * (pbx - pcx);
double const det = detleft - detright;
// Coefficient as per Ozaki et al
double const error = std::abs(detleft + detright)
* 3.3306690621773724e-16;
if (std::abs(det) >= error)
return (det > 0) - (det < 0);
return CGAlgorithmsDD::FAILURE;
};
static int
orientation(double x)
{
if(x < 0) {
return CGAlgorithmsDD::RIGHT;
}
if(x > 0) {
return CGAlgorithmsDD::LEFT;
}
return CGAlgorithmsDD::STRAIGHT;
};
static geom::CoordinateXY intersection(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2,
const geom::CoordinateXY& q1, const geom::CoordinateXY& q2);
static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2);
static DD detDD(double x1, double y1, double x2, double y2);
static DD detDD(const DD& x1, const DD& y1, const DD& x2, const DD& y2);
static geom::CoordinateXY circumcentreDD(const geom::CoordinateXY& a, const geom::CoordinateXY& b, const geom::CoordinateXY& c);
protected:
static int signOfDet2x2(const DD& x1, const DD& y1, const DD& x2, const DD& y2);
};
} // namespace geos::algorithm
} // namespace geos
geos::algorithm::CGAlgorithmsDD
Implements basic computational geometry algorithms using extended precision float-point arithmetic.
Definition CGAlgorithmsDD.h:37
geos::algorithm::CGAlgorithmsDD::orientationIndexFilter
static int orientationIndexFilter(double pax, double pay, double pbx, double pby, double pcx, double pcy)
Definition CGAlgorithmsDD.h:97
geos::algorithm::CGAlgorithmsDD::orientationIndex
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.
geos::algorithm::CGAlgorithmsDD::circumcentreDD
static geom::CoordinateXY circumcentreDD(const geom::CoordinateXY &a, const geom::CoordinateXY &b, const geom::CoordinateXY &c)
Computes the circumcentre of a triangle.
geos::algorithm::CGAlgorithmsDD::intersection
static geom::CoordinateXY intersection(const geom::CoordinateXY &p1, const geom::CoordinateXY &p2, const geom::CoordinateXY &q1, const geom::CoordinateXY &q2)
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::math::DD
Wrapper for DoubleDouble higher precision mathematics operations.
Definition DD.h:108
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38