@@ -894,7 +894,15 @@ private static boolean polygonEqualsPolygon_(Polygon polygon_a,
894894 progress_tracker ))
895895 return true ;
896896
897- return linearPathEqualsLinearPath_ (polygon_a , polygon_b , tolerance );
897+ double length_a = polygon_a .calculateLength2D ();
898+ double length_b = polygon_b .calculateLength2D ();
899+ int max_vertices = Math .max (polygon_a .getPointCount (),
900+ polygon_b .getPointCount ());
901+
902+ if (Math .abs (length_a - length_b ) > max_vertices * 4.0 * tolerance )
903+ return false ;
904+
905+ return linearPathEqualsLinearPath_ (polygon_a , polygon_b , tolerance , true );
898906 }
899907
900908 // Returns true if polygon_a is disjoint from polygon_b.
@@ -1264,7 +1272,7 @@ private static boolean polygonEqualsEnvelope_(Polygon polygon_a,
12641272 Polygon polygon_b = new Polygon ();
12651273 polygon_b .addEnvelope (envelope_b , false );
12661274
1267- return linearPathEqualsLinearPath_ (polygon_a , polygon_b , tolerance );
1275+ return linearPathEqualsLinearPath_ (polygon_a , polygon_b , tolerance , true );
12681276 }
12691277
12701278 // Returns true if polygon_a is disjoint from envelope_b.
@@ -1520,7 +1528,7 @@ private static boolean polylineEqualsPolyline_(Polyline polyline_a,
15201528 progress_tracker ))
15211529 return true ;
15221530
1523- return linearPathEqualsLinearPath_ (polyline_a , polyline_b , tolerance );
1531+ return linearPathEqualsLinearPath_ (polyline_a , polyline_b , tolerance , false );
15241532 }
15251533
15261534 // Returns true if polyline_a is disjoint from polyline_b.
@@ -1633,7 +1641,7 @@ private static boolean polylineContainsPolyline_(Polyline polyline_a,
16331641 false ) == Relation .disjoint )
16341642 return false ;
16351643
1636- return linearPathWithinLinearPath_ (polyline_b , polyline_a , tolerance );
1644+ return linearPathWithinLinearPath_ (polyline_b , polyline_a , tolerance , false );
16371645 }
16381646
16391647 // Returns true if polyline_a is disjoint from point_b.
@@ -2127,7 +2135,7 @@ private static boolean polylineContainsEnvelope_(Polyline polyline_a,
21272135 polyline_b .startPath (p );
21282136 envelope_b .queryCornerByVal (2 , p );
21292137 polyline_b .lineTo (p );
2130- return linearPathWithinLinearPath_ (polyline_b , polyline_a , tolerance );
2138+ return linearPathWithinLinearPath_ (polyline_b , polyline_a , tolerance , false );
21312139 }
21322140
21332141 // Returns true if polyline_a crosses envelope_b.
@@ -3405,16 +3413,16 @@ private static boolean multiPointIntersectsMultiPoint_(
34053413
34063414 // Returns true if multipathA equals multipathB.
34073415 private static boolean linearPathEqualsLinearPath_ (MultiPath multipathA ,
3408- MultiPath multipathB , double tolerance ) {
3409- return linearPathWithinLinearPath_ (multipathA , multipathB , tolerance )
3416+ MultiPath multipathB , double tolerance , boolean bEnforceOrientation ) {
3417+ return linearPathWithinLinearPath_ (multipathA , multipathB , tolerance , bEnforceOrientation )
34103418 && linearPathWithinLinearPath_ (multipathB , multipathA ,
3411- tolerance );
3419+ tolerance , bEnforceOrientation );
34123420 }
34133421
34143422 // Returns true if the segments of multipathA are within the segments of
34153423 // multipathB.
34163424 private static boolean linearPathWithinLinearPath_ (MultiPath multipathA ,
3417- MultiPath multipathB , double tolerance ) {
3425+ MultiPath multipathB , double tolerance , boolean bEnforceOrientation ) {
34183426 boolean bWithin = true ;
34193427 double [] scalarsA = new double [2 ];
34203428 double [] scalarsB = new double [2 ];
@@ -3485,7 +3493,7 @@ private static boolean linearPathWithinLinearPath_(MultiPath multipathA,
34853493 int result = segmentA .intersect (segmentB , null , scalarsA ,
34863494 scalarsB , tolerance );
34873495
3488- if (result == 2 ) {
3496+ if (result == 2 && (! bEnforceOrientation || scalarsB [ 0 ] <= scalarsB [ 1 ]) ) {
34893497 double scalar_a_0 = scalarsA [0 ];
34903498 double scalar_a_1 = scalarsA [1 ];
34913499 double scalar_b_0 = scalarsB [0 ];
@@ -3515,7 +3523,7 @@ private static boolean linearPathWithinLinearPath_(MultiPath multipathA,
35153523 result = segmentA .intersect (segmentB , null ,
35163524 scalarsA , scalarsB , tolerance );
35173525
3518- if (result == 2 ) {
3526+ if (result == 2 && (! bEnforceOrientation || scalarsB [ 0 ] <= scalarsB [ 1 ]) ) {
35193527 scalar_a_0 = scalarsA [0 ];
35203528 scalar_a_1 = scalarsA [1 ];
35213529
@@ -3533,7 +3541,7 @@ private static boolean linearPathWithinLinearPath_(MultiPath multipathA,
35333541 null , scalarsA , scalarsB ,
35343542 tolerance );
35353543
3536- if (result == 2 ) {
3544+ if (result == 2 && (! bEnforceOrientation || scalarsB [ 0 ] <= scalarsB [ 1 ]) ) {
35373545 scalar_a_0 = scalarsA [0 ];
35383546 scalar_a_1 = scalarsA [1 ];
35393547
@@ -3642,15 +3650,15 @@ private static boolean linearPathOverlapsLinearPath_(MultiPath multipathA,
36423650
36433651 if (bIntAExtB && !bIntBExtA )
36443652 return !linearPathWithinLinearPath_ (multipathB , multipathA ,
3645- tolerance );
3653+ tolerance , false );
36463654
36473655 if (bIntBExtA && !bIntAExtB )
36483656 return !linearPathWithinLinearPath_ (multipathA , multipathB ,
3649- tolerance );
3657+ tolerance , false );
36503658
3651- return !linearPathWithinLinearPath_ (multipathA , multipathB , tolerance )
3659+ return !linearPathWithinLinearPath_ (multipathA , multipathB , tolerance , false )
36523660 && !linearPathWithinLinearPath_ (multipathB , multipathA ,
3653- tolerance );
3661+ tolerance , false );
36543662 }
36553663
36563664 // Returns true the dimension of intersection of _multipathA and
0 commit comments