math.geom2d.polygon
Class Rectangle2D
- java.lang.Object
-
- math.geom2d.polygon.Rectangle2D
-
- All Implemented Interfaces:
- CirculinearDomain2D, CirculinearShape2D, Domain2D, GeometricObject2D, Polygon2D, Shape2D
public class Rectangle2D extends java.lang.Object implements Polygon2D
Rectangle2D defines a rectangle rotated around its first corner.
-
-
Constructor Summary
Constructors Constructor and Description Rectangle2D()Empty constructor (size and position zero)Rectangle2D(double x0, double y0, double w, double h)Main constructor, specifying position of reference corner and rectangle dimensions.Rectangle2D(Point2D p1, Point2D p2)Creates a rectangle from two corner points.Rectangle2D(java.awt.geom.Rectangle2D rect)Constructor from awt, to allow easy construction from existing apps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddVertex(Point2D point)Adds a vertex as last vertex of this polygon.booleanalmostEquals(GeometricObject2D obj, double eps)Checks if the two objects are similar up to a given threshold value.doublearea()Computes the area of this rectangle, given by the product of width by height.Polygon2DasPolygon(int n)Returns an approximation of the domain as a polygon, or a MultiPolygon.CirculinearContourArray2D<LinearRing2D>boundary()Overrides the definition of boundary() such that the boundary of a polygon is defined as a set of LinearRing2D.Box2DboundingBox()Returns the bounding box of the rectangle.CirculinearDomain2Dbuffer(double dist)Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.Point2Dcentroid()Computes the centroid (center of mass) of this rectangle.Polygon2Dclip(Box2D box)Returns the clipped polygon.intclosestVertexIndex(Point2D point)Computes the index of the closest vertex to the input point.Polygon2Dcomplement()Returns a new simple Polygon whose vertices are in reverse order of this rectangle.booleancontains(double x, double y)Checks if this rectangle contains the point given by (x,y)booleancontains(Point2D point)Checks if this rectangle contains the given point.java.util.Collection<LinearRing2D>contours()Returns the set of contours that enclose this domain.doubledistance(double x, double y)Returns the distance of the point to the polygon.doubledistance(Point2D p)Returns the distance of the point to the polygon.voiddraw(java.awt.Graphics2D g2)Draws the shape on the given graphics.intedgeNumber()Returns 4, as a rectangle has four edges.java.util.Collection<LineSegment2D>edges()Returns the four edges that constitute the boundary of this rectangle.booleanequals(java.lang.Object obj)Tests if rectangles are the same.voidfill(java.awt.Graphics2D g2)Fills the interior of the domain, using the Graphics current Paint.doublegetHeight()doublegetWidth()doublegetX()doublegetY()voidinsertVertex(int i, Point2D point)Inserts a vertex at the specified position.booleanisBounded()Always returns true, because a rectangle is always bounded.booleanisEmpty()Returns true if the shape does not contain any point.voidremoveVertex(int i)Removes the vertex at the given index.voidsetVertex(int i, Point2D point)Sets the position of the i-th vertexSimplePolygon2Dtransform(AffineTransform2D trans)Returns the new Polygon created by an affine transform of this polygon.CirculinearDomain2Dtransform(CircleInversion2D inv)Transforms the shape by a circle inversion.Point2Dvertex(int i)Returns the i-th vertex of the polygon.intvertexNumber()Returns the number of vertices of the rectangle, which is 4.java.util.Collection<Point2D>vertices()Returns the vertices of the rectangle as a collection of points.
-
-
-
Constructor Detail
-
Rectangle2D
public Rectangle2D(double x0, double y0, double w, double h)Main constructor, specifying position of reference corner and rectangle dimensions.
-
Rectangle2D
public Rectangle2D()
Empty constructor (size and position zero)
-
Rectangle2D
public Rectangle2D(java.awt.geom.Rectangle2D rect)
Constructor from awt, to allow easy construction from existing apps.
-
-
Method Detail
-
getX
public double getX()
-
getY
public double getY()
-
getWidth
public double getWidth()
-
getHeight
public double getHeight()
-
vertices
public java.util.Collection<Point2D> vertices()
Returns the vertices of the rectangle as a collection of points.
-
vertexNumber
public int vertexNumber()
Returns the number of vertices of the rectangle, which is 4.- Specified by:
vertexNumberin interfacePolygon2D- Since:
- 0.6.3
-
vertex
public Point2D vertex(int i)
Returns the i-th vertex of the polygon.
-
setVertex
public void setVertex(int i, Point2D point)Description copied from interface:Polygon2DSets the position of the i-th vertex
-
addVertex
public void addVertex(Point2D point)
Description copied from interface:Polygon2DAdds a vertex as last vertex of this polygon.
-
insertVertex
public void insertVertex(int i, Point2D point)Description copied from interface:Polygon2DInserts a vertex at the specified position.- Specified by:
insertVertexin interfacePolygon2D- Parameters:
i- index at which the specified vertex is to be insertedpoint- the position of the new vertex
-
removeVertex
public void removeVertex(int i)
Description copied from interface:Polygon2DRemoves the vertex at the given index.- Specified by:
removeVertexin interfacePolygon2D- Parameters:
i- index of the vertex to remove
-
closestVertexIndex
public int closestVertexIndex(Point2D point)
Computes the index of the closest vertex to the input point.- Specified by:
closestVertexIndexin interfacePolygon2D
-
edges
public java.util.Collection<LineSegment2D> edges()
Returns the four edges that constitute the boundary of this rectangle.
-
edgeNumber
public int edgeNumber()
Returns 4, as a rectangle has four edges.- Specified by:
edgeNumberin interfacePolygon2D
-
area
public double area()
Computes the area of this rectangle, given by the product of width by height.
-
centroid
public Point2D centroid()
Computes the centroid (center of mass) of this rectangle.
-
asPolygon
public Polygon2D asPolygon(int n)
Description copied from interface:Domain2DReturns an approximation of the domain as a polygon, or a MultiPolygon.
-
transform
public CirculinearDomain2D transform(CircleInversion2D inv)
Description copied from interface:CirculinearShape2DTransforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.- Specified by:
transformin interfaceCirculinearDomain2D- Specified by:
transformin interfaceCirculinearShape2D- Parameters:
inv- the circle inversion- Returns:
- the transformed shape
-
buffer
public CirculinearDomain2D buffer(double dist)
Description copied from interface:CirculinearShape2DComputes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.- Specified by:
bufferin interfaceCirculinearShape2D- Parameters:
dist- the maximal distance between a point of the buffer and the shape- Returns:
- the buffer of the shape
-
boundary
public CirculinearContourArray2D<LinearRing2D> boundary()
Description copied from interface:Polygon2DOverrides the definition of boundary() such that the boundary of a polygon is defined as a set of LinearRing2D.
-
contours
public java.util.Collection<LinearRing2D> contours()
Description copied from interface:Domain2DReturns the set of contours that enclose this domain. The result is a collection of shapes that implement the Contour2D interface.
-
complement
public Polygon2D complement()
Returns a new simple Polygon whose vertices are in reverse order of this rectangle.- Specified by:
complementin interfaceCirculinearDomain2D- Specified by:
complementin interfaceDomain2D- Specified by:
complementin interfacePolygon2D- Returns:
- the polygon complementary to this
-
isBounded
public boolean isBounded()
Always returns true, because a rectangle is always bounded.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Shape2DReturns true if the shape does not contain any point. This is the case for example for PointSet2D without any point.
-
distance
public double distance(Point2D p)
Returns the distance of the point to the polygon. The result is the minimal distance computed for each edge if the polygon, or ZERO if the point lies inside the polygon.
-
distance
public double distance(double x, double y)Returns the distance of the point to the polygon. The result is the minimal distance computed for each edge if the polygon, or ZERO if the point lies inside the polygon.
-
boundingBox
public Box2D boundingBox()
Returns the bounding box of the rectangle.- Specified by:
boundingBoxin interfaceShape2D- Returns:
- the bounding box of the shape.
-
transform
public SimplePolygon2D transform(AffineTransform2D trans)
Returns the new Polygon created by an affine transform of this polygon.
-
contains
public boolean contains(Point2D point)
Checks if this rectangle contains the given point.
-
contains
public boolean contains(double x, double y)Checks if this rectangle contains the point given by (x,y)
-
draw
public void draw(java.awt.Graphics2D g2)
Description copied from interface:Shape2DDraws the shape on the given graphics. If the shape is empty, nothing is drawn. If the shape is unbounded, an exception is thrown.
-
fill
public void fill(java.awt.Graphics2D g2)
Description copied from interface:Domain2DFills the interior of the domain, using the Graphics current Paint.
-
almostEquals
public boolean almostEquals(GeometricObject2D obj, double eps)
Description copied from interface:GeometricObject2DChecks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.- Specified by:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- a threshold value, for example the minimal coordinate difference- Returns:
- true if both object have the same value up to the threshold
-
equals
public boolean equals(java.lang.Object obj)
Tests if rectangles are the same.- Overrides:
equalsin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG