Class mxRectangle

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    mxCellState, mxGeometry

    public class mxRectangle
    extends mxPoint
    Implements a 2-dimensional rectangle with double precision coordinates.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double height
      Holds the width and the height.
      protected double width
      Holds the width and the height.
      • Fields inherited from class com.mxgraph.util.mxPoint

        x, y
    • Constructor Summary

      Constructors 
      Constructor Description
      mxRectangle()
      Constructs a new rectangle at (0, 0) with the width and height set to 0.
      mxRectangle​(double x, double y, double width, double height)
      Constructs a rectangle using the given parameters.
      mxRectangle​(mxRectangle rect)
      Constructs a copy of the given rectangle.
      mxRectangle​(java.awt.geom.Rectangle2D rect)
      Constructs a copy of the given rectangle.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(mxRectangle rect)
      Adds the given rectangle to this rectangle.
      java.lang.Object clone()
      Returns a new instance of the same rectangle.
      boolean contains​(double x, double y)
      Returns true if the given point is contained in the rectangle.
      boolean equals​(java.lang.Object obj)
      Returns true if the given object equals this rectangle.
      double getCenterX()
      Returns the x-coordinate of the center.
      double getCenterY()
      Returns the y-coordinate of the center.
      double getHeight()
      Returns the height of the rectangle.
      java.awt.Rectangle getRectangle()
      Returns the bounds as a new rectangle.
      double getWidth()
      Returns the width of the rectangle.
      void grow​(double amount)
      Grows the rectangle by the given amount, that is, this method subtracts the given amount from the x- and y-coordinates and adds twice the amount to the width and height.
      mxPoint intersectLine​(double x0, double y0, double x1, double y1)
      Returns the point at which the specified point intersects the perimeter of this rectangle or null if there is no intersection.
      void rotate90()
      Rotates this rectangle by 90 degree around its center point.
      void setHeight​(double value)
      Sets the height of the rectangle.
      void setRect​(double x, double y, double w, double h)
      Sets this rectangle to the specified values
      void setWidth​(double value)
      Sets the width of the rectangle.
      java.lang.String toString()
      Returns the String representation of this mxRectangle.
      • Methods inherited from class java.lang.Object

        finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • width

        protected double width
        Holds the width and the height. Default is 0.
      • height

        protected double height
        Holds the width and the height. Default is 0.
    • Constructor Detail

      • mxRectangle

        public mxRectangle()
        Constructs a new rectangle at (0, 0) with the width and height set to 0.
      • mxRectangle

        public mxRectangle​(java.awt.geom.Rectangle2D rect)
        Constructs a copy of the given rectangle.
        Parameters:
        rect - Rectangle to construct a copy of.
      • mxRectangle

        public mxRectangle​(mxRectangle rect)
        Constructs a copy of the given rectangle.
        Parameters:
        rect - Rectangle to construct a copy of.
      • mxRectangle

        public mxRectangle​(double x,
                           double y,
                           double width,
                           double height)
        Constructs a rectangle using the given parameters.
        Parameters:
        x - X-coordinate of the new rectangle.
        y - Y-coordinate of the new rectangle.
        width - Width of the new rectangle.
        height - Height of the new rectangle.
    • Method Detail

      • getWidth

        public double getWidth()
        Returns the width of the rectangle.
        Returns:
        Returns the width.
      • setWidth

        public void setWidth​(double value)
        Sets the width of the rectangle.
        Parameters:
        value - Double that specifies the new width.
      • getHeight

        public double getHeight()
        Returns the height of the rectangle.
        Returns:
        Returns the height.
      • setHeight

        public void setHeight​(double value)
        Sets the height of the rectangle.
        Parameters:
        value - Double that specifies the new height.
      • setRect

        public void setRect​(double x,
                            double y,
                            double w,
                            double h)
        Sets this rectangle to the specified values
        Parameters:
        x - the new x-axis position
        y - the new y-axis position
        w - the new width of the rectangle
        h - the new height of the rectangle
      • add

        public void add​(mxRectangle rect)
        Adds the given rectangle to this rectangle.
      • getCenterX

        public double getCenterX()
        Returns the x-coordinate of the center.
        Returns:
        Returns the x-coordinate of the center.
      • getCenterY

        public double getCenterY()
        Returns the y-coordinate of the center.
        Returns:
        Returns the y-coordinate of the center.
      • grow

        public void grow​(double amount)
        Grows the rectangle by the given amount, that is, this method subtracts the given amount from the x- and y-coordinates and adds twice the amount to the width and height.
        Parameters:
        amount - Amount by which the rectangle should be grown.
      • contains

        public boolean contains​(double x,
                                double y)
        Returns true if the given point is contained in the rectangle.
        Parameters:
        x - X-coordinate of the point.
        y - Y-coordinate of the point.
        Returns:
        Returns true if the point is contained in the rectangle.
      • intersectLine

        public mxPoint intersectLine​(double x0,
                                     double y0,
                                     double x1,
                                     double y1)
        Returns the point at which the specified point intersects the perimeter of this rectangle or null if there is no intersection.
        Parameters:
        x0 - the x co-ordinate of the first point of the line
        y0 - the y co-ordinate of the first point of the line
        x1 - the x co-ordinate of the second point of the line
        y1 - the y co-ordinate of the second point of the line
        Returns:
        the point at which the line intersects this rectangle, or null if there is no intersection
      • getRectangle

        public java.awt.Rectangle getRectangle()
        Returns the bounds as a new rectangle.
        Returns:
        Returns a new rectangle for the bounds.
      • rotate90

        public void rotate90()
        Rotates this rectangle by 90 degree around its center point.
      • equals

        public boolean equals​(java.lang.Object obj)
        Returns true if the given object equals this rectangle.
        Overrides:
        equals in class mxPoint
      • clone

        public java.lang.Object clone()
        Returns a new instance of the same rectangle.
        Overrides:
        clone in class mxPoint
      • toString

        public java.lang.String toString()
        Returns the String representation of this mxRectangle.
        Overrides:
        toString in class mxPoint
        Returns:
        a String representing this mxRectangle.