Skip to content

Commit abd2d89

Browse files
committed
improve robustness
1 parent ed0aed5 commit abd2d89

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/ai/nets/samj/models/AbstractSamJ.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)