Package snap.geom

Class Rect

All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ViewProxy

public class Rect extends RectBase
Represents a rectangle - a Quadrilateral with parallel sides.
  • Field Details

    • ZeroRect

      public static final Rect ZeroRect
    • UnitRect

      public static final Rect UnitRect
  • Constructor Details

    • Rect

      public Rect()
      Creates new Rect.
    • Rect

      public Rect(double aX, double aY, double aW, double aH)
      Creates new Rect.
  • Method Details

    • getBoundsImpl

      protected Rect getBoundsImpl()
      Override to just return this rect.
      Overrides:
      getBoundsImpl in class RectBase
    • getPathIter

      public PathIter getPathIter(Transform aTrans)
      Returns a path iterator.
      Specified by:
      getPathIter in class Shape
    • getPoint

      public Point getPoint(Pos aPos)
      Returns a point for given position on rect.
    • intersect

      public void intersect(Rect aRect)
      Returns the rect that is an intersection of this rect and given rect.
    • getIntersectRect

      public Rect getIntersectRect(Rect aRect)
      Returns the rect that is an intersection of this rect and given rect.
    • contains

      public boolean contains(double aX, double aY)
      Returns whether rect contains x/y.
      Overrides:
      contains in class Shape
    • contains

      public boolean contains(Shape aShape)
      Override to simplify since rect contains any shape if-and-only-if it contians that shapes bounds.
      Overrides:
      contains in class Shape
    • intersectsShape

      public boolean intersectsShape(Shape aShape)
      Override to omptimize rect-to-rect case.
      Overrides:
      intersectsShape in class Shape
    • containsRect

      public boolean containsRect(Rect aRect)
      Returns whether rect contains another rect.
    • intersectsRect

      public boolean intersectsRect(Rect aRect)
      Returns whether the receiver intersects with the given rect.
    • intersectsRectAndNotEmpty

      public boolean intersectsRectAndNotEmpty(Rect aRect)
      Returns whether this rect intersects with given rect and both are not empty.
    • contains

      public boolean contains(double x, double y, double aLineWidth)
      Returns whether shape with line width contains point.
      Overrides:
      contains in class Shape
    • intersectsShape

      public boolean intersectsShape(Shape aShape, double aLineWidth)
      Returns whether shape with line width intersects shape.
      Overrides:
      intersectsShape in class Shape
    • getInsetRect

      public Rect getInsetRect(double anInset)
      Returns a copy of this rect inset by given amount.
    • getInsetRect

      public Rect getInsetRect(double xIns, double yIns)
      Returns a copy of this rect inset by given amount.
    • getInsetRect

      public Rect getInsetRect(Insets anIns)
      Returns a copy of this rect inset by given insets.
    • getOffsetRect

      public Rect getOffsetRect(double dx, double dy)
      Offsets the receiver by the given x & y.
    • scale

      public void scale(double anAmt)
      Scales the receiver rect by the given amount.
    • getScaledRect

      public Rect getScaledRect(double anAmt)
      Creates a rect derived from the receiver scaled by the given amount.
    • add

      public void add(Rect r2)
      Sets this rect to combined bounds of both rects, even if either is empty.
    • getAddRect

      public Rect getAddRect(Rect r2)
      Returns rect for combined bounds of both rects, even if either is empty.
    • union

      public void union(Rect r2)
      Sets this rect to combined area with given rect. If either rect is empty, bounds are set to other rect.
    • union

      public void union(double aX, double aY, double aW, double aH)
      Sets this rect to combined area with given rect. If either rect is empty, bounds are set to other rect.
    • getUnionRect

      public Rect getUnionRect(Rect r2)
      Returns rect for combined area with given rect. If either rect is empty, bounds are from other rect.
    • unionEvenIfEmpty

      public void unionEvenIfEmpty(Rect r2)
      Unions the receiver rect with the given rect.
    • add

      public void add(double newx, double newy)
      Adds a point to this rect. The resulting rect is the smallest that contains both the original and given point.
    • addX

      public void addX(double newx)
      Adds a point to this rect. The resulting rect is the smallest that contains both the original and given point.
    • addY

      public void addY(double newy)
      Adds a point to this rect. The resulting rect is the smallest that contains both the original and given point.
    • snap

      public void snap()
      Rounds the rect to nearest pixel.
    • getPoints

      public Point[] getPoints()
      Returns an array of four points containing each corner of the rect.
    • getRectCenteredInside

      public Rect getRectCenteredInside(double aW, double aH)
      Returns the rect centered inside for given size.
    • getPerimeterPointForRadial

      public Point getPerimeterPointForRadial(double anAngle, boolean doEllipse)
      Returns the point on the rectangle's perimeter that is intersected by a radial at the given angle from the center of the rect. Zero degrees is at the 3 o'clock position.
      Parameters:
      anAngle - Angle in degrees.
      doEllipse - Whether to scale radials into ellipse or leave them normal.
      Returns:
      Returns point on perimeter of rect intersected by radial at given angle.
    • clone

      public Rect clone()
      Standard clone implementation.
      Overrides:
      clone in class RectBase
    • hashCode

      public int hashCode()
      Standard hashCode implementation.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class RectBase
    • contains

      public static boolean contains(double x, double y, double w, double h, double aX, double aY)
      Returns whether given rect parts contains given x/y.
    • getPointForPosition

      public static Point getPointForPosition(double aX, double aY, double aW, double aH, Pos aPos)
      Returns a point for x, y, w, h and position.
    • getPointForPositionAndSize

      public static Point getPointForPositionAndSize(Rect aRect, Pos aPos, double aW2, double aH2)
      Returns a point for x, y, w, h and position.
    • getPointForPositionAndSize

      public static Point getPointForPositionAndSize(double aX, double aY, double aW, double aH, Pos aPos, double aW2, double aH2)
      Returns a point for x, y, w, h and position.
    • getRectForPoints

      public static Rect getRectForPoints(Point... thePoints)
      Creates a rect enclosing the given array of points.
    • getRectForString

      public static Rect getRectForString(String aString)
      Creates a rect from an String in XML format as defined in toXMLString().
    • get

      public static Rect get(Point... points)
      Delete these.
    • get

      public static Rect get(String aString)