Skip to content

Commit

Permalink
Add CoordinateXY type (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Oct 17, 2022
1 parent cc66726 commit 32348a6
Show file tree
Hide file tree
Showing 88 changed files with 648 additions and 435 deletions.
14 changes: 6 additions & 8 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ typedef struct GEOSContextHandle_HS {
{
memset(msgBuffer, 0, sizeof(msgBuffer));
geomFactory = GeometryFactory::getDefaultInstance();
point2d.reset(geomFactory->createPoint({0, 0}));
point2d = geomFactory->createPoint(geos::geom::CoordinateXY{0, 0});
WKBOutputDims = 2;
WKBByteOrder = getMachineByteOrder();
setNoticeHandler(nullptr);
Expand Down Expand Up @@ -1934,7 +1934,7 @@ extern "C" {
if (radius) *radius = 0.0;
return gf->createPolygon().release();
}
if (center) *center = static_cast<Geometry*>(gf->createPoint(mc.getCentre()));
if (center) *center = gf->createPoint(mc.getCentre()).release();
if (radius) *radius = mc.getRadius();
ret->setSRID(g->getSRID());
return ret.release();
Expand Down Expand Up @@ -2344,9 +2344,7 @@ extern "C" {
return false;
}

double az = g->getCoordinate()->z;

return std::isfinite(az);
return g->getCoordinateDimension() == 3;
});
}

Expand Down Expand Up @@ -2586,7 +2584,7 @@ extern "C" {
GEOSCoordSeq_setXY_r(GEOSContextHandle_t extHandle, CoordinateSequence* cs, unsigned int idx, double x, double y)
{
return execute(extHandle, 0, [&]() {
cs->setAt({x, y}, idx);
cs->setAt(Coordinate{x, y}, idx);
return 1;
});
}
Expand Down Expand Up @@ -3658,8 +3656,8 @@ extern "C" {
if(!point) {
throw std::runtime_error("third argument of GEOSProject_r must be Point");
}
const geos::geom::Coordinate* inputPt = p->getCoordinate();
return geos::linearref::LengthIndexedLine(g).project(*inputPt);
const geos::geom::Coordinate inputPt(*p->getCoordinate());
return geos::linearref::LengthIndexedLine(g).project(inputPt);
});
}

Expand Down
36 changes: 18 additions & 18 deletions include/geos/algorithm/Angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class GEOS_DLL Angle {
/// @return the normalized angle (in radians) that p0-p1 makes
/// with the positive x-axis.
///
static double angle(const geom::Coordinate& p0,
const geom::Coordinate& p1);
static double angle(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1);

/// \brief
/// Returns the angle that the vector from (0,0) to p,
Expand All @@ -86,7 +86,7 @@ class GEOS_DLL Angle {
/// @return the normalized angle (in radians) that p makes
/// with the positive x-axis.
///
static double angle(const geom::Coordinate& p);
static double angle(const geom::CoordinateXY& p);

/// Tests whether the angle between p0-p1-p2 is acute.
///
Expand All @@ -99,9 +99,9 @@ class GEOS_DLL Angle {
/// @param p1 the base of the angle
/// @param p2 the other endpoint of the angle
///
static bool isAcute(const geom::Coordinate& p0,
const geom::Coordinate& p1,
const geom::Coordinate& p2);
static bool isAcute(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2);

/// Tests whether the angle between p0-p1-p2 is obtuse.
///
Expand All @@ -114,9 +114,9 @@ class GEOS_DLL Angle {
/// @param p1 the base of the angle
/// @param p2 the other endpoint of the angle
///
static bool isObtuse(const geom::Coordinate& p0,
const geom::Coordinate& p1,
const geom::Coordinate& p2);
static bool isObtuse(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2);

/// Returns the unoriented smallest angle between two vectors.
///
Expand All @@ -127,9 +127,9 @@ class GEOS_DLL Angle {
/// @param tip2 the tip of the other vector
/// @return the angle between tail-tip1 and tail-tip2
///
static double angleBetween(const geom::Coordinate& tip1,
const geom::Coordinate& tail,
const geom::Coordinate& tip2);
static double angleBetween(const geom::CoordinateXY& tip1,
const geom::CoordinateXY& tail,
const geom::CoordinateXY& tip2);

/// Returns the oriented smallest angle between two vectors.
///
Expand All @@ -143,9 +143,9 @@ class GEOS_DLL Angle {
/// @param tip2 the tip of v2
/// @return the angle between v1 and v2, relative to v1
///
static double angleBetweenOriented(const geom::Coordinate& tip1,
const geom::Coordinate& tail,
const geom::Coordinate& tip2);
static double angleBetweenOriented(const geom::CoordinateXY& tip1,
const geom::CoordinateXY& tail,
const geom::CoordinateXY& tip2);

/// Computes the interior angle between two segments of a ring.
///
Expand All @@ -160,9 +160,9 @@ class GEOS_DLL Angle {
/// the next point of the ring
/// @return the interior angle based at <code>p1</code>
///
static double interiorAngle(const geom::Coordinate& p0,
const geom::Coordinate& p1,
const geom::Coordinate& p2);
static double interiorAngle(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2);

/// \brief
/// Returns whether an angle must turn clockwise or counterclockwise
Expand Down
16 changes: 8 additions & 8 deletions include/geos/algorithm/CGAlgorithmsDD.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
class CoordinateXY;
class CoordinateSequence;
}
}
Expand Down Expand Up @@ -64,9 +64,9 @@ class GEOS_DLL CGAlgorithmsDD {
* @return -1 if q is clockwise (right) from p1-p2
* @return 0 if q is collinear with p1-p2
*/
static int orientationIndex(const geom::Coordinate& p1,
const geom::Coordinate& p2,
const geom::Coordinate& q);
static int orientationIndex(const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2,
const geom::CoordinateXY& q);


static int orientationIndex(double p1x, double p1y,
Expand Down Expand Up @@ -151,8 +151,8 @@ class GEOS_DLL CGAlgorithmsDD {
* @param q2 an endpoint of line segment 2
* @return an intersection point if one exists, or null if the lines are parallel
*/
static geom::Coordinate intersection(const geom::Coordinate& p1, const geom::Coordinate& p2,
const geom::Coordinate& q1, const geom::Coordinate& q2);
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);

Expand All @@ -172,7 +172,7 @@ class GEOS_DLL CGAlgorithmsDD {
*
* This method uses @ref geos::math::DD extended-precision arithmetic to provide more accurate
* results than [circumcentre(Coordinate, Coordinate, Coordinate)]
* (@ref geos::geom::Triangle::circumcentre(const Coordinate& p0, const Coordinate& p1, const Coordinate& p2)).
* (@ref geos::geom::Triangle::circumcentre(const CoordinateXY& p0, const CoordinateXY& p1, const CoordinateXY& p2)).
*
* @param a
* a vertex of the triangle
Expand All @@ -182,7 +182,7 @@ class GEOS_DLL CGAlgorithmsDD {
* a vertex of the triangle
* @return the circumcentre of the triangle
*/
static geom::Coordinate circumcentreDD(const geom::Coordinate& a, const geom::Coordinate& b, const geom::Coordinate& c);
static geom::CoordinateXY circumcentreDD(const geom::CoordinateXY& a, const geom::CoordinateXY& b, const geom::CoordinateXY& c);

protected:

Expand Down
22 changes: 11 additions & 11 deletions include/geos/algorithm/Distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class GEOS_DLL Distance {
* another point of the line (must be different to A)
*/
// formerly distanceLineLine
static double segmentToSegment(const geom::Coordinate& A,
const geom::Coordinate& B,
const geom::Coordinate& C,
const geom::Coordinate& D);
static double segmentToSegment(const geom::CoordinateXY& A,
const geom::CoordinateXY& B,
const geom::CoordinateXY& C,
const geom::CoordinateXY& D);

/**
* Computes the distance from a point to a sequence of line segments.
Expand All @@ -63,7 +63,7 @@ class GEOS_DLL Distance {
* a sequence of contiguous line segments defined by their vertices
* @return the minimum distance between the point and the line segments
*/
static double pointToSegmentString(const geom::Coordinate& p,
static double pointToSegmentString(const geom::CoordinateXY& p,
const geom::CoordinateSequence* seq);

/**
Expand All @@ -80,9 +80,9 @@ class GEOS_DLL Distance {
* @return the distance from p to line segment AB
*/
// formerly distancePointLine
static double pointToSegment(const geom::Coordinate& p,
const geom::Coordinate& A,
const geom::Coordinate& B);
static double pointToSegment(const geom::CoordinateXY& p,
const geom::CoordinateXY& A,
const geom::CoordinateXY& B);

/**
* Computes the perpendicular distance from a point p to the (infinite) line
Expand All @@ -97,9 +97,9 @@ class GEOS_DLL Distance {
* @return the distance from p to line AB
*/
// formerly distancePointLinePerpendicular
static double pointToLinePerpendicular(const geom::Coordinate& p,
const geom::Coordinate& A,
const geom::Coordinate& B);
static double pointToLinePerpendicular(const geom::CoordinateXY& p,
const geom::CoordinateXY& A,
const geom::CoordinateXY& B);

};

Expand Down
2 changes: 1 addition & 1 deletion include/geos/algorithm/LineIntersector.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class GEOS_DLL LineIntersector {
void computeIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);

/// Same as above but doesn't compute intersection point. Faster.
static bool hasIntersection(const geom::Coordinate& p, const geom::Coordinate& p1, const geom::Coordinate& p2);
static bool hasIntersection(const geom::CoordinateXY& p, const geom::CoordinateXY& p1, const geom::CoordinateXY& p2);

enum intersection_type : uint8_t {
/// Indicates that line segments do not intersect
Expand Down
18 changes: 9 additions & 9 deletions include/geos/algorithm/MinimumBoundingCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ class GEOS_DLL MinimumBoundingCircle {

// member variables
const geom::Geometry* input;
std::vector<geom::Coordinate> extremalPts;
geom::Coordinate centre;
std::vector<geom::CoordinateXY> extremalPts;
geom::CoordinateXY centre;
double radius;

void computeCentre();
void compute();
void computeCirclePoints();
geom::Coordinate lowestPoint(std::vector<geom::Coordinate>& pts);
geom::Coordinate pointWitMinAngleWithX(std::vector<geom::Coordinate>& pts, geom::Coordinate& P);
geom::Coordinate pointWithMinAngleWithSegment(std::vector<geom::Coordinate>& pts,
geom::Coordinate& P, geom::Coordinate& Q);
std::vector<geom::Coordinate> farthestPoints(std::vector<geom::Coordinate>& pts);
geom::CoordinateXY lowestPoint(std::vector<geom::CoordinateXY>& pts);
geom::CoordinateXY pointWitMinAngleWithX(std::vector<geom::CoordinateXY>& pts, geom::CoordinateXY& P);
geom::CoordinateXY pointWithMinAngleWithSegment(std::vector<geom::CoordinateXY>& pts,
geom::CoordinateXY& P, geom::CoordinateXY& Q);
std::vector<geom::CoordinateXY> farthestPoints(std::vector<geom::CoordinateXY>& pts);


public:
Expand Down Expand Up @@ -113,15 +113,15 @@ class GEOS_DLL MinimumBoundingCircle {
*
* @return the points defining the Minimum Bounding Circle
*/
std::vector<geom::Coordinate> getExtremalPoints();
std::vector<geom::CoordinateXY> getExtremalPoints();

/**
* Gets the centre point of the computed Minimum Bounding Circle.
*
* @return the centre point of the Minimum Bounding Circle
* @return null if the input is empty
*/
geom::Coordinate getCentre();
geom::CoordinateXY getCentre();

/**
* Gets the radius of the computed Minimum Bounding Circle.
Expand Down
4 changes: 2 additions & 2 deletions include/geos/algorithm/Orientation.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class GEOS_DLL Orientation {
* ( `Orientation::COUNTERCLOCKWISE`,
* `Orientation::CLOCKWISE`, or `Orientation::STRAIGHT` )
*/
static int index(const geom::Coordinate& p1, const geom::Coordinate& p2,
const geom::Coordinate& q);
static int index(const geom::CoordinateXY& p1, const geom::CoordinateXY& p2,
const geom::CoordinateXY& q);

/**
* Computes whether a ring defined by a geom::CoordinateSequence is
Expand Down
10 changes: 5 additions & 5 deletions include/geos/algorithm/PointLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GEOS_DLL PointLocation {
* @return true if the point is a vertex of the line or lies in the interior
* of a line segment in the line
*/
static bool isOnLine(const geom::Coordinate& p, const geom::CoordinateSequence* line);
static bool isOnLine(const geom::CoordinateXY& p, const geom::CoordinateSequence* line);

/** \brief
* Tests whether a point lies inside or on a ring.
Expand All @@ -63,8 +63,8 @@ class GEOS_DLL PointLocation {
*
* @see RayCrossingCounter::locatePointInRing()
*/
static bool isInRing(const geom::Coordinate& p, const std::vector<const geom::Coordinate*>& ring);
static bool isInRing(const geom::Coordinate& p, const geom::CoordinateSequence* ring);
static bool isInRing(const geom::CoordinateXY& p, const std::vector<const geom::Coordinate*>& ring);
static bool isInRing(const geom::CoordinateXY& p, const geom::CoordinateSequence* ring);

/** \brief
* Determines whether a point lies in the interior, on the boundary, or in the
Expand All @@ -78,8 +78,8 @@ class GEOS_DLL PointLocation {
* first point identical to last point)
* @return the [Location](@ref geom::Location) of p relative to the ring
*/
static geom::Location locateInRing(const geom::Coordinate& p, const std::vector<const geom::Coordinate*>& ring);
static geom::Location locateInRing(const geom::Coordinate& p, const geom::CoordinateSequence& ring);
static geom::Location locateInRing(const geom::CoordinateXY& p, const std::vector<const geom::Coordinate*>& ring);
static geom::Location locateInRing(const geom::CoordinateXY& p, const geom::CoordinateSequence& ring);

};

Expand Down
16 changes: 8 additions & 8 deletions include/geos/algorithm/PointLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
class CoordinateXY;
class Geometry;
class LinearRing;
class LineString;
Expand Down Expand Up @@ -66,7 +66,7 @@ class GEOS_DLL PointLocator {
*
* @return the Location of the point relative to the input Geometry
*/
geom::Location locate(const geom::Coordinate& p, const geom::Geometry* geom);
geom::Location locate(const geom::CoordinateXY& p, const geom::Geometry* geom);

/**
* Convenience method to test a point for intersection with
Expand All @@ -77,7 +77,7 @@ class GEOS_DLL PointLocator {
* @return <code>true</code> if the point is in the interior or boundary of the Geometry
*/
bool
intersects(const geom::Coordinate& p, const geom::Geometry* geom)
intersects(const geom::CoordinateXY& p, const geom::Geometry* geom)
{
return locate(p, geom) != geom::Location::EXTERIOR;
}
Expand All @@ -88,17 +88,17 @@ class GEOS_DLL PointLocator {

int numBoundaries; // the number of sub-elements whose boundaries the point lies in

void computeLocation(const geom::Coordinate& p, const geom::Geometry* geom);
void computeLocation(const geom::CoordinateXY& p, const geom::Geometry* geom);

void updateLocationInfo(geom::Location loc);

geom::Location locate(const geom::Coordinate& p, const geom::Point* pt);
geom::Location locate(const geom::CoordinateXY& p, const geom::Point* pt);

geom::Location locate(const geom::Coordinate& p, const geom::LineString* l);
geom::Location locate(const geom::CoordinateXY& p, const geom::LineString* l);

geom::Location locateInPolygonRing(const geom::Coordinate& p, const geom::LinearRing* ring);
geom::Location locateInPolygonRing(const geom::CoordinateXY& p, const geom::LinearRing* ring);

geom::Location locate(const geom::Coordinate& p, const geom::Polygon* poly);
geom::Location locate(const geom::CoordinateXY& p, const geom::Polygon* poly);

};

Expand Down
Loading

0 comments on commit 32348a6

Please sign in to comment.