Package com.tonic.vellum.geom
Class Rect
- java.lang.Object
-
- com.tonic.vellum.geom.Rect
-
public final class Rect extends java.lang.ObjectAn immutable rectangle in cell coordinates. The take methods return a strip and the split methods return{strip, remainder}; both leave this rect unchanged.
-
-
Constructor Summary
Constructors Constructor Description Rect(int x, int y, int width, int height)Creates a rectangle.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbottom()booleancontains(int px, int py)booleanequals(java.lang.Object o)inthashCode()intheight()Rectinset(int amount)Shrinks this rect on all four sides.Rectintersect(Rect other)Returns the overlap of this rect andother; the result is empty (zero width or height) when they do not overlap.booleanisEmpty()intright()Rect[]splitBottom(int rows)Splits off a bottom strip.Rect[]splitLeft(int cols)Splits off a left strip.Rect[]splitRight(int cols)Splits off a right strip.Rect[]splitTop(int rows)Splits off a top strip.RecttakeBottom(int rows)Returns the bottom strip of the given height, clamped to this rect.RecttakeLeft(int cols)Returns the left strip of the given width, clamped to this rect.RecttakeRight(int cols)Returns the right strip of the given width, clamped to this rect.RecttakeTop(int rows)Returns the top strip of the given height, clamped to this rect.java.lang.StringtoString()intwidth()intx()inty()
-
-
-
Method Detail
-
x
public int x()
- Returns:
- the left edge in cells
-
y
public int y()
- Returns:
- the top edge in cells
-
width
public int width()
- Returns:
- the width in cells
-
height
public int height()
- Returns:
- the height in cells
-
right
public int right()
- Returns:
- the exclusive right edge,
x + width
-
bottom
public int bottom()
- Returns:
- the exclusive bottom edge,
y + height
-
isEmpty
public boolean isEmpty()
- Returns:
- true when the width or height is zero
-
contains
public boolean contains(int px, int py)- Parameters:
px- point x in cellspy- point y in cells- Returns:
- true when the absolute point lies inside this rect
-
intersect
public Rect intersect(Rect other)
Returns the overlap of this rect andother; the result is empty (zero width or height) when they do not overlap.- Parameters:
other- the rect to intersect with- Returns:
- the overlapping rect
-
inset
public Rect inset(int amount)
Shrinks this rect on all four sides.- Parameters:
amount- cells to remove from each side; dimensions clamp at zero- Returns:
- a new rect inset by the amount
-
takeTop
public Rect takeTop(int rows)
Returns the top strip of the given height, clamped to this rect.- Parameters:
rows- strip height in cells- Returns:
- the top strip
-
takeBottom
public Rect takeBottom(int rows)
Returns the bottom strip of the given height, clamped to this rect.- Parameters:
rows- strip height in cells- Returns:
- the bottom strip
-
takeLeft
public Rect takeLeft(int cols)
Returns the left strip of the given width, clamped to this rect.- Parameters:
cols- strip width in cells- Returns:
- the left strip
-
takeRight
public Rect takeRight(int cols)
Returns the right strip of the given width, clamped to this rect.- Parameters:
cols- strip width in cells- Returns:
- the right strip
-
splitTop
public Rect[] splitTop(int rows)
Splits off a top strip.- Parameters:
rows- strip height in cells- Returns:
- a two-element array
{top, rest}
-
splitBottom
public Rect[] splitBottom(int rows)
Splits off a bottom strip.- Parameters:
rows- strip height in cells- Returns:
- a two-element array
{bottom, rest}
-
splitLeft
public Rect[] splitLeft(int cols)
Splits off a left strip.- Parameters:
cols- strip width in cells- Returns:
- a two-element array
{left, rest}
-
splitRight
public Rect[] splitRight(int cols)
Splits off a right strip.- Parameters:
cols- strip width in cells- Returns:
- a two-element array
{right, rest}
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-