Rectangle
Inheritance: java.lang.Object, com.aspose.ms.System.ValueType, com.aspose.ms.lang.Struct
All Implemented Interfaces: com.aspose.ms.System.IEquatable, java.lang.Cloneable
public class Rectangle extends Struct<Rectangle> implements System.IEquatable<Rectangle>, Cloneable
Stores a set of four integers that represent the location and size of a rectangle.
Constructors
Constructor | Description |
---|---|
Rectangle() | |
Rectangle(int x, int y, int width, int height) | Initializes a new instance of the Rectangle structure with the specified location and size. |
Rectangle(Point location, Size size) | Initializes a new instance of the Rectangle struct with the specified location and size. |
Methods
Method | Description |
---|---|
fromLTRB(int left, int top, int right, int bottom) | Creates a Rectangle structure with the specified edge locations. |
intersect(Rectangle a, Rectangle b) | Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. |
op_Equality(Rectangle left, Rectangle right) | Tests whether two Rectangle structures have equal location and size. |
op_Inequality(Rectangle left, Rectangle right) | Tests whether two Rectangle structures differ in location or size. |
ceiling(RectangleF value) | Converts the specified RectangleF structure to a Rectangle structure by rounding the RectangleF values to the next higher integer values. |
truncate(RectangleF value) | Converts the specified RectangleF to a Rectangle by truncating the RectangleF values. |
round(RectangleF value) | Converts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values. |
union(Rectangle a, Rectangle b) | Gets a Rectangle structure that contains the union of two Rectangle structures. |
inflate(Rectangle rect, int x, int y) | |
isEquals(Rectangle obj1, Rectangle obj2) | |
fromPoints(Point point1, Point point2) | Creates a new rectangle from two points. |
getEmpty() | Gets a new instance of the Rectangle structure that has Rectangle.X , Rectangle.Y , Rectangle.Width and Rectangle.Height values set to zero. |
getX() | Gets the x-coordinate of the upper-left corner of this Rectangle structure. |
setX(int value) | Sets the x-coordinate of the upper-left corner of this Rectangle structure. |
getY() | Gets the y-coordinate of the upper-left corner of this Rectangle structure. |
setY(int value) | Sets the y-coordinate of the upper-left corner of this Rectangle structure. |
getLocation() | Gets the coordinates of the upper-left corner of this Rectangle structure. |
setLocation(Point value) | Sets the coordinates of the upper-left corner of this Rectangle structure. |
getWidth() | Gets the width of this Rectangle structure. |
setWidth(int value) | Sets the width of this Rectangle structure. |
getHeight() | Gets the height of this Rectangle structure. |
setHeight(int value) | Sets the height of this Rectangle structure. |
getSize() | Gets the size of this Rectangle. |
setSize(Size value) | Sets the size of this Rectangle. |
getLeft() | Gets the x-coordinate of the left edge of this Rectangle structure. |
getTop() | Gets the y-coordinate of the top edge of this Rectangle structure. |
getRight() | Gets the x-coordinate that is the sum of X and Width property values of this Rectangle structure. |
getBottom() | Gets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure. |
isEmpty() | Gets a value indicating whether all numeric properties of this Rectangle have values of zero. |
equals(Object obj) | Tests whether obj is a Rectangle structure with the same location and size of this Rectangle structure. |
hashCode() | Returns the hash code for this Rectangle structure. |
toString() | |
intersect(Rectangle rect) | Replaces this Rectangle with the intersection of itself and the specified Rectangle. |
inflate(int width, int height) | Enlarges this Rectangle by the specified amount. |
inflate(Size size) | Enlarges this Rectangle by the specified amount. |
contains(int x, int y) | Determines if the specified point is contained within this Rectangle structure. |
contains(Point pt) | Determines if the specified point is contained within this Rectangle structure. |
contains(Rectangle rect) | |
intersectsWith(Rectangle rect) | Determines if this rectangle intersects with rect . |
offset(int x, int y) | Adjusts the location of this rectangle by the specified amount. |
offset(Point pos) | Adjusts the location of this rectangle by the specified amount. |
equals(Rectangle other) | Tests whether other Rectangle structure has the same location and size of this Rectangle structure. |
CloneTo(Rectangle that) | |
Clone() | |
clone() | |
normalize() | Normalizes the rectangle by making it’s width and height positive, left less than right and top less than bottom. |
Rectangle()
public Rectangle()
Rectangle(int x, int y, int width, int height)
public Rectangle(int x, int y, int width, int height)
Initializes a new instance of the Rectangle structure with the specified location and size.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The x-coordinate of the upper-left corner of the rectangle. |
y | int | The y-coordinate of the upper-left corner of the rectangle. |
width | int | The width of the rectangle. |
height | int | The height of the rectangle. |
Rectangle(Point location, Size size)
public Rectangle(Point location, Size size)
Initializes a new instance of the Rectangle struct with the specified location and size.
Parameters:
Parameter | Type | Description |
---|---|---|
location | Point | A Point that represents the upper-left corner of the rectangular region. |
size | Size | A Size (.getSize/.setSize(Size)) that represents the width and height of the rectangular region. |
fromLTRB(int left, int top, int right, int bottom)
public static Rectangle fromLTRB(int left, int top, int right, int bottom)
Creates a Rectangle structure with the specified edge locations.
Parameters:
Parameter | Type | Description |
---|---|---|
left | int | The x-coordinate of the upper-left corner of this Rectangle structure. |
top | int | The y-coordinate of the upper-left corner of this Rectangle structure. |
right | int | The x-coordinate of the lower-right corner of this Rectangle structure. |
bottom | int | The y-coordinate of the lower-right corner of this Rectangle structure. |
Returns: Rectangle - The new Rectangle that this method creates.
intersect(Rectangle a, Rectangle b)
public static Rectangle intersect(Rectangle a, Rectangle b)
Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. If there is no intersection, an empty Rectangle is returned.
Parameters:
Parameter | Type | Description |
---|---|---|
a | Rectangle | First rectangle to intersect. |
b | Rectangle | Second rectangle to intersect. |
Returns:
Rectangle - A Rectangle that represents the intersection of a
and b
.
op_Equality(Rectangle left, Rectangle right)
public static boolean op_Equality(Rectangle left, Rectangle right)
Tests whether two Rectangle structures have equal location and size.
Parameters:
Parameter | Type | Description |
---|---|---|
left | Rectangle | The Rectangle structure that is to the left of the equality operator. |
right | Rectangle | The Rectangle structure that is to the right of the equality operator. |
Returns:
boolean - This operator returns true
if the two Rectangle structures have equal X, Y, Width, and Height properties.
op_Inequality(Rectangle left, Rectangle right)
public static boolean op_Inequality(Rectangle left, Rectangle right)
Tests whether two Rectangle structures differ in location or size.
Parameters:
Parameter | Type | Description |
---|---|---|
left | Rectangle | The Rectangle structure that is to the left of the inequality operator. |
right | Rectangle | The Rectangle structure that is to the right of the inequality operator. |
Returns:
boolean - This operator returns true
if any of the X, Y, Width or Height properties of the two Rectangle structures are unequal; otherwise false
.
ceiling(RectangleF value)
public static Rectangle ceiling(RectangleF value)
Converts the specified RectangleF structure to a Rectangle structure by rounding the RectangleF values to the next higher integer values.
Parameters:
Parameter | Type | Description |
---|---|---|
value | RectangleF | The RectangleF structure to be converted. |
Returns: Rectangle - Returns a Rectangle.
truncate(RectangleF value)
public static Rectangle truncate(RectangleF value)
Converts the specified RectangleF to a Rectangle by truncating the RectangleF values.
Parameters:
Parameter | Type | Description |
---|---|---|
value | RectangleF | The RectangleF to be converted. |
Returns: Rectangle - The truncated value of the Rectangle.
round(RectangleF value)
public static Rectangle round(RectangleF value)
Converts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values.
Parameters:
Parameter | Type | Description |
---|---|---|
value | RectangleF | The RectangleF to be converted. |
Returns: Rectangle - A Rectangle.
union(Rectangle a, Rectangle b)
public static Rectangle union(Rectangle a, Rectangle b)
Gets a Rectangle structure that contains the union of two Rectangle structures.
Parameters:
Parameter | Type | Description |
---|---|---|
a | Rectangle | A first rectangle to union. |
b | Rectangle | A second rectangle to union. |
Returns: Rectangle - A Rectangle structure that bounds the union of the two Rectangle structures.
inflate(Rectangle rect, int x, int y)
public static Rectangle inflate(Rectangle rect, int x, int y)
Parameters:
Parameter | Type | Description |
---|---|---|
rect | Rectangle | |
x | int | |
y | int |
Returns: Rectangle
isEquals(Rectangle obj1, Rectangle obj2)
public static boolean isEquals(Rectangle obj1, Rectangle obj2)
Parameters:
Parameter | Type | Description |
---|---|---|
obj1 | Rectangle | |
obj2 | Rectangle |
Returns: boolean
fromPoints(Point point1, Point point2)
public static Rectangle fromPoints(Point point1, Point point2)
Creates a new rectangle from two points. The created rectangle will be normalized with (left,top) lower than (right,bottom).
Parameters:
Parameter | Type | Description |
---|---|---|
point1 | Point | The first point. |
point2 | Point | The second point. |
Returns: Rectangle - A newly created rectangle.
getEmpty()
public static Rectangle getEmpty()
Gets a new instance of the Rectangle
structure that has Rectangle.X
, Rectangle.Y
, Rectangle.Width
and Rectangle.Height
values set to zero.
Returns: Rectangle
getX()
public final int getX()
Gets the x-coordinate of the upper-left corner of this Rectangle structure.
Returns: int - the x-coordinate of the upper-left corner of this Rectangle structure.
setX(int value)
public final void setX(int value)
Sets the x-coordinate of the upper-left corner of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | the x-coordinate of the upper-left corner of this Rectangle structure. |
getY()
public final int getY()
Gets the y-coordinate of the upper-left corner of this Rectangle structure.
Returns: int - the y-coordinate of the upper-left corner of this Rectangle structure.
setY(int value)
public final void setY(int value)
Sets the y-coordinate of the upper-left corner of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | the y-coordinate of the upper-left corner of this Rectangle structure. |
getLocation()
public final Point getLocation()
Gets the coordinates of the upper-left corner of this Rectangle structure.
Returns: Point - the coordinates of the upper-left corner of this Rectangle structure.
setLocation(Point value)
public final void setLocation(Point value)
Sets the coordinates of the upper-left corner of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
value | Point | the coordinates of the upper-left corner of this Rectangle structure. |
getWidth()
public final int getWidth()
Gets the width of this Rectangle structure.
Returns: int - the width of this Rectangle structure.
setWidth(int value)
public final void setWidth(int value)
Sets the width of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | the width of this Rectangle structure. |
getHeight()
public final int getHeight()
Gets the height of this Rectangle structure.
Returns: int - the height of this Rectangle structure.
setHeight(int value)
public final void setHeight(int value)
Sets the height of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int | the height of this Rectangle structure. |
getSize()
public final Size getSize()
Gets the size of this Rectangle.
Returns: Size - the size of this Rectangle.
setSize(Size value)
public final void setSize(Size value)
Sets the size of this Rectangle.
Parameters:
Parameter | Type | Description |
---|---|---|
value | Size | the size of this Rectangle. |
getLeft()
public final int getLeft()
Gets the x-coordinate of the left edge of this Rectangle structure.
Returns: int - the x-coordinate of the left edge of this Rectangle structure.
getTop()
public final int getTop()
Gets the y-coordinate of the top edge of this Rectangle structure.
Returns: int - the y-coordinate of the top edge of this Rectangle structure.
getRight()
public final int getRight()
Gets the x-coordinate that is the sum of X and Width property values of this Rectangle structure.
Returns: int - the x-coordinate that is the sum of X and Width property values of this Rectangle structure.
getBottom()
public final int getBottom()
Gets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure.
Returns: int - the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure.
isEmpty()
public final boolean isEmpty()
Gets a value indicating whether all numeric properties of this Rectangle have values of zero.
Returns:
boolean - This property returns true
if the Rectangle.Width
, Rectangle.Height
, Rectangle.X
, and Rectangle.Y
properties of this Rectangle all have values of zero; otherwise, false
.
equals(Object obj)
public boolean equals(Object obj)
Tests whether obj is a Rectangle structure with the same location and size of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
obj | java.lang.Object | The Object to test. |
Returns:
boolean - This method returns true
if obj is a Rectangle structure and its X, Y, Width, and Height properties are equal to the corresponding properties of this Rectangle structure; otherwise, false
.
hashCode()
public int hashCode()
Returns the hash code for this Rectangle structure. For information about the use of hash codes, see GetHashCode .
Returns: int - An integer that represents the hash code for this rectangle.
toString()
public String toString()
Returns: java.lang.String
intersect(Rectangle rect)
public final void intersect(Rectangle rect)
Replaces this Rectangle with the intersection of itself and the specified Rectangle.
Parameters:
Parameter | Type | Description |
---|---|---|
rect | Rectangle | The Rectangle with which to intersect. |
inflate(int width, int height)
public final void inflate(int width, int height)
Enlarges this Rectangle by the specified amount.
Parameters:
Parameter | Type | Description |
---|---|---|
width | int | The amount to inflate this Rectangle horizontally. |
height | int | The amount to inflate this Rectangle vertically. |
inflate(Size size)
public final void inflate(Size size)
Enlarges this Rectangle by the specified amount.
Parameters:
Parameter | Type | Description |
---|---|---|
size | Size | The size to inflate this Rectangle. |
contains(int x, int y)
public final boolean contains(int x, int y)
Determines if the specified point is contained within this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The x-coordinate of the point to test. |
y | int | The y-coordinate of the point to test. |
Returns:
boolean - This method returns true
if the point defined by x
and y
is contained within this Rectangle structure; otherwise false
.
contains(Point pt)
public final boolean contains(Point pt)
Determines if the specified point is contained within this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
pt | Point | The Point to test. |
Returns:
boolean - This method returns true
if the point represented by pt
is contained within this Rectangle structure; otherwise false
.
contains(Rectangle rect)
public final boolean contains(Rectangle rect)
Parameters:
Parameter | Type | Description |
---|---|---|
rect | Rectangle |
Returns: boolean
intersectsWith(Rectangle rect)
public final boolean intersectsWith(Rectangle rect)
Determines if this rectangle intersects with rect
.
Parameters:
Parameter | Type | Description |
---|---|---|
rect | Rectangle | The rectangle to test. |
Returns: boolean - This method returns true if there is any intersection, otherwise false.
offset(int x, int y)
public final void offset(int x, int y)
Adjusts the location of this rectangle by the specified amount.
Parameters:
Parameter | Type | Description |
---|---|---|
x | int | The horizontal offset. |
y | int | The vertical offset. |
offset(Point pos)
public final void offset(Point pos)
Adjusts the location of this rectangle by the specified amount.
Parameters:
Parameter | Type | Description |
---|---|---|
pos | Point | The offset. |
equals(Rectangle other)
public final boolean equals(Rectangle other)
Tests whether other Rectangle structure has the same location and size of this Rectangle structure.
Parameters:
Parameter | Type | Description |
---|---|---|
other | Rectangle | Other rectangle to test |
Returns:
boolean - This method returns true
if other Rectangle structure and its X, Y, Width, and Height properties are equal to the corresponding properties of this Rectangle structure; otherwise, false
.
CloneTo(Rectangle that)
public void CloneTo(Rectangle that)
Parameters:
Parameter | Type | Description |
---|---|---|
that | Rectangle |
Clone()
public Rectangle Clone()
Returns: Rectangle
clone()
public Object clone()
Returns: java.lang.Object
normalize()
public void normalize()
Normalizes the rectangle by making it’s width and height positive, left less than right and top less than bottom.