: Class Rectangle

Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## Class Rectangle

    java.lang.Object
      |
      +--Rectangle

Direct Known Subclasses:
  Shade, Spring

class Rectangle
extends java.lang.Object
implements GeometricObject, Rotatable

This class represents a Rectangle described by its width and height vectors. This class also implements Rotatable. This means it has a getAngle() method. The angle that is returned is the angle between the width vector and the x axis. This angle is always equal to or greater than 0 and strictly less than Math.PI/2.

Field Summary
`private double` | `angle` angle as described by getAngle() This is always between -PI and PI
`java.awt.Graphics` | `graphics` Graphics context for this Geometric object.
`private double` | `height` height
`private double` | `height_x` x component of the height vector.
`private double` | `height_y` y component of the height vector.
`private Polygon` | `points` The original data points
`long` | `time_stamp` Time stamp of this object.
`private double` | `width` width
`private double` | `width_x` x component of the width vector.
`private double` | `width_y` y component of the width vector.
`double` | `x` The x coordinate of the position of width vector.
`double` | `y` The y coordinate of the position of width vector

Fields inherited from interface GeometricObject
`CIRCLE, ELLIPSE, LINE, POINT, POLYGON, RECTANGLE, SQUARE`

Constructor Summary
`(package private)` | `Rectangle(double x, double y, double width_x, double width_y, double height)` The constructor.
`(package private)` | `Rectangle(double x, double y, Point width_vector, double height)` The constructor.
`(package private)` | `Rectangle(int x, int y, int width, int height)` The constructor.
`(package private)` | `Rectangle(Point upper_left_point, java.awt.Dimension dimension)` The constructor.
`(package private)` | `Rectangle(Point upper_left_point, java.awt.Dimension dimension, double angle)` The constructor.
`(package private)` | `Rectangle(java.awt.Rectangle rectangle)` The constructor.
`(package private)` | `Rectangle(Rectangle r)` The constructor.

Method Summary
`double` | `area()` Return area.
`boolean` | `containsGeometricObject(GeometricObject object)` Returns false if the argument is not completely inside this object.
`boolean` | `containsGeometricObjects(GeometricObject[] objects)` Returns false if the objects in the input array are completely inside this object.
`double` | `getAngle()` Returns the angle of the object WRT the x axis in radians.
`Point` | `getCenter()` Returns the center of this rectangle.
`Polygon` | `getDataPoints()` This method is used to get the original data points that forms this GeometricObject
`double` | `getHeight()` Returns the height
`double` | `getMajorAxisAngle()` Returns the angle between the longer of width or height vectors and the x axis.
`int` | `getMajorAxisDirection()` Returns the direction of the major axis of this Rectangle Known eksik: Should be tested.
`double` | `getMajorAxisLength()` Returns the larger of width and height.
`double` | `getMinorAxisAngle()` Returns the angle between the shorter of width or height vectors and the x axis.
`double` | `getMinorAxisLength()` Returns the smaller of width and height.
`Polygon` | `getPolygonalBounds()` This method should return a polygon that corresponds to this object.
`Rectangle` | `getRectangularBounds()` Supplied for completeness.
`long` | `getTimeStamp()` Returns the time stamp of the current Terminal
`java.lang.String` | `getType()` Implement GeometricObject
`double` | `getWidth()` Returns the width
`boolean` | `hasOnMajorAxisDirection(GeometricObject object)` This method should return true if the input object lies in the major axis direction of this Rectangle.
`static boolean` | `isRectangle(Polygon p)` Returns true if the input polygon looks like a Rectangle Can be optimized by eliminating Polygon conversions.
`void` | `paint()` Draw the object
`void` | `paint(java.awt.Graphics g)` Draw the object
`void` | `paint(java.awt.Graphics g, int thickness)` Draw the object
`void` | `paintOriginal(java.awt.Graphics g)` This method is used to paint the original data points that forms this GeometricObject
`boolean` | `pointIsOn(Point point, int radius)` Returns true if the point is within +-radius distance from the curve defining the object.
`boolean` | `pointIsOnOriginal(Point p, int radius)` Returns true if the point is within +-radius distance from the original curve defining the object.
`void` | `rotateAbout(Point p, double theta)` Rotates the rectangle about the point p theta radians CCW.
`void` | `scaleAboutCenter(double scale)` scaleAboutCenter
`void` | `setDataPoints(Polygon points)` This method is used to set the original data points that forms this GeometricObject
`void` | `setGraphicsContext(java.awt.Graphics g)` Set graphics context for this Geometric object.
`void` | `setRectangle(Rectangle r)` setRectangle
`void` | `setTimeStamp(long time_stamp)` Sets the time stamp of the current Terminal
`void` | `shade(java.awt.Graphics g, int number_of_shades)` Shade the object
`void` | `shade(java.awt.Graphics g, int shades, int thickness, int offset)` Shade the object
`int` | `spatialRelation(GeometricObject object)` This method should return the spatial relation of the input parameter with respect to this object.
`int` | `spatialRelation(GeometricObject object, double scale)` This method should return the spatial relation of the input parameter with respect to this object.
`int` | `spatialRelationCartesian(GeometricObject object)` This method should return the spatial relation of the input parameter with respect to this object.
`java.lang.String` | `toString()` Override toString
`boolean` | `touches(GeometricObject object)` This method should return true if the input objects touch.
`Rectangle` | `union(Rectangle rectangle)` Return the rectangularBounds of the union of this rectangle and the argument.

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait`

Field Detail

### points

    private Polygon points

  The original data points

### angle

    private double angle

  angle as described by getAngle() This is always between -PI and PI

### width_x

    private double width_x

  x component of the width vector.

### width_y

    private double width_y

  y component of the width vector.

### height_x

    private double height_x

  x component of the height vector.

### height_y

    private double height_y

  y component of the height vector.

### width

    private double width

  width

### height

    private double height

  height

### x

    public double x

  The x coordinate of the position of width vector.

### y

    public double y

  The y coordinate of the position of width vector

### time_stamp

    public long time_stamp

  Time stamp of this object.

### graphics

    public java.awt.Graphics graphics

  Graphics context for this Geometric object.

Constructor Detail

### Rectangle

    Rectangle(java.awt.Rectangle rectangle)

  The constructor.

### Rectangle

    Rectangle(Point upper_left_point,
              java.awt.Dimension dimension)

  The constructor.

### Rectangle

    Rectangle(Point upper_left_point,
              java.awt.Dimension dimension,
              double angle)

  The constructor.

### Rectangle

    Rectangle(double x,
              double y,
              Point width_vector,
              double height)

  The constructor.

### Rectangle

    Rectangle(double x,
              double y,
              double width_x,
              double width_y,
              double height)

  The constructor.

### Rectangle

    Rectangle(Rectangle r)

  The constructor.

### Rectangle

    Rectangle(int x,
              int y,
              int width,
              int height)

  The constructor.

Method Detail

### setRectangle

    public void setRectangle(Rectangle r)

  setRectangle

### scaleAboutCenter

    public void scaleAboutCenter(double scale)

  scaleAboutCenter

### getType

    public java.lang.String getType()

  Implement GeometricObject

### toString

    public java.lang.String toString()

  Override toString
  Overrides:
    toString in class java.lang.Object

### paint

    public void paint()

  Draw the object

### paintOriginal

    public void paintOriginal(java.awt.Graphics g)

  This method is used to paint the original data points that forms this GeometricObject

### paint

    public void paint(java.awt.Graphics g,
                      int thickness)

  Draw the object

### shade

    public void shade(java.awt.Graphics g,
                      int shades,
                      int thickness,
                      int offset)

  Shade the object

### paint

    public void paint(java.awt.Graphics g)

  Draw the object

### shade

    public void shade(java.awt.Graphics g,
                      int number_of_shades)

  Shade the object

### pointIsOn

    public boolean pointIsOn(Point point,
                             int radius)

  Returns true if the point is within +-radius distance from the curve defining the object. Returns false o/w.
  Specified by:
    pointIsOn in interface GeometricObject

### pointIsOnOriginal

    public boolean pointIsOnOriginal(Point p,
                                     int radius)

  Returns true if the point is within +-radius distance from the original curve defining the object. Returns false o/w.
  Specified by:
    pointIsOnOriginal in interface GeometricObject

### setGraphicsContext

    public void setGraphicsContext(java.awt.Graphics g)

  Set graphics context for this Geometric object. Must be set at least once before doing any drawing.

### touches

    public boolean touches(GeometricObject object)

  This method should return true if the input objects touch. It should be optimized making use of the object type information.
  Specified by:
    touches in interface GeometricObject

### getRectangularBounds

    public Rectangle getRectangularBounds()

  Supplied for completeness.
  Specified by:
    getRectangularBounds in interface GeometricObject

### containsGeometricObject

    public boolean containsGeometricObject(GeometricObject object)

  Returns false if the argument is not completely inside this object. Return true O/W.
  Specified by:
    containsGeometricObject in interface GeometricObject

### getPolygonalBounds

    public Polygon getPolygonalBounds()

  This method should return a polygon that corresponds to this object. The polygon is implicity closed and the last point doesn't necessarily have to be the same as the first (zeroth) point. The returned polygon is a liberal approximation to the real shape of the object. Known eksik: This should be refined to return a more conservative result.
  Specified by:
    getPolygonalBounds in interface GeometricObject

### spatialRelation

    public int spatialRelation(GeometricObject object,
                               double scale)

  This method should return the spatial relation of the input parameter with respect to this object. see the SpatialRelation class for a detailed list of possible spatial relations. Another version of this method should be implemented for handling spatial relations where a rotated coordinate system is to be used. In this method the center square is adjusted using the scale argument. Note that we are using the cartesian coordinates for all the operations, but the returned relationship is for the screen coordinates. In this scheme Y axis is pointing south rather than north as it is in cartesian coordinates. Known eksik: Does not handle cases when directions are 0. Example for scale: Scale = 1 => 100% Scale = 1.5 => 150% (0,0) |--------------------------> X | | | | | | | | | ___|___|___\ horizontal_up | | | / | | | | ___|___|___\ horizontal_down | | | / | | | | | | | V V | left right | | | | Y V

### spatialRelation

    public int spatialRelation(GeometricObject object)

  This method should return the spatial relation of the input parameter with respect to this object. see the SpatialRelation class for a detailed list of possible spatial relations. This method should hadles spatial relations where a rotated Rectangle is used (0,0) |--------------------------> X | | | | | | | | | ___|___|___\ horizontal_up | | | / | | | | ___|___|___\ horizontal_down | | | / | | | | | | | V V | left right | | | | Y V
  Specified by:
    spatialRelation in interface GeometricObject

### hasOnMajorAxisDirection

    public boolean hasOnMajorAxisDirection(GeometricObject object)

  This method should return true if the input object lies in the major axis direction of this Rectangle. Else return false. This uses the screen coordinate system. (0,0) |------------------------> X | | | /\ /\ | | | | | | | ___|__________|___\ | | | / | *****| |***** | ___|__________|___\ | | | / | | | | | | | | | | Y V

### spatialRelationCartesian

    public int spatialRelationCartesian(GeometricObject object)

  This method should return the spatial relation of the input parameter with respect to this object. see the SpatialRelation class for a detailed list of possible spatial relations. This returns the relationship in the cartesian coordinate system. Y /\ | | | /\ /\ | | | | | | | ___|___|___\ | | | / | | | | ___|___|___\ | | | / | | | | | | | | | | |--------------------------> X (0,0)

### getWidth

    public double getWidth()

  Returns the width

### getHeight

    public double getHeight()

  Returns the height

### getAngle

    public double getAngle()

  Returns the angle of the object WRT the x axis in radians. This should be made more general by adding an angle field to the class.
  Specified by:
    getAngle in interface Rotatable

### getMajorAxisLength

    public double getMajorAxisLength()

  Returns the larger of width and height.

### getMinorAxisLength

    public double getMinorAxisLength()

  Returns the smaller of width and height.

### rotateAbout

    public void rotateAbout(Point p,
                            double theta)

  Rotates the rectangle about the point p theta radians CCW.

### getCenter

    public Point getCenter()

  Returns the center of this rectangle.

### isRectangle

    public static boolean isRectangle(Polygon p)

  Returns true if the input polygon looks like a Rectangle Can be optimized by eliminating Polygon conversions.

### setTimeStamp

    public void setTimeStamp(long time_stamp)

  Sets the time stamp of the current Terminal

### getTimeStamp

    public long getTimeStamp()

  Returns the time stamp of the current Terminal

### getMinorAxisAngle

    public double getMinorAxisAngle()

  Returns the angle between the shorter of width or height vectors and the x axis.

### getMajorAxisAngle

    public double getMajorAxisAngle()

  Returns the angle between the longer of width or height vectors and the x axis.

### getMajorAxisDirection

    public int getMajorAxisDirection()

  Returns the direction of the major axis of this Rectangle Known eksik: Should be tested.

### setDataPoints

    public void setDataPoints(Polygon points)

  This method is used to set the original data points that forms this GeometricObject
  Specified by:
    setDataPoints in interface GeometricObject

### getDataPoints

    public Polygon getDataPoints()

  This method is used to get the original data points that forms this GeometricObject
  Specified by:
    getDataPoints in interface GeometricObject

### area

    public double area()

  Return area.

### union

    public Rectangle union(Rectangle rectangle)

  Return the rectangularBounds of the union of this rectangle and the argument.

### containsGeometricObjects

    public boolean containsGeometricObjects(GeometricObject[] objects)

  Returns false if the objects in the input array are completely inside this object. Return true O/W.
  Specified by:
    containsGeometricObjects in interface GeometricObject

Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD