Class RelativeScaleCalculator

Object
RelativeScaleCalculator

public class RelativeScaleCalculator extends Object
Determine the scaling-factor needed to scale an Extent to become equal in size to another Extent.
Author:
Owen Feehan
  • Method Details

    • relativeScale

      public static ScaleFactor relativeScale(Extent source, Extent target, boolean preserveAspectRatio)
      Parameters:
      source - source extent (only X and Y dimensions are considered).
      target - target extent (only X and Y dimensions are considered).
      preserveAspectRatio - iff true, the aspect ratio is preserved, and relativeScalePreserveAspectRatio(Extent, Extent) is called, otherwise relativeScale(Extent, Extent).
      Returns:
      the scaling-factor to scale the source to be the same size as the target.
    • relativeScalePreserveAspectRatio

      public static ScaleFactor relativeScalePreserveAspectRatio(Extent source, Extent target)
      Calculates a scaling factor so as to maximally scale source to target - while preserving the aspect ratio.

      Either the X or Y dimension is guaranteed to have a scale-factor target / source, and the other will scale so as not to exceed the size of target.

      Parameters:
      source - source extent (only X and Y dimensions are considered).
      target - target extent (only X and Y dimensions are considered).
      Returns:
      the scaling-factor to scale the source to be the same size as the target.
    • relativeScale

      public static ScaleFactor relativeScale(Extent source, Extent target)
      Calculates a scaling factor so as to scale source to target.

      i.e. the scale-factor is target / source for each XY dimension.

      Parameters:
      source - source extent (only X and Y dimensions are considered).
      target - target extent (only X and Y dimensions are considered).
      Returns:
      the scaling-factor to scale the source to be the same size as the target.