Object
Scaler

public class Scaler extends Object
Scales object-masks (or other more generic elements) collectively to avoid undesired overlap.

If each object-mask is scaled independently, touching but non-overlapping objects can become overlapping when scaled. This provides a collective scaling procedure that avoids this using nearest-neighbor interpolation.

Author:
Owen Feehan
  • Method Details

    • scaleObjects

      public static ScaledElements<ObjectMask> scaleObjects(ObjectCollection objects, ScaleFactor factor) throws OperationFailedException
      Scales every object-mask in a collection collectively.

      It is desirable scale objects together, as interpolation can be done so that adjacent boundaries pre-scaling remain adjacent after scaling (only if there's no overlap among them).

      This is an immutable operation.

      Parameters:
      objects - objects to scale.
      factor - scaling-factor.
      Returns:
      a new collection with scaled object-masks (existing object-masks are unaltered).
      Throws:
      OperationFailedException - if objects cannot be successfully scaled.
    • scaleObjects

      public static ScaledElements<ObjectMask> scaleObjects(ObjectCollection objects, ScaleFactor factor, boolean overlappingObjects, Extent clipTo) throws OperationFailedException
      Scales every object-mask in a collection collectively, ensuring the results remain inside a particular region.

      This is an immutable operation.

      Like scaleObjects(ObjectCollection,ScaleFactor) but ensured the scaled-results will always be inside a particular extent (clipping if necessary).

      Parameters:
      objects - objects to scale.
      factor - scaling-factor.
      overlappingObjects - true if objects may overlap unscaled. false if this is never allowed. This influences whether scaling occurs collectively (to preserve tight borders between objects), or individually.
      clipTo - clips any objects after scaling to make sure they fit inside this extent.
      Returns:
      a new collection with scaled object-masks.
      Throws:
      OperationFailedException - if objects cannot be successfully scaled.
    • scaleObjects

      public static ScaledElements<ObjectMask> scaleObjects(ObjectCollection objects, ScaleFactor factor, boolean overlappingObjects, Optional<UnaryOperator<ObjectMask>> preOperation, Optional<UnaryOperator<ObjectMask>> postOperation) throws OperationFailedException
      Scales every object-mask in a collection collectively (if not overlappjng), allowing for additional manipulation before and after scaling.
      Parameters:
      objects - objects to scale.
      factor - scaling-factor.
      overlappingObjects - true if objects may overlap unscaled. false if this is never allowed. This influences whether scaling occurs collectively (to preserve tight borders between objects), or individually.
      preOperation - applied to each-object before it is scaled (e.g. flattening).
      postOperation - applied to each-object after it is scaled (e.g. clipping to an extent).
      Returns:
      a new collection with scaled object-masks (existing object-masks are unaltered).
      Throws:
      OperationFailedException - if objects cannot be successfully scaled.
    • scaleElements

      public static <T> ScaledElements<T> scaleElements(List<T> elements, ScaleFactor factor, boolean overlappingObjects, Extent clipTo, AccessObjectMask<T> access) throws OperationFailedException
      Scales every element in a list collectively, ensuring the results remain inside a particular region.

      This is similar to scaleObjects(ObjectCollection, ScaleFactor, boolean, Extent) but accepts a parameterized type, rather than ObjectMask.

      Type Parameters:
      T - element-type.
      Parameters:
      elements - objects to scale.
      factor - scaling-factor.
      overlappingObjects - true if objects may overlap unscaled. false if this is never allowed. This influences whether scaling occurs collectively (to preserve tight borders between objects), or individually.
      clipTo - clips any objects after scaling to make sure they fit inside this extent.
      access - retrieves a corresponding bounding-box and ObjectMask from an element.
      Returns:
      a new collection with scaled elements.
      Throws:
      OperationFailedException - if the scaled-elements cannot be created successfully.