covers method

bool covers(
  1. Geometry g
)

Tests whether this geometry covers the argument geometry.

The covers predicate has the following equivalent definitions:

  • Every point of the other geometry is a point of this geometry.
  • The DE-9IM Intersection Matrix for the two geometries matches at least one of the following patterns:
    • [T*****FF*]
    • [*T****FF*]
    • [***T**FF*]
    • [****T*FF*]
  • g.coveredBy(this) = true
    (covers is the converse of {@link #coveredBy})
If either geometry is empty, the value of this predicate is false.

This predicate is similar to {@link #contains}, but is more inclusive (i.e. returns true for more cases). In particular, unlike contains it does not distinguish between points in the boundary and in the interior of geometries. For most situations, covers should be used in preference to contains. As an added benefit, covers is more amenable to optimization, and hence should be more performant.

@param g the Geometry with which to compare this Geometry @return true if this Geometry covers g

@see Geometry#contains @see Geometry#coveredBy

Implementation

bool covers(Geometry g) {
  // optimization - lower dimension cannot cover areas
  if (g.getDimension() == 2 && getDimension() < 2) {
    return false;
  }
  // optimization - P cannot cover a non-zero-length L
  // Note that a point can cover a zero-length lineal geometry
  if (g.getDimension() == 1 && getDimension() < 1 && g.getLength() > 0.0) {
    return false;
  }
  // optimization - envelope test
  if (!getEnvelopeInternal().coversEnvelope(g.getEnvelopeInternal()))
    return false;
  // optimization for rectangle arguments
  if (isRectangle()) {
    // since we have already tested that the test envelope is covered
    return true;
  }
  return relate(g).isCovers();
}