Package cz.vutbr.fit.layout.model
Class Rectangular
- java.lang.Object
-
- cz.vutbr.fit.layout.model.Rectangular
-
- All Implemented Interfaces:
Rect
- Direct Known Subclasses:
RectangularZ,Separator
public class Rectangular extends Object implements Rect
This class represents a general rectangular area.- Author:
- radek
-
-
Constructor Summary
Constructors Constructor Description Rectangular()Rectangular(int x1, int y1)Creates an empty rectangle at the given coordinates.Rectangular(int x1, int y1, int x2, int y2)Creates a rectangle at the given coordinates.Rectangular(int x1, int y1, int x2, int y2, boolean reorder)Creates a rectangle at the given coordinates.Rectangular(Rectangular src)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(int x, int y)Checks if this rectangle contains a point.voidcopy(Rectangular src)booleanencloses(Rectangular other)Checks if this rectangle entirely contains another rectangle.booleanenclosesX(Rectangular other)Checks if this rectangle entirely contains the X coordinates of another rectangle.booleanenclosesY(Rectangular other)Checks if this rectangle entirely contains the Y coordinates of another rectangle.booleanequals(Object obj)voidexpandToEnclose(Rectangular other)intgetArea()intgetHeight()intgetWidth()intgetX1()intgetX2()intgetY1()intgetY2()Rectangularhsplit(Rectangular other)If this rectangle intersets with the other one, splits this rectangle horizontally so that it does not intersect with the other one anymore.Rectangularintersection(Rectangular other)Computes the intersection of this rectangle with another one.booleanintersects(Rectangular other)booleanintersectsX(Rectangular other)booleanintersectsY(Rectangular other)booleanisEmpty()intmidX()intmidY()voidmove(int xofs, int yofs)Changes the rectangle coordinates by adding the specified X and Y offsetsRectangularreplaceX(Rectangular other)Replaces the X coordinates of the rectangle with the X coordinates of another one.RectangularreplaceY(Rectangular other)Replaces the Y coordinates of the rectangle with the Y coordinates of another one.voidsetX1(int x1)voidsetX2(int x2)voidsetY1(int y1)voidsetY2(int y2)StringtoString()Rectangularunion(Rectangular other)Computes the union of this rectangle with another one.Rectangularvsplit(Rectangular other)If this rectangle intersets with the other one, splits this rectangle horizontally so that it does not intersect with the other one anymore.
-
-
-
Constructor Detail
-
Rectangular
public Rectangular()
-
Rectangular
public Rectangular(int x1, int y1, int x2, int y2)Creates a rectangle at the given coordinates. The x1:x2 and y1:y2 coordinates are automatically reordered so that x1 < x2 and y1 < y2. Note that this behavior does not allow creating empty rectangles using this constructor.- Parameters:
x1-y1-x2-y2-
-
Rectangular
public Rectangular(int x1, int y1, int x2, int y2, boolean reorder)Creates a rectangle at the given coordinates. The x1:x2 and y1:y2 coordinates may be automatically reordered so that x1 < x2 and y1 < y2.- Parameters:
x1-y1-x2-y2-reorder- Allow reordering the x and y values so that x1 < x2 and y1 < y2
-
Rectangular
public Rectangular(int x1, int y1)Creates an empty rectangle at the given coordinates.- Parameters:
x1-y1-
-
Rectangular
public Rectangular(Rectangular src)
-
-
Method Detail
-
copy
public void copy(Rectangular src)
-
setX1
public void setX1(int x1)
- Parameters:
x1- the x1 to set
-
setX2
public void setX2(int x2)
- Parameters:
x2- the x2 to set
-
setY1
public void setY1(int y1)
- Parameters:
y1- the y1 to set
-
setY2
public void setY2(int y2)
- Parameters:
y2- the y2 to set
-
midX
public int midX()
-
midY
public int midY()
-
move
public void move(int xofs, int yofs)Changes the rectangle coordinates by adding the specified X and Y offsets
-
getArea
public int getArea()
-
isEmpty
public boolean isEmpty()
-
encloses
public boolean encloses(Rectangular other)
Checks if this rectangle entirely contains another rectangle.- Parameters:
other- the other rectangle- Returns:
- true when the other rectangle is completely contained in this one
-
enclosesX
public boolean enclosesX(Rectangular other)
Checks if this rectangle entirely contains the X coordinates of another rectangle.- Parameters:
other- the other rectangle- Returns:
- true when the X coordinates of the other rectangle are completely contained in this one
-
enclosesY
public boolean enclosesY(Rectangular other)
Checks if this rectangle entirely contains the Y coordinates of another rectangle.- Parameters:
other- the other rectangle- Returns:
- true when the Y coordinates of the other rectangle are completely contained in this one
-
contains
public boolean contains(int x, int y)Checks if this rectangle contains a point.- Parameters:
x- the point X coordinatey- the point Y coordinate- Returns:
- true when the point is contained in this one
-
intersects
public boolean intersects(Rectangular other)
-
intersectsX
public boolean intersectsX(Rectangular other)
-
intersectsY
public boolean intersectsY(Rectangular other)
-
intersection
public Rectangular intersection(Rectangular other)
Computes the intersection of this rectangle with another one.- Parameters:
other- the other rectangle- Returns:
- the resulting intersection or an empty rectangle when there is no intersection
-
union
public Rectangular union(Rectangular other)
Computes the union of this rectangle with another one.- Parameters:
other- the other rectangle- Returns:
- the union rectangle
-
replaceX
public Rectangular replaceX(Rectangular other)
Replaces the X coordinates of the rectangle with the X coordinates of another one.- Parameters:
other- the rectangle whose X coordinates will be used- Returns:
- the resulting rectangle
-
replaceY
public Rectangular replaceY(Rectangular other)
Replaces the Y coordinates of the rectangle with the Y coordinates of another one.- Parameters:
other- the rectangle whose Y coordinates will be used- Returns:
- the resulting rectangle
-
hsplit
public Rectangular hsplit(Rectangular other)
If this rectangle intersets with the other one, splits this rectangle horizontally so that it does not intersect with the other one anymore.- Parameters:
other- the rectangle used to split this one- Returns:
- if this rectangle had to be split in two parts, the second one is returned. Otherwise, null is returned.
-
vsplit
public Rectangular vsplit(Rectangular other)
If this rectangle intersets with the other one, splits this rectangle horizontally so that it does not intersect with the other one anymore.- Parameters:
other- the rectangle used to split this one- Returns:
- if this rectangle had to be split in two parts, the second one is returned. Otherwise, null is returned.
-
expandToEnclose
public void expandToEnclose(Rectangular other)
-
-