private static boolean polylineTouchesEnvelope_ ( Polyline polyline_a , Envelope envelope_b , double tolerance , ProgressTracker progress_tracker ) { Envelope2D env_a = new Envelope2D ( ) , env_b = new Envelope2D ( ) ; polyline_a . queryEnvelope2D ( env_a ) ; envelope_b . queryEnvelope2D ( env_b ) ; if ( env_b . getHeight ( ) <= tolerance && env_b . getWidth ( ) <= tolerance ) { // Treat // as // point Point2D pt_b = envelope_b . getCenterXY ( ) ; return linearPathTouchesPointImpl_ ( polyline_a , pt_b , tolerance ) ; } if ( env_b . getHeight ( ) <= tolerance || env_b . getWidth ( ) <= 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 polylineTouchesPolyline_ ( polyline_a , polyline_b , tolerance , progress_tracker ) ; } // Treat env_b as area SegmentIterator seg_iter_a = polyline_a . querySegmentIterator ( ) ; Envelope2D env_b_deflated = new Envelope2D ( ) , env_b_inflated = new Envelope2D ( ) ; env_b_deflated . setCoords ( env_b ) ; env_b_inflated . setCoords ( env_b ) ; env_b_deflated . inflate ( - tolerance , - tolerance ) ; env_b_inflated . inflate ( tolerance , tolerance ) ; boolean b_boundary = false ; Envelope2D env_segment_a = new Envelope2D ( ) ; Envelope2D env_inter = new Envelope2D ( ) ; while ( seg_iter_a . nextPath ( ) ) { while ( seg_iter_a . hasNextSegment ( ) ) { Segment segment_a = seg_iter_a . nextSegment ( ) ; segment_a . queryEnvelope2D ( env_segment_a ) ; env_inter . setCoords ( env_b_deflated ) ; env_inter . intersect ( env_segment_a ) ; if ( ! env_inter . isEmpty ( ) && ( env_inter . getHeight ( ) > tolerance || env_inter . getWidth ( ) > tolerance ) ) return false ; // consider segment within env_inter . setCoords ( env_b_inflated ) ; env_inter . intersect ( env_segment_a ) ; if ( ! env_inter . isEmpty ( ) ) b_boundary = true ; } } return b_boundary ; }
Returns true if polyline_a touches envelope_b .