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 committed Oct 10, 2024
1 parent ea22116 commit 321f6fb
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 @@ -2479,8 +2479,10 @@ class CPL_DLL OGRCurvePolygon CPL_NON_FINAL : 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 @@ -2696,8 +2698,9 @@ class CPL_DLL OGRPolygon CPL_NON_FINAL : 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 @@ -75,7 +75,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 @@ -347,13 +347,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 @@ -377,14 +391,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 @@ -263,21 +263,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 321f6fb

Please sign in to comment.