@@ -1028,7 +1028,11 @@ private Rectangle getApproximateAreaNeeded(List<int[]> pointsList, List<int[]> p
10281028 rect .width = (int ) Math .max (maxX - minX , MIN_ENCODED_AREA_SIDE );
10291029 rect .height = (int ) Math .max (maxY - minY , MIN_ENCODED_AREA_SIDE );
10301030 rect .x -= (Math .max (rect .x + rect .width - img .dimensionsAsLongArray ()[0 ], 0 ));
1031+ rect .x = Math .max (rect .x , 0 );
1032+ rect .width = (int ) Math .min (rect .width , img .dimensionsAsLongArray ()[0 ]);
10311033 rect .y -= (Math .max (rect .y + rect .height - img .dimensionsAsLongArray ()[1 ], 0 ));
1034+ rect .y = Math .max (rect .y , 0 );
1035+ rect .height = (int ) Math .min (rect .height , img .dimensionsAsLongArray ()[1 ]);
10321036 return rect ;
10331037 }
10341038
@@ -1060,7 +1064,11 @@ private Rectangle getApproximateAreaNeeded(List<int[]> pointsList, List<int[]> p
10601064 rect .width = (int ) Math .max (maxX - minX , MIN_ENCODED_AREA_SIDE );
10611065 rect .height = (int ) Math .max (maxY - minY , MIN_ENCODED_AREA_SIDE );
10621066 rect .x -= (Math .max (rect .x + rect .width - img .dimensionsAsLongArray ()[0 ], 0 ));
1067+ rect .x = Math .max (rect .x , 0 );
1068+ rect .width = (int ) Math .min (rect .width , img .dimensionsAsLongArray ()[0 ]);
10631069 rect .y -= (Math .max (rect .y + rect .height - img .dimensionsAsLongArray ()[1 ], 0 ));
1070+ rect .y = Math .max (rect .y , 0 );
1071+ rect .height = (int ) Math .min (rect .height , img .dimensionsAsLongArray ()[1 ]);
10641072 return rect ;
10651073 }
10661074
0 commit comments