@@ -255,6 +255,20 @@ public static Rectangle autoScaleDown(Rectangle rect) {
255
255
}
256
256
257
257
public static Rectangle scaleDown (Rectangle rect , int zoom ) {
258
+ if (zoom == 100 || rect == null ) return rect ;
259
+ if (rect instanceof Rectangle .OfFloat rectOfFloat ) return scaleDown (rectOfFloat , zoom );
260
+ Rectangle scaledRect = new Rectangle .OfFloat (0 ,0 ,0 ,0 );
261
+ Point scaledTopLeft = scaleDown (new Point (rect .x , rect .y ), zoom );
262
+ Point scaledBottomRight = scaleDown (new Point (rect .x + rect .width , rect .y + rect .height ), zoom );
263
+
264
+ scaledRect .x = scaledTopLeft .x ;
265
+ scaledRect .y = scaledTopLeft .y ;
266
+ scaledRect .width = scaledBottomRight .x - scaledTopLeft .x ;
267
+ scaledRect .height = scaledBottomRight .y - scaledTopLeft .y ;
268
+ return scaledRect ;
269
+ }
270
+
271
+ public static Rectangle scaleDown (Rectangle .OfFloat rect , int zoom ) {
258
272
return scaleBounds (rect , 100 , zoom );
259
273
}
260
274
/**
@@ -323,6 +337,21 @@ public static boolean isSmoothScalingEnabled() {
323
337
* Returns a new rectangle as per the scaleFactor.
324
338
*/
325
339
public static Rectangle scaleBounds (Rectangle rect , int targetZoom , int currentZoom ) {
340
+ if (rect == null || targetZoom == currentZoom ) return rect ;
341
+ if (rect instanceof Rectangle .OfFloat rectOfFloat ) return scaleBounds (rectOfFloat , targetZoom , currentZoom );
342
+ float scaleFactor = ((float )targetZoom ) / (float )currentZoom ;
343
+ Rectangle returnRect = new Rectangle .OfFloat (0 ,0 ,0 ,0 );
344
+ returnRect .x = Math .round (rect .x * scaleFactor );
345
+ returnRect .y = Math .round (rect .y * scaleFactor );
346
+ returnRect .width = Math .round (rect .width * scaleFactor );
347
+ returnRect .height = Math .round (rect .height * scaleFactor );
348
+ return returnRect ;
349
+ }
350
+
351
+ /**
352
+ * Returns a new rectangle as per the scaleFactor.
353
+ */
354
+ public static Rectangle scaleBounds (Rectangle .OfFloat rect , int targetZoom , int currentZoom ) {
326
355
if (rect == null || targetZoom == currentZoom ) return rect ;
327
356
Rectangle .OfFloat fRect = FloatAwareGeometryFactory .createFrom (rect );
328
357
float scaleFactor = getScalingFactor (targetZoom , currentZoom );
@@ -454,6 +483,20 @@ public static Rectangle autoScaleUp(Rectangle rect) {
454
483
}
455
484
456
485
public static Rectangle scaleUp (Rectangle rect , int zoom ) {
486
+ if (zoom == 100 || rect == null ) return rect ;
487
+ if (rect instanceof Rectangle .OfFloat rectOfFloat ) return scaleUp (rectOfFloat , zoom );
488
+ Rectangle scaledRect = new Rectangle .OfFloat (0 ,0 ,0 ,0 );
489
+ Point scaledTopLeft = scaleUp (new Point (rect .x , rect .y ), zoom );
490
+ Point scaledBottomRight = scaleUp (new Point (rect .x + rect .width , rect .y + rect .height ), zoom );
491
+
492
+ scaledRect .x = scaledTopLeft .x ;
493
+ scaledRect .y = scaledTopLeft .y ;
494
+ scaledRect .width = scaledBottomRight .x - scaledTopLeft .x ;
495
+ scaledRect .height = scaledBottomRight .y - scaledTopLeft .y ;
496
+ return scaledRect ;
497
+ }
498
+
499
+ public static Rectangle scaleUp (Rectangle .OfFloat rect , int zoom ) {
457
500
return scaleBounds (rect , zoom , 100 );
458
501
}
459
502
0 commit comments