ImageScience 3.0.0

imagescience.shape
Class Rectangle

java.lang.Object
  extended by imagescience.shape.Rectangle
All Implemented Interfaces:
Shape

public class Rectangle
extends java.lang.Object
implements Shape

A rectangle in the x-y plane.


Constructor Summary
Rectangle()
          Default constructor.
Rectangle(double x, double y, double width, double height)
          Constructs a rectangle with given top-left corner position, width and height.
Rectangle(Rectangle rectangle)
          Copy constructor.
 
Method Summary
 double area()
          Returns the area spanned by the rectangle.
 Image bitmap(boolean binary)
          Computes a bitmapped version of the shape.
 Bounds bounds()
          Computes the bounding box of the shape.
 boolean contains(double x, double y)
          Indicates the position of a point relative to the rectangle.
 boolean contains(Point point)
          Indicates the position of a point relative to the rectangle.
 java.awt.geom.GeneralPath contour()
          Returns the contour of the rectangle.
 Shape duplicate()
          Duplicates the shape.
 boolean empty()
          Indicates whether the shape is empty.
 boolean equals(Shape shape)
          Indicates whether this object has the same shape as the given object.
 double height()
          Returns the height of the rectangle.
 void height(double height)
          Sets the height of the rectangle.
 double perimeter()
          Returns the perimeter of the rectangle.
 void position(double x, double y)
          Sets the top-left corner position of the rectangle.
 void set(double x, double y, double width, double height)
          Sets the top-left corner position and size of the rectangle.
 void size(double width, double height)
          Sets the size of the rectangle.
 void translate(double dx, double dy)
          Translates the rectangle over the given distance.
 double width()
          Returns the width of the rectangle.
 void width(double width)
          Sets the width of the rectangle.
 double x()
          Returns the x-coordinate of the top-left corner of the rectangle.
 void x(double x)
          Sets the x-coordinate of the top-left corner of the rectangle.
 double y()
          Returns the y-coordinate of the top-left corner of the rectangle.
 void y(double y)
          Sets the y-coordinate of the top-left corner of the rectangle.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle()
Default constructor. Results in a rectangle with top-left corner at the origin and with unit width and height.


Rectangle

public Rectangle(double x,
                 double y,
                 double width,
                 double height)
Constructs a rectangle with given top-left corner position, width and height.

Parameters:
x - The x-coordinate of the top-left position of the rectangle.
y - The y-coordinate of the top-left position of the rectangle.
width - The width of the rectangle.
height - The height of the rectangle.
Throws:
java.lang.IllegalArgumentException - If width or height is less than 0.

Rectangle

public Rectangle(Rectangle rectangle)
Copy constructor.

Parameters:
rectangle - The rectangle to be copied. All information is copied and no memory is shared with this rectangle.
Throws:
java.lang.NullPointerException - If rectangle is null.
Method Detail

x

public void x(double x)
Sets the x-coordinate of the top-left corner of the rectangle.

Parameters:
x - The x-coordinate of the top-left position of the rectangle.

y

public void y(double y)
Sets the y-coordinate of the top-left corner of the rectangle.

Parameters:
y - The y-coordinate of the top-left position of the rectangle.

width

public void width(double width)
Sets the width of the rectangle.

Parameters:
width - The width of the rectangle.
Throws:
java.lang.IllegalArgumentException - If width is less than 0.

height

public void height(double height)
Sets the height of the rectangle.

Parameters:
height - The height of the rectangle.
Throws:
java.lang.IllegalArgumentException - If height is less than 0.

x

public double x()
Returns the x-coordinate of the top-left corner of the rectangle.

Returns:
The x-coordinate of the top-left corner of the rectangle.

y

public double y()
Returns the y-coordinate of the top-left corner of the rectangle.

Returns:
The y-coordinate of the top-left corner of the rectangle.

width

public double width()
Returns the width of the rectangle.

Returns:
The width of the rectangle.

height

public double height()
Returns the height of the rectangle.

Returns:
The height of the rectangle.

perimeter

public double perimeter()
Returns the perimeter of the rectangle.

Returns:
The perimeter of the rectangle.

area

public double area()
Returns the area spanned by the rectangle.

Returns:
The area spanned by the rectangle.

position

public void position(double x,
                     double y)
Sets the top-left corner position of the rectangle.

Parameters:
x - The x-coordinate of the top-left position of the rectangle.
y - The y-coordinate of the top-left position of the rectangle.

translate

public void translate(double dx,
                      double dy)
Translates the rectangle over the given distance.

Parameters:
dx - The distance in the x-dimension over which to translate.
dy - The distance in the y-dimension over which to translate.

duplicate

public Shape duplicate()
Description copied from interface: Shape
Duplicates the shape.

Specified by:
duplicate in interface Shape
Returns:
A new Shape object that is an exact copy of this object. All information is copied and no memory is shared between this and the returned object.

set

public void set(double x,
                double y,
                double width,
                double height)
Sets the top-left corner position and size of the rectangle.

Parameters:
x - The x-coordinate of the top-left position of the rectangle.
y - The y-coordinate of the top-left position of the rectangle.
width - The width of the rectangle.
height - The height of the rectangle.
Throws:
java.lang.IllegalArgumentException - If width or height is less than 0.

size

public void size(double width,
                 double height)
Sets the size of the rectangle.

Parameters:
width - The width of the rectangle.
height - The height of the rectangle.
Throws:
java.lang.IllegalArgumentException - If width or height is less than 0.

contains

public boolean contains(Point point)
Indicates the position of a point relative to the rectangle.

Specified by:
contains in interface Shape
Parameters:
point - The point whose position relative to the rectangle is to be tested. The point is treated as a 2D point. That is, only its x- and y-coordinate values are considered.
Returns:
The value contains(point.x,point.y).
Throws:
java.lang.NullPointerException - If point is null.

contains

public boolean contains(double x,
                        double y)
Indicates the position of a point relative to the rectangle.

Parameters:
x - The x-coordinate of the point.
y - The y-coordinate of the point.
Returns:
Value true if the point is on or inside the rectangle, or false if it is outside the rectangle.

contour

public java.awt.geom.GeneralPath contour()
Returns the contour of the rectangle.

Returns:
A new GeneralPath object containing the contour of the rectangle.

bitmap

public Image bitmap(boolean binary)
Description copied from interface: Shape
Computes a bitmapped version of the shape.

Specified by:
bitmap in interface Shape
Parameters:
binary - Determines whether the returned bitmap image is two-valued. If true, image elements whose center positions fall inside the shape are set to 255, and elements whose center positions fall outside the shape are set to 0. If false, additional processing is performed, by which each image element falling partly inside and partly outside the shape is set to 255 times its (approximate) inside-fraction.
Returns:
A new ByteImage object containing a bitmapped version of the shape. The origin of the integer coordinate system of the image corresponds to the position in the shape coordinate system obtained by taking the floor value of the lower bound of the shape in each dimension.

bounds

public Bounds bounds()
Description copied from interface: Shape
Computes the bounding box of the shape.

Specified by:
bounds in interface Shape
Returns:
A new Bounds object containing the bounding box of the shape.

equals

public boolean equals(Shape shape)
Description copied from interface: Shape
Indicates whether this object has the same shape as the given object.

Specified by:
equals in interface Shape
Parameters:
shape - The shape to compare this shape with.
Returns:
Value true if shape is not null, and an instance of the same class as this object, with the exact same shape, or false if this is not the case.

empty

public boolean empty()
Description copied from interface: Shape
Indicates whether the shape is empty.

Specified by:
empty in interface Shape
Returns:
Value true if the shape does not enclose any space, or false if it does.

ImageScience 3.0.0

Copyright (C) Erik Meijering. Permission to use this software and corresponding documentation for educational, research, and not-for-profit purposes, without a fee and without a signed licensing agreement, is granted, subject to the following terms and conditions.

IT IS NOT ALLOWED TO REDISTRIBUTE, SELL, OR LEASE THIS SOFTWARE, OR DERIVATIVE WORKS THEREOF, WITHOUT PERMISSION IN WRITING FROM THE COPYRIGHT HOLDER. THE COPYRIGHT HOLDER IS FREE TO MAKE VERSIONS OF THE SOFTWARE AVAILABLE FOR A FEE OR COMMERCIALLY ONLY.

IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OF ANY KIND WHATSOEVER, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.

THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE EXPRESS OR IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND CORRESPONDING DOCUMENTATION IS PROVIDED "AS IS". THE COPYRIGHT HOLDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.