private static boolean polygonTouchesEnvelope_(Polygon polygon_a,
			Envelope envelope_b, double tolerance,
			ProgressTracker progress_tracker) {
		// Quick rasterize test to see whether the the geometries are disjoint,
		// or if one is contained in the other.
		int relation = tryRasterizedContainsOrDisjoint_(polygon_a, envelope_b,
				tolerance, false);

		if (relation == Relation.disjoint || relation == Relation.contains
				|| relation == Relation.within)
			return false;

		Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D();
		polygon_a.queryEnvelope2D(env_a);
		envelope_b.queryEnvelope2D(env_b);

		if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance))
			return false;

		if (env_b.getWidth() <= tolerance && env_b.getHeight() <= tolerance) {// treat
																				// as
																				// point
			Point2D pt_b = envelope_b.getCenterXY();
			return polygonTouchesPointImpl_(polygon_a, pt_b, tolerance,
					progress_tracker);
		}

		if (env_b.getWidth() <= tolerance || env_b.getHeight() <= tolerance) {// treat
																				// as
																				// polyline
			Polyline polyline_b = new Polyline();
			Point p = new Point();
			envelope_b.queryCornerByVal(0, p);
			polyline_b.startPath(p);
			envelope_b.queryCornerByVal(2, p);
			polyline_b.lineTo(p);
			return polygonTouchesPolylineImpl_(polygon_a, polyline_b,
					tolerance, progress_tracker);
		}

		// treat as polygon
		Polygon polygon_b = new Polygon();
		polygon_b.addEnvelope(envelope_b, false);
		return polygonTouchesPolygonImpl_(polygon_a, polygon_b, tolerance,
				progress_tracker);
	}
private static boolean polygonTouchesEnvelope_ ( Polygon polygon_a , Envelope envelope_b , double tolerance , ProgressTracker progress_tracker ) { int relation = tryRasterizedContainsOrDisjoint_ ( polygon_a , envelope_b , tolerance , false ) ; if ( relation == Relation . disjoint || relation == Relation . contains || relation == Relation . within ) return false ; Envelope2D env_a = new Envelope2D ( ) , env_b = new Envelope2D ( ) ; polygon_a . queryEnvelope2D ( env_a ) ; envelope_b . queryEnvelope2D ( env_b ) ; if ( envelopeInfContainsEnvelope_ ( env_b , env_a , tolerance ) ) return false ; if ( env_b . getWidth ( ) <= tolerance && env_b . getHeight ( ) <= tolerance ) { Point2D pt_b = envelope_b . getCenterXY ( ) ; return polygonTouchesPointImpl_ ( polygon_a , pt_b , tolerance , progress_tracker ) ; } if ( env_b . getWidth ( ) <= tolerance || env_b . getHeight ( ) <= tolerance ) { Polyline polyline_b = new Polyline ( ) ; Point p = new Point ( ) ; envelope_b . queryCornerByVal ( 0 , p ) ; polyline_b . startPath ( p ) ; envelope_b . queryCornerByVal ( 2 , p ) ; polyline_b . lineTo ( p ) ; return polygonTouchesPolylineImpl_ ( polygon_a , polyline_b , tolerance , progress_tracker ) ; } Polygon polygon_b = new Polygon ( ) ; polygon_b . addEnvelope ( envelope_b , false ) ; return polygonTouchesPolygonImpl_ ( polygon_a , polygon_b , tolerance , progress_tracker ) ; }
Returns true if polygon_a touches envelope_b.