Class Extent2D

All Implemented Interfaces:
Shape, Serializable, Cloneable, Comparable

public class Extent2D extends Rectangle2D.Double implements Comparable
A class to perform operations on enclosing rectangles
Author:
Carey Lockwood, Tom Moore Modified, methods added and commented by Tom Moore
See Also:
Serialized Form
  • Constructor Details

    • Extent2D

      public Extent2D()
    • Extent2D

      public Extent2D(Rectangle2D r)
    • Extent2D

      public Extent2D(double x, double y, double w, double h)
  • Method Details

    • adjustAspect

      public void adjustAspect(Extent2D target)
      Expand the source extent to the aspect ratio of target.
      Parameters:
      target - The extent with the desired aspect ratio.
    • zoom

      public void zoom(double factor)
      Expand or contract the extent by the specified factor
      Parameters:
      factor - If less than 1 the extent will shrink, if greater than 1 the extent will grow.
    • recenter

      public void recenter(double xcen, double ycen)
      Recenter the extent at the specified point
    • translate

      public void translate(double xdel, double ydel)
      Translate the extent by the specified distance
    • left

      public Extent2D left()
      Return a new extent that covers the left half of this extent
    • right

      public Extent2D right()
      Return a new extent that covers the right half of this extent
    • top

      public Extent2D top()
      Return a new extent that covers the top half of this extent
    • bottom

      public Extent2D bottom()
      Return a new extent that covers the bottom half of this extent
    • overlaps

      public boolean overlaps(Shape s)
    • round

      public Extent2D round(double roundOff)
      Create an extent that is enlarged so that the corners of the current extent are rounded to the specified roundOff value. The left and bottom will be reduced to the next lowest even multiple of the roundOff value. The right and top values will be increased to the next even multiple of the roundOff value.
      Parameters:
      roundOff - The value that the corners of the new extent will be 'snapped' to.
    • snap

      public Extent2D snap(Extent2D ext, double roundOff)
      Create an extent that is snapped so that the corners of the current extent are aligned to the corners of the specified extent. The left and bottom will be reduced to the next lowest even multiple of the adjustment value. The right and top values will be increased to the next higher even multiple of the adjustment value.
      Parameters:
      ext - An extent that the current extent will be snapped to.
      roundOff - The modulus value that will be used to find the closest adjustment.
    • snap

      public Extent2D snap(double xOffset, double yOffset, double roundOff)
      Create an extent that is snapped so that the corners of the current extent are aligned to the specified offset values. The left and bottom will be reduced to the next lowest even multiple of the adjustment value. The right and top values will be increased to the next higher even multiple of the adjustment value.
      Parameters:
      xOffset - The x snapping adjustment value.
      yOffset - The y snapping adjustment value.
      roundOff - The modulus value that will be used to find the closest adjustment.
    • toString

      public String toString()
      Overrides:
      toString in class Rectangle2D.Double
    • compareTo

      public int compareTo(Object o)
      Define the sorted order of Extent2D objects to be top-to-bottom, left-to-right.
      Specified by:
      compareTo in interface Comparable
    • distance

      public double distance(Extent2D extent)
      Return the minimum distance between the two extents. If the extents overlap then return 0;