Class Rectangle

All Implemented Interfaces:
Geometry, Surface, Serializable, Cloneable
Direct Known Subclasses:
Rectangle.Double, Rectangle.Float

public abstract class Rectangle extends DefaultGeometry implements Surface
See Also:
  • Field Details

    • coord

      protected Point coord
  • Constructor Details

    • Rectangle

      protected Rectangle()
  • Method Details

    • createBigRectangle

      public static Rectangle createBigRectangle()
    • pointOnSurface

      public Point pointOnSurface()
      Description copied from interface: Surface
      Returns a point that is located in the interior of this surface geometry.
      Specified by:
      pointOnSurface in interface Surface
      Returns:
      a point on thge surface.
    • getCenteredPoint

      public Point getCenteredPoint()
      Description copied from interface: Geometry
      This method returns a point that is typically centered on the geometry. If the geometry is a point, the point is returned. If it is a line, a point on the curve interpolated at 50% is returned. If the geometry is a surface, the centroid is returned if it is inside the polygon, if not, a point inside the polygon (but likely not exactly in the center) will be returned. If the geometry is a collection, the method is called on the first part of the collection.
      Specified by:
      getCenteredPoint in interface Geometry
      Returns:
      a point likely at the center of the geometry
      See Also:
    • getHeight

      public abstract double getHeight()
      Returns:
    • getCoord

      public Point getCoord()
      Returns:
      Bottom-left coordinates
    • getWidth

      public abstract double getWidth()
      Returns:
    • setHeight

      public abstract void setHeight(double height)
      Parameters:
      height -
    • clone

      public abstract Rectangle clone()
      Description copied from class: DefaultGeometry
      Clones this geometry.
      Specified by:
      clone in interface Geometry
      Specified by:
      clone in class DefaultGeometry
      Returns:
      a deep copy of the current geometry.
    • setCoord

      public void setCoord(double x, double y)
      Parameters:
      x -
      y -
    • setCoord

      public void setCoord(Point coord)
      Parameters:
      coord -
    • setWidth

      public abstract void setWidth(double width)
      Parameters:
      width -
    • getMinX

      public abstract double getMinX()
    • getMinY

      public abstract double getMinY()
    • getMaxX

      public abstract double getMaxX()
    • getMaxY

      public abstract double getMaxY()
    • createBounds

      public void createBounds()
      Description copied from interface: Geometry
      Updates the geometry bounds from the current geometry.
      Specified by:
      createBounds in interface Geometry
    • getBounds

      public Rectangle getBounds()
      Description copied from interface: Geometry
      Returns the minimum bounding rectangle of this geometry.
      Specified by:
      getBounds in interface Geometry
      Returns:
      the bounding box of this geometry.
    • setBounds

      public void setBounds(Rectangle rect)
      Sets the new bounds of this rectangle.
      Parameters:
      rect - the new bounds to set.
    • area

      public double area()
      Description copied from interface: Surface
      Computes and returns the surface area.
      Specified by:
      area in interface Geometry
      Specified by:
      area in interface Surface
      Returns:
      the surface area.
    • length

      public double length()
      Description copied from interface: Geometry
      Returns the geometry length. If the geometry is a surface, then the geometry perimeter shall be returned.
      Specified by:
      length in interface Geometry
      Returns:
      the geometry length.
    • centroid

      public Point centroid()
      Description copied from interface: Surface
      Returns the centroid of the current surface.
      Specified by:
      centroid in interface Surface
      Returns:
      the centroid.
    • add

      public Rectangle add(Rectangle rect)
      Modifies this rectangle so that it is equal to the sum of the two rectangles. The result contains the two rectangles entirely.
      Parameters:
      rect - the rectangle to add
      Returns:
      the modified rectangle
    • intersects

      public boolean intersects(Rectangle rect)
    • intersects

      public boolean intersects(Rectangle rect, PrecisionModel precisionModel)
    • intersects

      public static boolean intersects(Rectangle rect, double x, double y, double width, double height)
    • intersects

      public static boolean intersects(Rectangle rect, double x, double y, double width, double height, PrecisionModel precisionModel)
    • intersection

      public Rectangle intersection(Rectangle rect)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • spatiallyEquals

      public boolean spatiallyEquals(Geometry geometry, PrecisionModel precisionModel)
      Description copied from interface: Geometry
      Tests if this geometry is equal to the argument, on a topological point of view.
      Specified by:
      spatiallyEquals in interface Geometry
      Parameters:
      geometry - the geometry to be tested.
      precisionModel - the precision model to use while comparing geometries.
      Returns:
      whether both geometries are spatially equals.
    • contains

      public boolean contains(Point coord)
    • contains

      public boolean contains(Point coord, PrecisionModel precisionModel)
    • contains

      public boolean contains(double x, double y)
    • contains

      public boolean contains(double x, double y, double tolerance)
    • translate

      public void translate(double dx, double dy)
      Description copied from interface: Geometry
      Translate this geometry with the specified values.
      Specified by:
      translate in interface Geometry
      Parameters:
      dx - translation on the X-axis.
      dy - translation on the Y-axis.
    • inflate

      public Rectangle inflate(double factor)
    • add

      public static Rectangle add(Rectangle r1, Rectangle r2)
      Adds the second rectangle to the first rectangle specified. If one of the rectangle is null, the other non-null rectangle is returned. If both rectangles are null, null is returned.
      Parameters:
      r1 - the first rectangle
      r2 - the second rectangle
      Returns:
      the addition of both rectangles.
    • translate

      public static Rectangle translate(Rectangle rect, double dx, double dy)
      Creates a clone of the specified rectangle et translates it by the specified values.
      Parameters:
      rect - the rectangle to translate.
      dx - the value to add to the X coordinate.
      dy - the value to add to the Y coordinate.
      Returns:
      a new rectangle initialized using the specified rectangle and translated by the specified values.
    • intersects

      public static boolean intersects(Point p, Rectangle rect)
      fast intersects test (faster than the one for geometries in general)
    • intersects

      public static boolean intersects(Point p, Rectangle rect, PrecisionModel precisionModel)
      fast intersects test (faster than the one for geometries in general)
      Parameters:
      p -
      rect -
      precisionModel -
      Returns:
    • intersects

      public static boolean intersects(LineString l, Rectangle rect, PrecisionModel precisionModel)
      fast intersects test (faster than the one for geometries in general)
      Parameters:
      l -
      rect -
      precisionModel -
      Returns:
    • intersects

      public static boolean intersects(Polygon poly, Rectangle rect, PrecisionModel precisionModel)
      fast intersects test (faster than the one for geometries in general)
      Parameters:
      poly -
      rect -
      precisionModel -
      Returns:
    • intersection

      public static Geometry intersection(Geometry geo, Rectangle rect)
    • intersection

      public static Geometry intersection(Geometry geo, Rectangle rect, PrecisionModel precisionModel)
    • toAwtRectangle

      public Rectangle toAwtRectangle()
    • getGeometryId

      public short getGeometryId()
      Description copied from interface: Geometry
      Returns the geometry class id. This method is useful for geometry serialization.
      Specified by:
      getGeometryId in interface Geometry
      Returns:
      a new Polygon
    • getGeometryType

      public int getGeometryType()
      Description copied from interface: Geometry
      Returns the geometry type for this geometry.
      Specified by:
      getGeometryType in interface Geometry
      Returns:
      the geometry type.
      See Also:
    • transform

      public Geometry transform(Transformation tr)
      Creates a clone of the current rectangle and returns the new instance tranformed with the specified geometry transformation.
      The returned geometry can be of any geometry types after the transformation.
      Specified by:
      transform in interface Geometry
      Parameters:
      tr - the transformation to apply.
      Returns:
      the newly created and transformed geometry instance.
    • toPolygon

      public Polygon toPolygon()
    • toPolygon

      public Polygon toPolygon(double maxNodeDistance)
      Creates a polygon from the rectangle, inserting nodes along the sides of the rectangle so that the maximum distance between 2 nodes is less than the specified distance.
      Parameters:
      maxNodeDistance - the maximum distance between 2 nodes of the polygon
      Returns:
      the resulting polygon
    • boundary

      public Geometry boundary()
      Description copied from interface: Geometry
      Returns the boundary of this geometry as a line string.
      Specified by:
      boundary in interface Geometry
      Returns:
      a line string which defines the boundary of the current geometry.
    • serialize

      public Point[] serialize()
      Description copied from interface: Geometry
      Returns this geometry as an array of Point.
      Specified by:
      serialize in interface Geometry
      Returns:
      this geometry as an array of Point.
    • asText

      public String asText()
      Description copied from class: DefaultGeometry
      Returns this geometry encoded using the Well-Known Text (WKT) standard.
      Specified by:
      asText in interface Geometry
      Overrides:
      asText in class DefaultGeometry
      Returns:
      a WKT geometry.