Skip to content

Commit

Permalink
Avoid overhead in zeroLenLine tests for non-line features. Some inlin…
Browse files Browse the repository at this point in the history
…eing of trivial accessors.
  • Loading branch information
pramsey committed Aug 15, 2024
1 parent e8e3e25 commit 1821b67
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 103 deletions.
2 changes: 1 addition & 1 deletion include/geos/algorithm/CGAlgorithmsDD.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class GEOS_DLL CGAlgorithmsDD {
*
* Uses an approach due to Jonathan Shewchuk, which is in the public domain.
*/
static int orientationIndexFilter(
static inline int orientationIndexFilter(
double pax, double pay,
double pbx, double pby,
double pcx, double pcy)
Expand Down
40 changes: 31 additions & 9 deletions include/geos/operation/relateng/RelateGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class GEOS_DLL RelateGeometry {

static bool isZeroLength(const LineString* line);

bool isZeroLengthLine(const Geometry* g) const {
// avoid expensive zero-length calculation if not linear
if (getDimension() != Dimension::L)
return false;
return isZeroLength(g);
};

RelatePointLocator* getLocator();

Coordinate::ConstXYSet createUniquePoints();
Expand Down Expand Up @@ -141,15 +148,30 @@ class GEOS_DLL RelateGeometry {

static std::string name(bool isA);

const Geometry* getGeometry() const;

bool isPrepared() const;

const Envelope* getEnvelope() const;

int getDimension() const;

bool hasDimension(int dim) const;
const Geometry* getGeometry() const {
return geom;
}

bool isPrepared() const {
return m_isPrepared;
}

const Envelope* getEnvelope() const {
return geomEnv;
}

inline int getDimension() const {
return geomDim;
}

bool hasDimension(int dim) const {
switch (dim) {
case Dimension::P: return hasPoints;
case Dimension::L: return hasLines;
case Dimension::A: return hasAreas;
}
return false;
}

/**
* Gets the actual non-empty dimension of the geometry.
Expand Down
12 changes: 9 additions & 3 deletions include/geos/operation/relateng/RelateSegmentString.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ class GEOS_DLL RelateSegmentString : public BasicSegmentString {
bool isA, int elementId, int ringId,
const Geometry* poly, const RelateGeometry* parent);

bool isA() const;
inline bool isA() const {
return m_isA;
}

const RelateGeometry* getGeometry() const;
inline const RelateGeometry* getGeometry() const {
return m_inputGeom;
}

const Geometry* getPolygonal() const;
inline const Geometry* getPolygonal() const {
return m_parentPolygonal;
}

NodeSection* createNodeSection(std::size_t segIndex, const CoordinateXY intPt) const;

Expand Down
24 changes: 13 additions & 11 deletions include/geos/operation/relateng/TopologyComputer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class GEOS_DLL TopologyComputer {

void initExteriorEmpty(bool geomNonEmpty);

RelateGeometry& getGeometry(bool isA) const;
inline RelateGeometry& getGeometry(bool isA) const {
return isA ? geomA : geomB;
};

void updateDim(Location locA, Location locB, int dimension);

Expand Down Expand Up @@ -135,16 +137,16 @@ class GEOS_DLL TopologyComputer {

public:

TopologyComputer(
TopologyPredicate& p_predicate,
RelateGeometry& p_geomA,
RelateGeometry& p_geomB)
: predicate(p_predicate)
, geomA(p_geomA)
, geomB(p_geomB)
{
initExteriorDims();
};
TopologyComputer(
TopologyPredicate& p_predicate,
RelateGeometry& p_geomA,
RelateGeometry& p_geomB)
: predicate(p_predicate)
, geomA(p_geomA)
, geomB(p_geomB)
{
initExteriorDims();
};

int getDimension(bool isA) const;

Expand Down
44 changes: 2 additions & 42 deletions src/operation/relateng/RelateGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RelateGeometry::RelateGeometry(const Geometry* input, bool isPrepared, const Bou
, geomEnv(input->getEnvelopeInternal())
, boundaryNodeRule(bnRule)
, geomDim(input->getDimension())
, isLineZeroLen(isZeroLength(input))
, isLineZeroLen(isZeroLengthLine(input))
, isGeomEmpty(input->isEmpty())
{
analyzeDimensions();
Expand Down Expand Up @@ -154,47 +154,6 @@ RelateGeometry::isZeroLength(const LineString* line) {
}


/* public */
const Geometry*
RelateGeometry::getGeometry() const
{
return geom;
}

/* public */
bool
RelateGeometry::isPrepared() const
{
return m_isPrepared;
}

/* public */
const Envelope*
RelateGeometry::getEnvelope() const
{
return geomEnv;
}

/* public */
int
RelateGeometry::getDimension() const
{
return geomDim;
}

/* public */
bool
RelateGeometry::hasDimension(int dim) const
{
switch (dim) {
case Dimension::P: return hasPoints;
case Dimension::L: return hasLines;
case Dimension::A: return hasAreas;
}
return false;
}


/* public */
int
RelateGeometry::getDimensionReal() const
Expand All @@ -210,6 +169,7 @@ RelateGeometry::getDimensionReal() const
return Dimension::P;
}


/* public */
bool
RelateGeometry::hasEdges() const
Expand Down
24 changes: 0 additions & 24 deletions src/operation/relateng/RelateSegmentString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,6 @@ RelateSegmentString::createSegmentString(
}


/* public */
bool
RelateSegmentString::isA() const
{
return m_isA;
}


/* public */
const RelateGeometry*
RelateSegmentString::getGeometry() const
{
return m_inputGeom;
}


/* public */
const Geometry*
RelateSegmentString::getPolygonal() const
{
return m_parentPolygonal;
}


/* public */
NodeSection*
RelateSegmentString::createNodeSection(std::size_t segIndex, const CoordinateXY intPt) const
Expand Down
18 changes: 5 additions & 13 deletions src/operation/relateng/TopologyComputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ TopologyComputer::initExteriorEmpty(bool geomNonEmpty)
}


/* private */
RelateGeometry&
TopologyComputer::getGeometry(bool isA) const
/* public */
bool
TopologyComputer::isAreaArea() const
{
return isA ? geomA : geomB;
return getDimension(RelateGeometry::GEOM_A) == Dimension::A
&& getDimension(RelateGeometry::GEOM_B) == Dimension::A;
}


Expand All @@ -127,15 +128,6 @@ TopologyComputer::getDimension(bool isA) const
}


/* public */
bool
TopologyComputer::isAreaArea() const
{
return getDimension(RelateGeometry::GEOM_A) == Dimension::A
&& getDimension(RelateGeometry::GEOM_B) == Dimension::A;
}


/* public */
bool
TopologyComputer::isSelfNodingRequired() const
Expand Down

0 comments on commit 1821b67

Please sign in to comment.