/*public*/ bool Geometry::covers(const Geometry* g) const { #ifdef SHORTCIRCUIT_PREDICATES // short-circuit test if (! getEnvelopeInternal()->contains(g->getEnvelopeInternal())) return false; #endif // optimization for rectangle arguments if (isRectangle()) { return getEnvelopeInternal()->contains(g->getEnvelopeInternal()); } auto_ptr<IntersectionMatrix> im(relate(g)); return im->isCovers(); }
bool Polygon::isRectangle() const { if ( getNumInteriorRing() != 0 ) return false; assert(shell!=nullptr); if ( shell->getNumPoints() != 5 ) return false; const CoordinateSequence &seq = *(shell->getCoordinatesRO()); // check vertices have correct values const Envelope &env = *getEnvelopeInternal(); for (int i=0; i<5; i++) { double x = seq.getX(i); if (! (x == env.getMinX() || x == env.getMaxX())) return false; double y = seq.getY(i); if (! (y == env.getMinY() || y == env.getMaxY())) return false; } // check vertices are in right order double prevX = seq.getX(0); double prevY = seq.getY(0); for (int i = 1; i <= 4; i++) { double x = seq.getX(i); double y = seq.getY(i); bool xChanged = (x != prevX); bool yChanged = (y != prevY); if (xChanged == yChanged) return false; prevX = x; prevY = y; } return true; }
bool Geometry::equals(const Geometry *g) const { #ifdef SHORTCIRCUIT_PREDICATES // short-circuit test if (! getEnvelopeInternal()->equals(g->getEnvelopeInternal())) return false; #endif IntersectionMatrix *im=relate(g); bool res=im->isEquals(getDimension(), g->getDimension()); delete im; return res; }
bool Geometry::disjoint(const Geometry *g) const { #ifdef SHORTCIRCUIT_PREDICATES // short-circuit test if (! getEnvelopeInternal()->intersects(g->getEnvelopeInternal())) return true; #endif IntersectionMatrix *im=relate(g); bool res=im->isDisjoint(); delete im; return res; }
Geometry* Geometry::Union(const Geometry *other) const //throw(TopologyException *, IllegalArgumentException *) { checkNotGeometryCollection(this); checkNotGeometryCollection(other); Geometry *out = NULL; #ifdef SHORTCIRCUIT_PREDICATES // if envelopes are disjoint return a MULTI geom or // a geometrycollection if ( ! getEnvelopeInternal()->intersects(other->getEnvelopeInternal()) ) { //cerr<<"SHORTCIRCUITED-UNION engaged"<<endl; const GeometryCollection *coll; size_t ngeoms, i; vector<Geometry *> *v = new vector<Geometry *>(); if ( NULL != (coll = dynamic_cast<const GeometryCollection *>(this)) ) { ngeoms = coll->getNumGeometries(); for (i=0; i<ngeoms; i++) v->push_back(coll->getGeometryN(i)->clone()); } else { v->push_back(this->clone()); } if ( NULL != (coll = dynamic_cast<const GeometryCollection *>(other)) ) { ngeoms = coll->getNumGeometries(); for (i=0; i<ngeoms; i++) v->push_back(coll->getGeometryN(i)->clone()); } else { v->push_back(other->clone()); } out = factory->buildGeometry(v); return out; } #endif return OverlayOp::overlayOp(this, other, OverlayOp::opUNION); }
/** * Tests whether the distance from this <code>Geometry</code> * to another is less than or equal to a specified value. * * @param geom the Geometry to check the distance to * @param cDistance the distance value to compare * @return <code>true</code> if the geometries are less than * <code>distance</code> apart. */ bool Geometry::isWithinDistance(const Geometry *geom,double cDistance) { const Envelope *env0=getEnvelopeInternal(); const Envelope *env1=geom->getEnvelopeInternal(); double envDist=env0->distance(env1); //delete env0; //delete env1; if (envDist>cDistance) { return false; } // NOTE: this could be implemented more efficiently double geomDist=distance(geom); if (geomDist>cDistance) { return false; } return true; }
bool Geometry::contains(const Geometry *g) const { #ifdef SHORTCIRCUIT_PREDICATES // short-circuit test if (! getEnvelopeInternal()->contains(g->getEnvelopeInternal())) return false; #endif // optimization for rectangle arguments if (isRectangle()) { return predicate::RectangleContains::contains((Polygon&)*this, *g); } if (g->isRectangle()) { return predicate::RectangleContains::contains((const Polygon&)*g, *this); } IntersectionMatrix *im=relate(g); bool res=im->isContains(); delete im; return res; }
bool Geometry::intersects(const Geometry *g) const { #ifdef SHORTCIRCUIT_PREDICATES // short-circuit test if (! getEnvelopeInternal()->intersects(g->getEnvelopeInternal())) return false; #endif /** * TODO: (MD) Add optimizations: * * - for P-A case: * If P is in env(A), test for point-in-poly * * - for A-A case: * If env(A1).overlaps(env(A2)) * test for overlaps via point-in-poly first (both ways) * Possibly optimize selection of point to test by finding point of A1 * closest to centre of env(A2). * (Is there a test where we shouldn't bother - e.g. if env A * is much smaller than env B, maybe there's no point in testing * pt(B) in env(A)? */ // optimization for rectangle arguments if (isRectangle()) { return predicate::RectangleIntersects::intersects((Polygon&)*this, *g); } if (g->isRectangle()) { return predicate::RectangleIntersects::intersects((const Polygon&)*g, *this); } IntersectionMatrix *im=relate(g); bool res=im->isIntersects(); delete im; return res; }
Geometry* Geometry::getEnvelope() const { return getFactory()->toGeometry(getEnvelopeInternal()); }