Class JavaRectangle2D
- java.lang.Object
-
- science.aist.imaging.api.domain.AbstractSurface<T,L>
-
- science.aist.imaging.api.domain.AbstractJavaPolygon<JavaPoint2D,JavaLine2D>
-
- science.aist.imaging.api.domain.twodimensional.JavaPolygon2D
-
- science.aist.imaging.api.domain.twodimensional.JavaRectangleRotated2D
-
- science.aist.imaging.api.domain.twodimensional.JavaRectangle2D
-
- All Implemented Interfaces:
Serializable
public class JavaRectangle2D extends JavaRectangleRotated2D
This class represents a Rectangle using JavaPoint
- Since:
- 1.0
- Author:
- Andreas Pointner
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class science.aist.imaging.api.domain.AbstractJavaPolygon
points
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JavaRectangle2D()
Empty constructor for deriving classesJavaRectangle2D(double x1, double y1, double x2, double y2)
JavaRectangle2D(int x1, int y1, int x2, int y2)
JavaRectangle2D(JavaPoint2D topLeft, double width, double height)
this(topLeft, new JavaPoint(topLeft.getX() + width, topLeft.getY() + height))JavaRectangle2D(JavaPoint2D topLeft, JavaPoint2D bottomRight)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsJavaPoint(JavaPoint2D javaPoint2D)
Checks if a point in contained in the rectangle.static JavaRectangle2D
createBoundingBox(Collection<JavaPoint2D> jps)
Creates a bounding box for a given set of java pointsstatic JavaRectangle2D
createBoundingBox(JavaPoint2D... jps)
Creates a bounding box for a given set of java pointsstatic JavaRectangle2D
createRectangle(double x1, double y1, double x2, double y2)
Comfort method for creating an rectangle from any x and y points.static Optional<JavaRectangle2D>
getIntersection(JavaRectangle2D rect1, JavaRectangle2D rect2)
Method that calculates the intersection rectangle of two rectangles.JavaPoint2D
getNormalvector()
void
setBottomRight(JavaPoint2D bottomRight)
Sets the bottom right point of the rectangle.void
setTopLeft(JavaPoint2D topLeft)
Sets the top left point of the rectangle.String
toString()
Generated Codestatic Optional<Side>
touchingSide(JavaRectangle2D rect1, JavaRectangle2D rect2)
Method which checks if two rectangles which are not equal or overlapping are touching each other-
Methods inherited from class science.aist.imaging.api.domain.twodimensional.JavaRectangleRotated2D
calculateContour, calculateNormalvector, equals, getArea, getBorderLines, getBottomLeft, getBottomLine, getBottomRight, getCenterPoint, getHeight, getLeftLine, getRightLine, getRotation, getTopLeft, getTopLine, getTopRight, getWidth, hashCode, move, moveTo, normalize, rotate, stretch, stretchTo
-
Methods inherited from class science.aist.imaging.api.domain.twodimensional.JavaPolygon2D
calculateInnerDepth, createLine, createPoint, getIntersection, getPolygonFromUnsortedPointCloud, isInConvexHull, isInConvexHull, sort
-
Methods inherited from class science.aist.imaging.api.domain.AbstractJavaPolygon
getPoints, getSize, isEmpty
-
Methods inherited from class science.aist.imaging.api.domain.AbstractSurface
getIntersection
-
-
-
-
Constructor Detail
-
JavaRectangle2D
public JavaRectangle2D(JavaPoint2D topLeft, JavaPoint2D bottomRight)
- Parameters:
topLeft
- top left point of the rectanglebottomRight
- bottom right point of the rectangle
-
JavaRectangle2D
public JavaRectangle2D(JavaPoint2D topLeft, double width, double height)
this(topLeft, new JavaPoint(topLeft.getX() + width, topLeft.getY() + height))- Parameters:
topLeft
- top left point of the rectanglewidth
- width of the rectangleheight
- height of the rectangle
-
JavaRectangle2D
public JavaRectangle2D(int x1, int y1, int x2, int y2)
- Parameters:
x1
- x-coordinate top left point of the rectangley1
- y-coordinate top left point of the rectanglex2
- x-coordinate bottom right point of the rectangley2
- y-coordinate bottom right point of the rectangle
-
JavaRectangle2D
public JavaRectangle2D(double x1, double y1, double x2, double y2)
- Parameters:
x1
- x-coordinate top left point of the rectangley1
- y-coordinate top left point of the rectanglex2
- x-coordinate bottom right point of the rectangley2
- y-coordinate bottom right point of the rectangle
-
JavaRectangle2D
protected JavaRectangle2D()
Empty constructor for deriving classes
-
-
Method Detail
-
getIntersection
public static Optional<JavaRectangle2D> getIntersection(JavaRectangle2D rect1, JavaRectangle2D rect2)
Method that calculates the intersection rectangle of two rectangles.- Parameters:
rect1
- the first rectanglerect2
- the second rectangle- Returns:
- the intersection rectangle if there is an intersection else Optional.empty
-
touchingSide
public static Optional<Side> touchingSide(JavaRectangle2D rect1, JavaRectangle2D rect2)
Method which checks if two rectangles which are not equal or overlapping are touching each other- Parameters:
rect1
- rect 1rect2
- rect 2- Returns:
- The side of rect 1 where rect2 is touching or an empty optional iff not touching/equal/overlapping
-
createRectangle
public static JavaRectangle2D createRectangle(double x1, double y1, double x2, double y2)
Comfort method for creating an rectangle from any x and y points. The correct coordinates are determined forJavaRectangleRotated2D.getTopLeft()
andJavaRectangleRotated2D.getBottomRight()
- Parameters:
x1
- any first x coordinatey1
- any first y coordinatex2
- any second x coordinatey2
- any second y coordinate- Returns:
- a JavaRectangle
-
createBoundingBox
public static JavaRectangle2D createBoundingBox(JavaPoint2D... jps)
Creates a bounding box for a given set of java points- Parameters:
jps
- the points- Returns:
- the bounding box of the java points
- Throws:
IllegalArgumentException
- if the collection is empty- See Also:
createBoundingBox(Collection)
-
createBoundingBox
public static JavaRectangle2D createBoundingBox(Collection<JavaPoint2D> jps)
Creates a bounding box for a given set of java points- Parameters:
jps
- the list of points- Returns:
- the bounding box of the java points
- Throws:
IllegalArgumentException
- if the collection is empty
-
setTopLeft
public void setTopLeft(JavaPoint2D topLeft)
Sets the top left point of the rectangle. This mutates the current rectangle!- Parameters:
topLeft
- the new top left point of the rectangle
-
setBottomRight
public void setBottomRight(JavaPoint2D bottomRight)
Sets the bottom right point of the rectangle. This mutates the current rectangle!- Parameters:
bottomRight
- the new bottom right point of the rectangle
-
containsJavaPoint
public boolean containsJavaPoint(JavaPoint2D javaPoint2D)
Checks if a point in contained in the rectangle. so if it is inside or on the boundaries.- Overrides:
containsJavaPoint
in classJavaRectangleRotated2D
- Parameters:
javaPoint2D
- the point to be checked- Returns:
- true if contained, else false
-
toString
public String toString()
Description copied from class:JavaRectangleRotated2D
Generated Code- Overrides:
toString
in classJavaRectangleRotated2D
- Returns:
- toString for debugging
-
getNormalvector
public JavaPoint2D getNormalvector()
-
-