Skip to content

Commit

Permalink
Lower overhead associated with zeroLengthLine checks, and inline a fe…
Browse files Browse the repository at this point in the history
…w popular methods
  • Loading branch information
pramsey committed Aug 14, 2024
1 parent 5a2afd8 commit 54993f1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 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
7 changes: 7 additions & 0 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) {
// avoid expensive zero-length calculation if not linear
if (getDimension() != Dimension::L)
return false;
return isZeroLength(g);
};

RelatePointLocator* getLocator();

Coordinate::ConstXYSet createUniquePoints();
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
2 changes: 1 addition & 1 deletion 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
20 changes: 6 additions & 14 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 @@ -124,16 +125,7 @@ int
TopologyComputer::getDimension(bool isA) const
{
return getGeometry(isA).getDimension();
}


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


/* public */
Expand Down

0 comments on commit 54993f1

Please sign in to comment.