@Test public void newBoundsEdgeCase() { Rect rect = SquarifiedPacking.newBounds(new Rect(787, 1045, 915, 1047), 0.006106064544560274, 0.9457072296133543); assertEquals(new Rect(908, 1045, 909, 1047), rect); }
@VisibleForTesting @Nonnull static Rect newBounds(@Nonnull Rect bounds, double fraction, double priorFraction) { verify(fraction + priorFraction <= 1 + EPSILON, "fraction (%d) & prior fraction (%d) more than 1 + EPSILON ", fraction, priorFraction); if (bounds.isEmpty()) return bounds; Rect newBounds; if (bounds.width() >= bounds.height()) { double left = bounds.left + bounds.width() * priorFraction; double right = left + (bounds.width() * fraction); newBounds = new Rect((int) round(left), bounds.top, (int) round(right), bounds.bottom); } else { double top = bounds.top + bounds.height() * priorFraction; double bottom = top + bounds.height() * fraction; newBounds = new Rect(bounds.left, (int) round(top), bounds.right, (int) round(bottom)); } verify(bounds.contains(newBounds), "newBounds not contained. horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); verify(newBounds.width() >= 0 && newBounds.height() >= 0, "width or height negative, horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); return newBounds; }
SquarifiedPacking { @VisibleForTesting @Nonnull static Rect newBounds(@Nonnull Rect bounds, double fraction, double priorFraction) { verify(fraction + priorFraction <= 1 + EPSILON, "fraction (%d) & prior fraction (%d) more than 1 + EPSILON ", fraction, priorFraction); if (bounds.isEmpty()) return bounds; Rect newBounds; if (bounds.width() >= bounds.height()) { double left = bounds.left + bounds.width() * priorFraction; double right = left + (bounds.width() * fraction); newBounds = new Rect((int) round(left), bounds.top, (int) round(right), bounds.bottom); } else { double top = bounds.top + bounds.height() * priorFraction; double bottom = top + bounds.height() * fraction; newBounds = new Rect(bounds.left, (int) round(top), bounds.right, (int) round(bottom)); } verify(bounds.contains(newBounds), "newBounds not contained. horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); verify(newBounds.width() >= 0 && newBounds.height() >= 0, "width or height negative, horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); return newBounds; } }
SquarifiedPacking { @VisibleForTesting @Nonnull static Rect newBounds(@Nonnull Rect bounds, double fraction, double priorFraction) { verify(fraction + priorFraction <= 1 + EPSILON, "fraction (%d) & prior fraction (%d) more than 1 + EPSILON ", fraction, priorFraction); if (bounds.isEmpty()) return bounds; Rect newBounds; if (bounds.width() >= bounds.height()) { double left = bounds.left + bounds.width() * priorFraction; double right = left + (bounds.width() * fraction); newBounds = new Rect((int) round(left), bounds.top, (int) round(right), bounds.bottom); } else { double top = bounds.top + bounds.height() * priorFraction; double bottom = top + bounds.height() * fraction; newBounds = new Rect(bounds.left, (int) round(top), bounds.right, (int) round(bottom)); } verify(bounds.contains(newBounds), "newBounds not contained. horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); verify(newBounds.width() >= 0 && newBounds.height() >= 0, "width or height negative, horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); return newBounds; }  }
SquarifiedPacking { @VisibleForTesting @Nonnull static Rect newBounds(@Nonnull Rect bounds, double fraction, double priorFraction) { verify(fraction + priorFraction <= 1 + EPSILON, "fraction (%d) & prior fraction (%d) more than 1 + EPSILON ", fraction, priorFraction); if (bounds.isEmpty()) return bounds; Rect newBounds; if (bounds.width() >= bounds.height()) { double left = bounds.left + bounds.width() * priorFraction; double right = left + (bounds.width() * fraction); newBounds = new Rect((int) round(left), bounds.top, (int) round(right), bounds.bottom); } else { double top = bounds.top + bounds.height() * priorFraction; double bottom = top + bounds.height() * fraction; newBounds = new Rect(bounds.left, (int) round(top), bounds.right, (int) round(bottom)); } verify(bounds.contains(newBounds), "newBounds not contained. horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); verify(newBounds.width() >= 0 && newBounds.height() >= 0, "width or height negative, horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); return newBounds; }  @Nonnull static Tree<DisplayNode> pack(@Nonnull Tree<FilesystemSummary> summaryTree, @Nonnull Rect bounds); }
SquarifiedPacking { @VisibleForTesting @Nonnull static Rect newBounds(@Nonnull Rect bounds, double fraction, double priorFraction) { verify(fraction + priorFraction <= 1 + EPSILON, "fraction (%d) & prior fraction (%d) more than 1 + EPSILON ", fraction, priorFraction); if (bounds.isEmpty()) return bounds; Rect newBounds; if (bounds.width() >= bounds.height()) { double left = bounds.left + bounds.width() * priorFraction; double right = left + (bounds.width() * fraction); newBounds = new Rect((int) round(left), bounds.top, (int) round(right), bounds.bottom); } else { double top = bounds.top + bounds.height() * priorFraction; double bottom = top + bounds.height() * fraction; newBounds = new Rect(bounds.left, (int) round(top), bounds.right, (int) round(bottom)); } verify(bounds.contains(newBounds), "newBounds not contained. horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); verify(newBounds.width() >= 0 && newBounds.height() >= 0, "width or height negative, horizontal: %s, frac: %s, priorFrac: %s, bounds: %s, newBounds: %s", bounds.width() >= bounds.height(), fraction, priorFraction, bounds, newBounds); return newBounds; }  @Nonnull static Tree<DisplayNode> pack(@Nonnull Tree<FilesystemSummary> summaryTree, @Nonnull Rect bounds); static final int MAX_PADDING; }