Quadrant.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* 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: geom/Quadrant.java rev. 1.8 (JTS-1.10)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Quadrant.h>
#include <geos/geom/Coordinate.h>
#include <geos/util/IllegalArgumentException.h>
#include <string>
#include <sstream>
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
}
}
namespace geos {
namespace geom { // geos.geom
class GEOS_DLL Quadrant {
public:
static const int NE = 0;
static const int NW = 1;
static const int SW = 2;
static const int SE = 3;
static int quadrant(double dx, double dy)
{
if(dx == 0.0 && dy == 0.0) {
std::ostringstream s;
s << "Cannot compute the quadrant for point ";
s << "(" << dx << "," << dy << ")" << std::endl;
throw util::IllegalArgumentException(s.str());
}
if(dx >= 0) {
if(dy >= 0) {
return NE;
}
else {
return SE;
}
}
else {
if(dy >= 0) {
return NW;
}
else {
return SW;
}
}
};
static int quadrant(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1)
{
if(p1.x == p0.x && p1.y == p0.y) {
throw util::IllegalArgumentException("Cannot compute the quadrant for two identical points " + p0.toString());
}
if(p1.x >= p0.x) {
if(p1.y >= p0.y) {
return NE;
}
else {
return SE;
}
}
else {
if(p1.y >= p0.y) {
return NW;
}
else {
return SW;
}
}
};
static double pseudoAngle(const CoordinateXY& p0, const CoordinateXY& p1)
{
const double dx = p1.x - p0.x;
const double dy = p1.y - p0.y;
const double k = dx / (std::abs(dx) + std::abs(dy));
const double w = 2 + (dy > 0 ? 3 - k : 1 + k);
return w >= 4 ? w - 4 : w;
}
static bool isOpposite(int quad1, int quad2)
{
if(quad1 == quad2) {
return false;
}
int diff = (quad1 - quad2 + 4) % 4;
// if quadrants are not adjacent, they are opposite
if(diff == 2) {
return true;
}
return false;
};
/*
* Returns the right-hand quadrant of the halfplane defined by
* the two quadrants,
* or -1 if the quadrants are opposite, or the quadrant if they
* are identical.
*/
static int commonHalfPlane(int quad1, int quad2);
static bool isInHalfPlane(int quad, int halfPlane);
static bool isNorthern(int quad)
{
return quad == NE || quad == NW;
};
};
} // namespace geos.geom
} // namespace geos
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::Quadrant
Utility functions for working with quadrants.
Definition Quadrant.h:52
geos::geom::Quadrant::quadrant
static int quadrant(double dx, double dy)
Definition Quadrant.h:67
geos::geom::Quadrant::isOpposite
static bool isOpposite(int quad1, int quad2)
Definition Quadrant.h:143
geos::geom::Quadrant::quadrant
static int quadrant(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1)
Definition Quadrant.h:98
geos::geom::Quadrant::isInHalfPlane
static bool isInHalfPlane(int quad, int halfPlane)
geos::geom::Quadrant::isNorthern
static bool isNorthern(int quad)
Definition Quadrant.h:173
geos::geom::Quadrant::pseudoAngle
static double pseudoAngle(const CoordinateXY &p0, const CoordinateXY &p1)
Definition Quadrant.h:129
geos::util::IllegalArgumentException
Indicates one or more illegal arguments.
Definition IllegalArgumentException.h:33
geos::geom
Definition Angle.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38