Skip to content

Commit

Permalink
OGRGeometry: Factor isRingCorrectType out of checkRing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston authored and rouault committed Oct 10, 2024
1 parent 868c604 commit fad6dd5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
11 changes: 7 additions & 4 deletions ogr/ogr_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2447,8 +2447,10 @@ class CPL_DLL OGRCurvePolygon : public OGRSurface
private:
OGRBoolean IntersectsPoint(const OGRPoint *p) const;
OGRBoolean ContainsPoint(const OGRPoint *p) const;
virtual bool checkRing(const OGRCurve *poNewRing,
bool bOnlyType = false) const;

virtual bool isRingCorrectType(const OGRCurve *poRing) const;

virtual bool checkRing(const OGRCurve *poNewRing) const;
OGRErr addRingDirectlyInternal(OGRCurve *poCurve, int bNeedRealloc);
static OGRErr addCurveDirectlyFromWkt(OGRGeometry *poSelf,
OGRCurve *poCurve);
Expand Down Expand Up @@ -2664,8 +2666,9 @@ class CPL_DLL OGRPolygon : public OGRCurvePolygon
friend class OGRPolyhedralSurface;
friend class OGRTriangulatedSurface;

virtual bool checkRing(const OGRCurve *poNewRing,
bool bOnlyType = false) const override;
virtual bool isRingCorrectType(const OGRCurve *poRing) const override;

virtual bool checkRing(const OGRCurve *poNewRing) const override;
virtual OGRErr importFromWKTListOnly(const char **ppszInput, int bHasZ,
int bHasM, OGRRawPoint *&paoPoints,
int &nMaxPoints, double *&padfZ);
Expand Down
28 changes: 18 additions & 10 deletions ogr/ogrcurvepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ OGRCurvePolygon &OGRCurvePolygon::operator=(const OGRCurvePolygon &other)

for (const auto *poRing : other.oCC)
{
if (!checkRing(poRing, /* bOnlyType = */ true))
if (!isRingCorrectType(poRing))
{
CPLError(CE_Failure, CPLE_AppDefined,
"Illegal use of OGRCurvePolygon::operator=(): "
Expand Down Expand Up @@ -331,13 +331,27 @@ OGRErr OGRCurvePolygon::addRing(const OGRCurve *poNewRing)
return eErr;
}

/************************************************************************/
/* isRingCorrectType() */
/************************************************************************/
bool OGRCurvePolygon::isRingCorrectType(const OGRCurve *poRing) const
{
return poRing && !EQUAL(poRing->getGeometryName(), "LINEARRING");
}

/************************************************************************/
/* checkRing() */
/************************************************************************/

bool OGRCurvePolygon::checkRing(const OGRCurve *poNewRing, bool bOnlyType) const
bool OGRCurvePolygon::checkRing(const OGRCurve *poNewRing) const
{
if (!bOnlyType && !poNewRing->IsEmpty() && !poNewRing->get_IsClosed())
if (!isRingCorrectType(poNewRing))
{
CPLError(CE_Failure, CPLE_AppDefined, "Linearring not allowed.");
return false;
}

if (!poNewRing->IsEmpty() && !poNewRing->get_IsClosed())
{
// This configuration option name must be the same as in
// OGRPolygon::checkRing()
Expand All @@ -361,14 +375,8 @@ bool OGRCurvePolygon::checkRing(const OGRCurve *poNewRing, bool bOnlyType) const

if (wkbFlatten(poNewRing->getGeometryType()) == wkbLineString)
{
if (!bOnlyType && poNewRing->getNumPoints() < 4)
{
return false;
}

if (EQUAL(poNewRing->getGeometryName(), "LINEARRING"))
if (poNewRing->getNumPoints() < 4)
{
CPLError(CE_Failure, CPLE_AppDefined, "Linearring not allowed.");
return false;
}
}
Expand Down
16 changes: 12 additions & 4 deletions ogr/ogrpolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,29 @@ OGRLinearRing *OGRPolygon::stealInteriorRing(int iRing)
}

/*! @cond Doxygen_Suppress */

/************************************************************************/
/* isRingCorrectType() */
/************************************************************************/
bool OGRPolygon::isRingCorrectType(const OGRCurve *poRing) const
{
return poRing != nullptr && EQUAL(poRing->getGeometryName(), "LINEARRING");
}

/************************************************************************/
/* checkRing() */
/************************************************************************/

bool OGRPolygon::checkRing(const OGRCurve *poNewRing, bool bOnlyType) const
bool OGRPolygon::checkRing(const OGRCurve *poNewRing) const
{
if (poNewRing == nullptr ||
!(EQUAL(poNewRing->getGeometryName(), "LINEARRING")))
if (!isRingCorrectType(poNewRing))
{
CPLError(CE_Failure, CPLE_AppDefined,
"Wrong curve type. Expected LINEARRING.");
return false;
}

if (!bOnlyType && !poNewRing->IsEmpty() && !poNewRing->get_IsClosed())
if (!poNewRing->IsEmpty() && !poNewRing->get_IsClosed())
{
// This configuration option name must be the same as in
// OGRCurvePolygon::checkRing()
Expand Down

0 comments on commit fad6dd5

Please sign in to comment.