/** * Return the scaled width and height relative to a maximum size. * * @param dMaxWidth Maximum width. Must be > 0. * @param dMaxHeight Maximum height. Must be > 0. * @return An array with 2 elements, where the first element is the width, and the second is the * height. */ @Nonnull @CheckReturnValue public SizeDouble getBestMatchingSize( @Nonnegative final double dMaxWidth, @Nonnegative final double dMaxHeight) { ValueEnforcer.isGT0(dMaxWidth, "MaxWidth"); ValueEnforcer.isGT0(dMaxHeight, "MaxHeight"); final double dRelWidth = m_dWidth / dMaxWidth; final double dRelHeight = m_dHeight / dMaxHeight; if (dRelWidth > dRelHeight) { if (m_dWidth > dMaxWidth) return new SizeDouble(dMaxWidth, m_dHeight / dRelWidth); } else { if (m_dHeight > dMaxHeight) return new SizeDouble(m_dWidth / dRelHeight, dMaxHeight); } return this; }
@Nonnull @CheckReturnValue public SizeDouble getScaledToHeight(@Nonnegative final double dNewHeight) { ValueEnforcer.isGT0(dNewHeight, "NewHeight"); if (m_dHeight == dNewHeight) return this; final double dMultFactory = dNewHeight / m_dHeight; return new SizeDouble(m_dWidth * dMultFactory, dNewHeight); }
@Nonnull @CheckReturnValue public SizeDouble getScaledToWidth(@Nonnegative final double dNewWidth) { ValueEnforcer.isGT0(dNewWidth, "NewWidth"); if (m_dWidth == dNewWidth) return this; final double dMultFactory = dNewWidth / m_dWidth; return new SizeDouble(dNewWidth, m_dHeight * dMultFactory); }