within method

bool within(
  1. Geometry g
)

Tests whether this geometry is within the specified geometry.

The within predicate has the following equivalent definitions:

  • Every point of this geometry is a point of the other geometry, and the interiors of the two geometries have at least one point in common.
  • The DE-9IM Intersection Matrix for the two geometries matches [T*F**F***]
  • g.contains(this) = true
    (within is the converse of {@link #contains})
An implication of the definition is that "The boundary of a Geometry is not within the Geometry". In other words, if a geometry A is a subset of the points in the boundary of a geometry B, A.within(B) = false (As a concrete example, take A to be a LineString which lies in the boundary of a Polygon B.) For a predicate with similar behaviour but avoiding this subtle limitation, see {@link #coveredBy}.

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

@see Geometry#contains @see Geometry#coveredBy

Implementation

bool within(Geometry g) {
  return g.contains(this);
}