touches method

bool touches(
  1. Geometry g
)

Tests whether this geometry touches the argument geometry.

The touches predicate has the following equivalent definitions:

  • The geometries have at least one point in common, but their interiors do not intersect.
  • The DE-9IM Intersection Matrix for the two geometries matches at least one of the following patterns
    • [FT*******]
    • [F**T*****]
    • [F***T****]
If both geometries have dimension 0, the predicate returns false, since points have only interiors. This predicate is symmetric.

@param g the Geometry with which to compare this Geometry @return true if the two Geometrys touch; Returns false if both Geometrys are points

Implementation

bool touches(Geometry g) {
  // short-circuit test
  if (!getEnvelopeInternal().intersectsEnvelope(g.getEnvelopeInternal()))
    return false;
  return relate(g).isTouches(getDimension(), g.getDimension());
}