Skip to content

Commit

Permalink
Point: Make getCoordinate() return CoordinateXY
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Jan 18, 2023
1 parent 3a9eab8 commit 2a4461d
Show file tree
Hide file tree
Showing 24 changed files with 64 additions and 73 deletions.
6 changes: 3 additions & 3 deletions include/geos/algorithm/InteriorPointPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GEOS_DLL InteriorPointPoint {

bool hasInterior;

geom::Coordinate centroid;
geom::CoordinateXY centroid;

double minDistance;

Expand All @@ -55,15 +55,15 @@ class GEOS_DLL InteriorPointPoint {
*/
void add(const geom::Geometry* geom);

void add(const geom::Coordinate* point);
void add(const geom::CoordinateXY* point);

public:

InteriorPointPoint(const geom::Geometry* g);

~InteriorPointPoint() {}

bool getInteriorPoint(geom::Coordinate& ret) const;
bool getInteriorPoint(geom::CoordinateXY& ret) const;

};

Expand Down
2 changes: 1 addition & 1 deletion include/geos/geom/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ class GEOS_DLL Geometry {
//
/// Returns false if centroid cannot be computed (EMPTY geometry)
///
virtual bool getCentroid(Coordinate& ret) const;
virtual bool getCentroid(CoordinateXY& ret) const;

/** \brief
* Computes an interior point of this <code>Geometry</code>.
Expand Down
4 changes: 2 additions & 2 deletions include/geos/geom/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class GEOS_DLL Point : public Geometry {
geometryChangedAction();
}

const Coordinate* getCoordinate() const override {
return isEmpty() ? nullptr : &coordinates[0];
const CoordinateXY* getCoordinate() const override {
return isEmpty() ? nullptr : &coordinates.getAt<CoordinateXY>(0);
}

double getX() const;
Expand Down
2 changes: 1 addition & 1 deletion include/geos/io/GeoJSONWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class GEOS_DLL GeoJSONWriter {

private:

std::pair<double, double> convertCoordinate(const geom::Coordinate* c);
std::pair<double, double> convertCoordinate(const geom::CoordinateXY* c);

std::vector<std::pair<double, double>> convertCoordinateSequence(const geom::CoordinateSequence* c);

Expand Down
2 changes: 1 addition & 1 deletion include/geos/operation/predicate/RectangleContains.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GEOS_DLL RectangleContains {
* @param pt the point to test
* @return true if the point is contained in the boundary
*/
bool isPointContainedInBoundary(const geom::Coordinate& pt);
bool isPointContainedInBoundary(const geom::CoordinateXY& pt);

/** \brief
* Tests if a linestring is completely contained in the boundary
Expand Down
12 changes: 6 additions & 6 deletions include/geos/operation/valid/IsSimpleOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class GEOS_DLL IsSimpleOp {
bool isClosedEndpointsInInterior = true;
bool isFindAllLocations = false;
bool isSimpleResult = false;
std::vector<geom::Coordinate> nonSimplePts;
std::vector<geom::CoordinateXY> nonSimplePts;
bool computed = false;

void compute();
Expand Down Expand Up @@ -143,7 +143,7 @@ class GEOS_DLL IsSimpleOp {
bool isClosedEndpointsInInterior;
bool isFindAll = false;

std::vector<geom::Coordinate>& intersectionPts;
std::vector<geom::CoordinateXY>& intersectionPts;
algorithm::LineIntersector li;

// bool hasInteriorInt;
Expand Down Expand Up @@ -186,7 +186,7 @@ class GEOS_DLL IsSimpleOp {
NonSimpleIntersectionFinder(
bool p_isClosedEndpointsInInterior,
bool p_isFindAll,
std::vector<geom::Coordinate>& p_intersectionPts)
std::vector<geom::CoordinateXY>& p_intersectionPts)
: isClosedEndpointsInInterior(p_isClosedEndpointsInInterior)
, isFindAll(p_isFindAll)
, intersectionPts(p_intersectionPts)
Expand Down Expand Up @@ -255,7 +255,7 @@ class GEOS_DLL IsSimpleOp {
* @param geom the input geometry
* @return a non-simple location, or null if the geometry is simple
*/
geom::Coordinate getNonSimpleLocation(const geom::Geometry& geom);
geom::CoordinateXY getNonSimpleLocation(const geom::Geometry& geom);

/**
* Sets whether all non-simple intersection points
Expand All @@ -280,14 +280,14 @@ class GEOS_DLL IsSimpleOp {
* @return a coordinate for the location of the non-boundary self-intersection
* or null if the geometry is simple
*/
geom::Coordinate getNonSimpleLocation();
geom::CoordinateXY getNonSimpleLocation();

/**
* Gets all non-simple intersection locations.
*
* @return a list of the coordinates of non-simple locations
*/
const std::vector<geom::Coordinate>& getNonSimpleLocations();
const std::vector<geom::CoordinateXY>& getNonSimpleLocations();



Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/InteriorPointPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ InteriorPointPoint::add(const Geometry* geom)

/*private*/
void
InteriorPointPoint::add(const Coordinate* point)
InteriorPointPoint::add(const CoordinateXY* point)
{
assert(point); // we wouldn't been called if this was an empty geom
double dist = point->distance(centroid);
Expand All @@ -75,7 +75,7 @@ InteriorPointPoint::add(const Coordinate* point)

/*public*/
bool
InteriorPointPoint::getInteriorPoint(Coordinate& ret) const
InteriorPointPoint::getInteriorPoint(CoordinateXY& ret) const
{
if (! hasInterior) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/PointLocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Location
PointLocator::locate(const CoordinateXY& p, const Point* pt)
{
// no point in doing envelope test, since equality test is just as fast
const Coordinate* ptCoord = pt->getCoordinate();
const CoordinateXY* ptCoord = pt->getCoordinate();
if(ptCoord != nullptr && ptCoord->equals2D(p)) {
return Location::INTERIOR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/geom/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Geometry::getCentroid() const

/*public*/
bool
Geometry::getCentroid(Coordinate& ret) const
Geometry::getCentroid(CoordinateXY& ret) const
{
if(isEmpty()) {
return false;
Expand Down
11 changes: 2 additions & 9 deletions src/geom/Point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Point::getZ() const
if(isEmpty()) {
throw util::UnsupportedOperationException("getZ called on empty Point\n");
}
return getCoordinate()->z;
return coordinates.getAt<Coordinate>(0).z;
}

std::string
Expand Down Expand Up @@ -198,18 +198,12 @@ Point::computeEnvelopeInternal() const
void
Point::apply_ro(CoordinateFilter* filter) const
{
if(isEmpty()) {
return;
}
filter->filter_ro(getCoordinate());
coordinates.apply_ro(filter);
}

void
Point::apply_rw(const CoordinateFilter* filter)
{
if (isEmpty()) {
return;
}
coordinates.apply_rw(filter);
}

Expand Down Expand Up @@ -256,7 +250,6 @@ Point::apply_ro(CoordinateSequenceFilter& filter) const
return;
}
filter.filter_ro(coordinates, 0);
//if (filter.isGeometryChanged()) geometryChanged();
}

bool
Expand Down
2 changes: 1 addition & 1 deletion src/geom/util/GeometryFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ GeometryFixer::fixPointElement(const Point* p_geom) const
bool
GeometryFixer::isValidPoint(const Point* pt) const
{
const Coordinate* p = pt->getCoordinate();
const CoordinateXY* p = pt->getCoordinate();
return p->isValid();
}

Expand Down
2 changes: 1 addition & 1 deletion src/geomgraph/GeometryGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ GeometryGraph::addCollection(const GeometryCollection* gc)
void
GeometryGraph::addPoint(const Point* p)
{
const Coordinate& coord = *(p->getCoordinate());
const Coordinate& coord = p->getCoordinatesRO()->getAt(0);
insertPoint(argIndex, coord, Location::INTERIOR);
}

Expand Down
2 changes: 1 addition & 1 deletion src/io/GeoJSONWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void GeoJSONWriter::encodeGeometryCollection(const geom::GeometryCollection* g,
j["geometries"] = geometryArray;
}

std::pair<double, double> GeoJSONWriter::convertCoordinate(const Coordinate* c)
std::pair<double, double> GeoJSONWriter::convertCoordinate(const CoordinateXY* c)
{
return std::make_pair(c->x, c->y);
}
Expand Down
2 changes: 1 addition & 1 deletion src/operation/distance/DistanceOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ DistanceOp::computeMinDistance(const LineString* line,
return;
}
const CoordinateSequence* coord0 = line->getCoordinatesRO();
const Coordinate* coord = pt->getCoordinate();
const CoordinateXY* coord = pt->getCoordinate();

// brute force approach!
std::size_t npts0 = coord0->getSize();
Expand Down
2 changes: 1 addition & 1 deletion src/operation/overlayng/OverlayPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct PointExtractingFilter: public GeometryComponentFilter {
static Coordinate
roundCoord(const Point* pt, const PrecisionModel* p_pm)
{
const Coordinate* p = pt->getCoordinate();
const Coordinate* p = static_cast<const Coordinate*>(pt->getCoordinate());
if (OverlayUtil::isFloating(p_pm))
return *p;
Coordinate p2 = *p;
Expand Down
3 changes: 1 addition & 2 deletions src/operation/overlayng/OverlayUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ bool
OverlayUtil::round(const Point* pt, const PrecisionModel* pm, Coordinate& rsltCoord)
{
if (pt->isEmpty()) return false;
const Coordinate* p = pt->getCoordinate();
rsltCoord = *p;
pt->getCoordinatesRO()->getAt(0, rsltCoord);
if (! isFloating(pm)) {
pm->makePrecise(rsltCoord);
}
Expand Down
2 changes: 1 addition & 1 deletion src/operation/predicate/RectangleContains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ RectangleContains::isPointContainedInBoundary(const Point& point)

/*private*/
bool
RectangleContains::isPointContainedInBoundary(const Coordinate& pt)
RectangleContains::isPointContainedInBoundary(const CoordinateXY& pt)
{
/**
* contains = false iff the point is properly contained
Expand Down
2 changes: 1 addition & 1 deletion src/operation/union/PointGeometryUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PointGeometryUnion::Union() const
for(std::size_t i = 0, n = pointGeom.getNumGeometries(); i < n; ++i) {
const Point* point = dynamic_cast<const Point*>(pointGeom.getGeometryN(i));
assert(point);
const Coordinate* coord = point->getCoordinate();
const Coordinate* coord = static_cast<const Coordinate*>(point->getCoordinate());
Location loc = locater.locate(*coord, &otherGeom);
if(loc == Location::EXTERIOR) {
exteriorCoords.insert(*coord);
Expand Down
14 changes: 7 additions & 7 deletions src/operation/valid/IsSimpleOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ IsSimpleOp::isSimple(const Geometry& geom)
}

/* public static */
Coordinate
CoordinateXY
IsSimpleOp::getNonSimpleLocation(const Geometry& geom)
{
IsSimpleOp op(geom);
Expand All @@ -78,21 +78,21 @@ IsSimpleOp::isSimple()
}

/* public */
Coordinate
CoordinateXY
IsSimpleOp::getNonSimpleLocation()
{
compute();
if (nonSimplePts.size() == 0) {
Coordinate c;
CoordinateXY c;
c.setNull();
return c;
}
return nonSimplePts.at(0);
return nonSimplePts[0];
}


/* public */
const std::vector<Coordinate>&
const std::vector<CoordinateXY>&
IsSimpleOp::getNonSimpleLocations()
{
compute();
Expand Down Expand Up @@ -141,11 +141,11 @@ IsSimpleOp::isSimpleMultiPoint(const MultiPoint& mp)
{
if (mp.isEmpty()) return true;
bool bIsSimple = true;
std::unordered_set<Coordinate, Coordinate::HashCode> points;
std::unordered_set<CoordinateXY, Coordinate::HashCode> points;

for (std::size_t i = 0; i < mp.getNumGeometries(); i++) {
const Point* pt = mp.getGeometryN(i);
const Coordinate* p = pt->getCoordinate();
const CoordinateXY* p = pt->getCoordinate();
if (points.find(*p) != points.end()) {
nonSimplePts.push_back(*p);
bIsSimple = false;
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/algorithm/construct/LargestEmptyCircleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ struct test_lec_data {
double tolerance = 2*build_tolerance;
LargestEmptyCircle lec(geom, tolerance);
std::unique_ptr<Point> centerPoint = lec.getCenter();
const Coordinate* centerPt = centerPoint->getCoordinate();
Coordinate centerPt(*centerPoint->getCoordinate());
Coordinate expectedCenter(x, y);
ensure_equals_coordinate(*centerPt, expectedCenter, tolerance);
ensure_equals_coordinate(centerPt, expectedCenter, tolerance);
std::unique_ptr<LineString> radiusLine = lec.getRadiusLine();
double actualRadius = radiusLine->getLength();
ensure_equals("radius", actualRadius, expectedRadius, tolerance);
Expand All @@ -80,8 +80,8 @@ struct test_lec_data {
// std::cout << writer_.write(geom) << std::endl;
// std::cout << writer_.write(radiusLine.get()) << std::endl;

ensure_equals_coordinate(*centerPt, linePt0, tolerance);
const Coordinate radiusPt = *lec.getRadiusPoint()->getCoordinate();
ensure_equals_coordinate(centerPt, linePt0, tolerance);
Coordinate radiusPt(*lec.getRadiusPoint()->getCoordinate());
ensure_equals_coordinate(radiusPt, linePt1, tolerance);
}

Expand All @@ -90,16 +90,16 @@ struct test_lec_data {
{
LargestEmptyCircle lec(geom, tolerance);
std::unique_ptr<Point> centerPoint = lec.getCenter();
const Coordinate* centerPt = centerPoint->getCoordinate();
Coordinate centerPt(*centerPoint->getCoordinate());
std::unique_ptr<LineString> radiusLine = lec.getRadiusLine();
double actualRadius = radiusLine->getLength();
ensure_equals("radius", actualRadius, 0.0, tolerance);

const Coordinate& linePt0 = radiusLine->getCoordinateN(0);
const Coordinate& linePt1 = radiusLine->getCoordinateN(1);

ensure_equals_coordinate(*centerPt, linePt0, tolerance);
const Coordinate radiusPt = *lec.getRadiusPoint()->getCoordinate();
ensure_equals_coordinate(centerPt, linePt0, tolerance);
Coordinate radiusPt(*lec.getRadiusPoint()->getCoordinate());
ensure_equals_coordinate(radiusPt, linePt1, tolerance);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/algorithm/construct/MaximumInscribedCircleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ struct test_mic_data {
double tolerance = 2*build_tolerance;
MaximumInscribedCircle mic(geom, tolerance);
std::unique_ptr<Point> centerPoint = mic.getCenter();
const Coordinate* centerPt = centerPoint->getCoordinate();
Coordinate centerPt(*centerPoint->getCoordinate());
Coordinate expectedCenter(x, y);
ensure_equals_coordinate(*centerPt, expectedCenter, tolerance);
ensure_equals_coordinate(centerPt, expectedCenter, tolerance);
std::unique_ptr<LineString> radiusLine = mic.getRadiusLine();
double actualRadius = radiusLine->getLength();
ensure_equals("radius", actualRadius, expectedRadius, tolerance);
Expand All @@ -78,8 +78,8 @@ struct test_mic_data {
// std::cout << writer_.write(geom) << std::endl;
// std::cout << writer_.write(radiusLine.get()) << std::endl;

ensure_equals_coordinate(*centerPt, linePt0, tolerance);
const Coordinate radiusPt = *mic.getRadiusPoint()->getCoordinate();
ensure_equals_coordinate(centerPt, linePt0, tolerance);
Coordinate radiusPt(*mic.getRadiusPoint()->getCoordinate());
ensure_equals_coordinate(radiusPt, linePt1, tolerance);
}

Expand Down
Loading

0 comments on commit 2a4461d

Please sign in to comment.