AdjustBounds { public static void clean(@NonNull Bounds b, @NonNull Bounds inner, @NonNull Bounds outer) { if (Double.isNaN(b.x.min)) b.x.min = inner.x.min; if (Double.isNaN(b.y.max)) b.y.max = inner.y.max; if (Double.isNaN(b.x.max)) b.x.max = inner.x.max; if (Double.isNaN(b.y.min)) b.y.min = inner.y.min; if (Double.isInfinite(b.x.min)) b.x.min = 0; if (Double.isInfinite(b.y.max)) b.y.max = 1; if (Double.isInfinite(b.x.max)) b.x.max = 1; if (Double.isInfinite(b.y.min)) b.y.min = 0; if (b.x.min > inner.x.min) b.x.min = inner.x.min; if (b.x.min < outer.x.min) b.x.min = outer.x.min; if (b.y.max < inner.y.max) b.y.max = inner.y.max; if (b.y.max > outer.y.max) b.y.max = outer.y.max; if (b.x.max < inner.x.max) b.x.max = inner.x.max; if (b.x.max > outer.x.max) b.x.max = outer.x.max; if (b.y.min > inner.y.min) b.y.min = inner.y.min; if (b.y.min < outer.y.min) b.y.min = outer.y.min; if (b.x.max < b.x.min) { final double tmp = b.x.max; b.x.max = b.x.min; b.x.min = tmp; } if (b.y.max < b.y.min) { final double tmp = b.y.max; b.y.max = b.y.min; b.y.min = tmp; } if (b.x.max - b.x.min < EPSILON) { b.x.min -= EPSILON / 2; b.x.max += EPSILON / 2; } if (b.y.max - b.y.min < EPSILON) { b.y.min -= EPSILON / 2; b.y.max += EPSILON / 2; } }  static void clean(@NonNull Bounds b, @NonNull Bounds inner, @NonNull Bounds outer); static void squareBounds(@NonNull Bounds b, int width, int height, @NonNull IntBounds padding);  }
@Test public void cleanBounds() { Bounds bounds = new Bounds(); Bounds min = new Bounds(); min.set(-1, 1, 1, -1); Bounds max = new Bounds(); max.set(-2, 2, 2, -2); AdjustBounds.clean(bounds, min, max); assertEquals(-1, bounds.x.min, 0.01); assertEquals(1, bounds.y.max, 0.01); assertEquals(1, bounds.x.max, 0.01); assertEquals(-1, bounds.y.min, 0.01); }