Package snap.geom
Class Rect
java.lang.Object
snap.geom.Shape
snap.geom.RectBase
snap.geom.Rect
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ViewProxy
Represents a rectangle - a Quadrilateral with parallel sides.
-
Field Summary
Fields inherited from class snap.geom.Shape
_bounds, WIND_EVEN_ODD, WIND_NON_ZERO
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double newx, double newy) Adds a point to this rect.void
Sets this rect to combined bounds of both rects, even if either is empty.void
addX
(double newx) Adds a point to this rect.void
addY
(double newy) Adds a point to this rect.clone()
Standard clone implementation.boolean
contains
(double aX, double aY) Returns whether rect contains x/y.boolean
contains
(double x, double y, double aLineWidth) Returns whether shape with line width contains point.static boolean
contains
(double x, double y, double w, double h, double aX, double aY) Returns whether given rect parts contains given x/y.boolean
Override to simplify since rect contains any shape if-and-only-if it contians that shapes bounds.boolean
containsRect
(Rect aRect) Returns whether rect contains another rect.boolean
Standard equals implementation.static Rect
static Rect
Delete these.getAddRect
(Rect r2) Returns rect for combined bounds of both rects, even if either is empty.protected Rect
Override to just return this rect.getInsetRect
(double anInset) Returns a copy of this rect inset by given amount.getInsetRect
(double xIns, double yIns) Returns a copy of this rect inset by given amount.getInsetRect
(Insets anIns) Returns a copy of this rect inset by given insets.getIntersectRect
(Rect aRect) Returns the rect that is an intersection of this rect and given rect.getOffsetRect
(double dx, double dy) Offsets the receiver by the given x & y.getPathIter
(Transform aTrans) Returns a path iterator.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.Returns a point for given position on rect.static Point
getPointForPosition
(double aX, double aY, double aW, double aH, Pos aPos) Returns a point for x, y, w, h and position.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.static Point
getPointForPositionAndSize
(Rect aRect, Pos aPos, double aW2, double aH2) Returns a point for x, y, w, h and position.Point[]
Returns an array of four points containing each corner of the rect.getRectCenteredInside
(double aW, double aH) Returns the rect centered inside for given size.static Rect
getRectForPoints
(Point... thePoints) Creates a rect enclosing the given array of points.static Rect
getRectForString
(String aString) Creates a rect from an String in XML format as defined in toXMLString().getScaledRect
(double anAmt) Creates a rect derived from the receiver scaled by the given amount.getUnionRect
(Rect r2) Returns rect for combined area with given rect.int
hashCode()
Standard hashCode implementation.void
Returns the rect that is an intersection of this rect and given rect.boolean
intersectsRect
(Rect aRect) Returns whether the receiver intersects with the given rect.boolean
intersectsRectAndNotEmpty
(Rect aRect) Returns whether this rect intersects with given rect and both are not empty.boolean
intersectsShape
(Shape aShape) Override to omptimize rect-to-rect case.boolean
intersectsShape
(Shape aShape, double aLineWidth) Returns whether shape with line width intersects shape.void
scale
(double anAmt) Scales the receiver rect by the given amount.void
snap()
Rounds the rect to nearest pixel.void
union
(double aX, double aY, double aW, double aH) Sets this rect to combined area with given rect.void
Sets this rect to combined area with given rect.void
unionEvenIfEmpty
(Rect r2) Unions the receiver rect with the given rect.Methods inherited from class snap.geom.RectBase
copyFor, copyFor, equals, getHeight, getMaxX, getMaxY, getMidX, getMidY, getMinX, getMinY, getSize, getSvgString, getWidth, getX, getXY, getY, inset, inset, inset, isEmpty, offset, setCenteredXY, setHeight, setRect, setRect, setSize, setWidth, setX, setXY, setY, toString
Methods inherited from class snap.geom.Shape
addShapes, contains, containsSeg, copyForBounds, crossesSeg, getArcLength, getBounds, getCrossings, getDistance, getFlattenedShape, getFlattenedShape, getNotSelfIntersectingShape, intersectShapes, intersectsSeg, intersectsXY, isClosed, isFlat, isMultiCycle, isSelfIntersecting, isSingleCycle, shapeChanged, subtractShapes
-
Field Details
-
ZeroRect
-
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
Override to just return this rect.- Overrides:
getBoundsImpl
in classRectBase
-
getPathIter
Returns a path iterator.- Specified by:
getPathIter
in classShape
-
getPoint
Returns a point for given position on rect. -
intersect
Returns the rect that is an intersection of this rect and given rect. -
getIntersectRect
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. -
contains
Override to simplify since rect contains any shape if-and-only-if it contians that shapes bounds. -
intersectsShape
Override to omptimize rect-to-rect case.- Overrides:
intersectsShape
in classShape
-
containsRect
Returns whether rect contains another rect. -
intersectsRect
Returns whether the receiver intersects with the given rect. -
intersectsRectAndNotEmpty
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. -
intersectsShape
Returns whether shape with line width intersects shape.- Overrides:
intersectsShape
in classShape
-
getInsetRect
Returns a copy of this rect inset by given amount. -
getInsetRect
Returns a copy of this rect inset by given amount. -
getInsetRect
Returns a copy of this rect inset by given insets. -
getOffsetRect
Offsets the receiver by the given x & y. -
scale
public void scale(double anAmt) Scales the receiver rect by the given amount. -
getScaledRect
Creates a rect derived from the receiver scaled by the given amount. -
add
Sets this rect to combined bounds of both rects, even if either is empty. -
getAddRect
Returns rect for combined bounds of both rects, even if either is empty. -
union
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
Returns rect for combined area with given rect. If either rect is empty, bounds are from other rect. -
unionEvenIfEmpty
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
Returns an array of four points containing each corner of the rect. -
getRectCenteredInside
Returns the rect centered inside for given size. -
getPerimeterPointForRadial
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
Standard clone implementation. -
hashCode
public int hashCode()Standard hashCode implementation. -
equals
Standard equals implementation. -
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
Returns a point for x, y, w, h and position. -
getPointForPositionAndSize
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
Creates a rect enclosing the given array of points. -
getRectForString
Creates a rect from an String in XML format as defined in toXMLString(). -
get
Delete these. -
get
-