/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The <code>Rectangle2D</code> class describes a rectangle
* defined by a location {@code (x,y)} and dimension
* {@code (w x h)}.
* <p>
* This class is only the abstract superclass for all objects that
* store a 2D rectangle.
* The actual storage representation of the coordinates is left to
* the subclass.
*
* @author Jim Graham
* @since 1.2
*/
/**
* The bitmask that indicates that a point lies to the left of
* this <code>Rectangle2D</code>.
* @since 1.2
*/
/**
* The bitmask that indicates that a point lies above
* this <code>Rectangle2D</code>.
* @since 1.2
*/
/**
* The bitmask that indicates that a point lies to the right of
* this <code>Rectangle2D</code>.
* @since 1.2
*/
/**
* The bitmask that indicates that a point lies below
* this <code>Rectangle2D</code>.
* @since 1.2
*/
/**
* The <code>Float</code> class defines a rectangle specified in float
* coordinates.
* @since 1.2
*/
/**
* The X coordinate of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public float x;
/**
* The Y coordinate of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public float y;
/**
* The width of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public float width;
/**
* The height of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public float height;
/**
* Constructs a new <code>Rectangle2D</code>, initialized to
* location (0.0, 0.0) and size (0.0, 0.0).
* @since 1.2
*/
public Float() {
}
/**
* Constructs and initializes a <code>Rectangle2D</code>
* from the specified <code>float</code> coordinates.
*
* @param x the X coordinate of the upper-left corner
* of the newly constructed <code>Rectangle2D</code>
* @param y the Y coordinate of the upper-left corner
* of the newly constructed <code>Rectangle2D</code>
* @param w the width of the newly constructed
* <code>Rectangle2D</code>
* @param h the height of the newly constructed
* <code>Rectangle2D</code>
* @since 1.2
*/
public Float(float x, float y, float w, float h) {
setRect(x, y, w, h);
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getX() {
return (double) x;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getY() {
return (double) y;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getWidth() {
return (double) width;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getHeight() {
return (double) height;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean isEmpty() {
}
/**
* Sets the location and size of this <code>Rectangle2D</code>
* to the specified <code>float</code> values.
*
* @param x the X coordinate of the upper-left corner
* of this <code>Rectangle2D</code>
* @param y the Y coordinate of the upper-left corner
* of this <code>Rectangle2D</code>
* @param w the width of this <code>Rectangle2D</code>
* @param h the height of this <code>Rectangle2D</code>
* @since 1.2
*/
public void setRect(float x, float y, float w, float h) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public void setRect(double x, double y, double w, double h) {
this.x = (float) x;
this.y = (float) y;
this.width = (float) w;
this.height = (float) h;
}
/**
* {@inheritDoc}
* @since 1.2
*/
this.x = (float) r.getX();
this.y = (float) r.getY();
}
/**
* {@inheritDoc}
* @since 1.2
*/
public int outcode(double x, double y) {
/*
* Note on casts to double below. If the arithmetic of
* x+w or y+h is done in float, then some bits may be
* lost if the binary exponents of x/y and w/h are not
* similar. By converting to double before the addition
* we force the addition to be carried out in double to
* avoid rounding error in the comparison.
*
* See bug 4320890 for problems that this inaccuracy causes.
*/
int out = 0;
if (this.width <= 0) {
} else if (x < this.x) {
} else if (x > this.x + (double) this.width) {
}
if (this.height <= 0) {
} else if (y < this.y) {
} else if (y > this.y + (double) this.height) {
out |= OUT_BOTTOM;
}
return out;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
if (r instanceof Float) {
} else {
}
return dest;
}
/**
* {@inheritDoc}
* @since 1.2
*/
if (r instanceof Float) {
} else {
}
return dest;
}
/**
* Returns the <code>String</code> representation of this
* <code>Rectangle2D</code>.
* @return a <code>String</code> representing this
* <code>Rectangle2D</code>.
* @since 1.2
*/
+ "[x=" + x +
",y=" + y +
",w=" + width +
}
/*
* JDK 1.6 serialVersionUID
*/
}
/**
* The <code>Double</code> class defines a rectangle specified in
* double coordinates.
* @since 1.2
*/
/**
* The X coordinate of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public double x;
/**
* The Y coordinate of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public double y;
/**
* The width of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public double width;
/**
* The height of this <code>Rectangle2D</code>.
* @since 1.2
* @serial
*/
public double height;
/**
* Constructs a new <code>Rectangle2D</code>, initialized to
* location (0, 0) and size (0, 0).
* @since 1.2
*/
public Double() {
}
/**
* Constructs and initializes a <code>Rectangle2D</code>
* from the specified <code>double</code> coordinates.
*
* @param x the X coordinate of the upper-left corner
* of the newly constructed <code>Rectangle2D</code>
* @param y the Y coordinate of the upper-left corner
* of the newly constructed <code>Rectangle2D</code>
* @param w the width of the newly constructed
* <code>Rectangle2D</code>
* @param h the height of the newly constructed
* <code>Rectangle2D</code>
* @since 1.2
*/
public Double(double x, double y, double w, double h) {
setRect(x, y, w, h);
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getX() {
return x;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getY() {
return y;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getWidth() {
return width;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public double getHeight() {
return height;
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean isEmpty() {
}
/**
* {@inheritDoc}
* @since 1.2
*/
public void setRect(double x, double y, double w, double h) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
}
/**
* {@inheritDoc}
* @since 1.2
*/
this.x = r.getX();
this.y = r.getY();
}
/**
* {@inheritDoc}
* @since 1.2
*/
public int outcode(double x, double y) {
int out = 0;
if (this.width <= 0) {
} else if (x < this.x) {
} else if (x > this.x + this.width) {
}
if (this.height <= 0) {
} else if (y < this.y) {
} else if (y > this.y + this.height) {
out |= OUT_BOTTOM;
}
return out;
}
/**
* {@inheritDoc}
* @since 1.2
*/
}
/**
* {@inheritDoc}
* @since 1.2
*/
return dest;
}
/**
* {@inheritDoc}
* @since 1.2
*/
return dest;
}
/**
* Returns the <code>String</code> representation of this
* <code>Rectangle2D</code>.
* @return a <code>String</code> representing this
* <code>Rectangle2D</code>.
* @since 1.2
*/
+ "[x=" + x +
",y=" + y +
",w=" + width +
}
/*
* JDK 1.6 serialVersionUID
*/
}
/**
* This is an abstract class that cannot be instantiated directly.
* Type-specific implementation subclasses are available for
* instantiation and provide a number of formats for storing
* the information necessary to satisfy the various accessor
* methods below.
*
* @see java.awt.geom.Rectangle2D.Float
* @see java.awt.geom.Rectangle2D.Double
* @see java.awt.Rectangle
* @since 1.2
*/
protected Rectangle2D() {
}
/**
* Sets the location and size of this <code>Rectangle2D</code>
* to the specified <code>double</code> values.
*
* @param x the X coordinate of the upper-left corner
* of this <code>Rectangle2D</code>
* @param y the Y coordinate of the upper-left corner
* of this <code>Rectangle2D</code>
* @param w the width of this <code>Rectangle2D</code>
* @param h the height of this <code>Rectangle2D</code>
* @since 1.2
*/
public abstract void setRect(double x, double y, double w, double h);
/**
* Sets this <code>Rectangle2D</code> to be the same as the specified
* <code>Rectangle2D</code>.
* @param r the specified <code>Rectangle2D</code>
* @since 1.2
*/
}
/**
* Tests if the specified line segment intersects the interior of this
* <code>Rectangle2D</code>.
*
* @param x1 the X coordinate of the start point of the specified
* line segment
* @param y1 the Y coordinate of the start point of the specified
* line segment
* @param x2 the X coordinate of the end point of the specified
* line segment
* @param y2 the Y coordinate of the end point of the specified
* line segment
* @return <code>true</code> if the specified line segment intersects
* the interior of this <code>Rectangle2D</code>; <code>false</code>
* otherwise.
* @since 1.2
*/
return true;
}
return false;
}
double x = getX();
x += getWidth();
}
x1 = x;
} else {
double y = getY();
y += getHeight();
}
y1 = y;
}
}
return true;
}
/**
* Tests if the specified line segment intersects the interior of this
* <code>Rectangle2D</code>.
* @param l the specified {@link Line2D} to test for intersection
* with the interior of this <code>Rectangle2D</code>
* @return <code>true</code> if the specified <code>Line2D</code>
* intersects the interior of this <code>Rectangle2D</code>;
* <code>false</code> otherwise.
* @since 1.2
*/
}
/**
* Determines where the specified coordinates lie with respect
* to this <code>Rectangle2D</code>.
* This method computes a binary OR of the appropriate mask values
* indicating, for each side of this <code>Rectangle2D</code>,
* whether or not the specified coordinates are on the same side
* of the edge as the rest of this <code>Rectangle2D</code>.
* @param x the specified X coordinate
* @param y the specified Y coordinate
* @return the logical OR of all appropriate out codes.
* @see #OUT_LEFT
* @see #OUT_TOP
* @see #OUT_RIGHT
* @see #OUT_BOTTOM
* @since 1.2
*/
public abstract int outcode(double x, double y);
/**
* Determines where the specified {@link Point2D} lies with
* respect to this <code>Rectangle2D</code>.
* This method computes a binary OR of the appropriate mask values
* indicating, for each side of this <code>Rectangle2D</code>,
* whether or not the specified <code>Point2D</code> is on the same
* side of the edge as the rest of this <code>Rectangle2D</code>.
* @param p the specified <code>Point2D</code>
* @return the logical OR of all appropriate out codes.
* @see #OUT_LEFT
* @see #OUT_TOP
* @see #OUT_RIGHT
* @see #OUT_BOTTOM
* @since 1.2
*/
}
/**
* Sets the location and size of the outer bounds of this
* <code>Rectangle2D</code> to the specified rectangular values.
*
* @param x the X coordinate of the upper-left corner
* of this <code>Rectangle2D</code>
* @param y the Y coordinate of the upper-left corner
* of this <code>Rectangle2D</code>
* @param w the width of this <code>Rectangle2D</code>
* @param h the height of this <code>Rectangle2D</code>
* @since 1.2
*/
public void setFrame(double x, double y, double w, double h) {
setRect(x, y, w, h);
}
/**
* {@inheritDoc}
* @since 1.2
*/
return (Rectangle2D) clone();
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean contains(double x, double y) {
return (x >= x0 &&
y >= y0 &&
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean intersects(double x, double y, double w, double h) {
return false;
}
return (x + w > x0 &&
y + h > y0 &&
}
/**
* {@inheritDoc}
* @since 1.2
*/
public boolean contains(double x, double y, double w, double h) {
return false;
}
return (x >= x0 &&
y >= y0 &&
}
/**
* Returns a new <code>Rectangle2D</code> object representing the
* intersection of this <code>Rectangle2D</code> with the specified
* <code>Rectangle2D</code>.
* @param r the <code>Rectangle2D</code> to be intersected with
* this <code>Rectangle2D</code>
* @return the largest <code>Rectangle2D</code> contained in both
* the specified <code>Rectangle2D</code> and in this
* <code>Rectangle2D</code>.
* @since 1.2
*/
/**
* Intersects the pair of specified source <code>Rectangle2D</code>
* objects and puts the result into the specified destination
* <code>Rectangle2D</code> object. One of the source rectangles
* can also be the destination to avoid creating a third Rectangle2D
* object, but in this case the original points of this source
* rectangle will be overwritten by this method.
* @param src1 the first of a pair of <code>Rectangle2D</code>
* objects to be intersected with each other
* @param src2 the second of a pair of <code>Rectangle2D</code>
* objects to be intersected with each other
* @param dest the <code>Rectangle2D</code> that holds the
* results of the intersection of <code>src1</code> and
* <code>src2</code>
* @since 1.2
*/
Rectangle2D dest) {
}
/**
* Returns a new <code>Rectangle2D</code> object representing the
* union of this <code>Rectangle2D</code> with the specified
* <code>Rectangle2D</code>.
* @param r the <code>Rectangle2D</code> to be combined with
* this <code>Rectangle2D</code>
* @return the smallest <code>Rectangle2D</code> containing both
* the specified <code>Rectangle2D</code> and this
* <code>Rectangle2D</code>.
* @since 1.2
*/
/**
* Unions the pair of source <code>Rectangle2D</code> objects
* and puts the result into the specified destination
* <code>Rectangle2D</code> object. One of the source rectangles
* can also be the destination to avoid creating a third Rectangle2D
* object, but in this case the original points of this source
* rectangle will be overwritten by this method.
* @param src1 the first of a pair of <code>Rectangle2D</code>
* objects to be combined with each other
* @param src2 the second of a pair of <code>Rectangle2D</code>
* objects to be combined with each other
* @param dest the <code>Rectangle2D</code> that holds the
* results of the union of <code>src1</code> and
* <code>src2</code>
* @since 1.2
*/
Rectangle2D dest) {
}
/**
* Adds a point, specified by the double precision arguments
* <code>newx</code> and <code>newy</code>, to this
* <code>Rectangle2D</code>. The resulting <code>Rectangle2D</code>
* is the smallest <code>Rectangle2D</code> that
* contains both the original <code>Rectangle2D</code> and the
* specified point.
* <p>
* After adding a point, a call to <code>contains</code> with the
* added point as an argument does not necessarily return
* <code>true</code>. The <code>contains</code> method does not
* return <code>true</code> for points on the right or bottom
* edges of a rectangle. Therefore, if the added point falls on
* the left or bottom edge of the enlarged rectangle,
* <code>contains</code> returns <code>false</code> for that point.
* @param newx the X coordinate of the new point
* @param newy the Y coordinate of the new point
* @since 1.2
*/
}
/**
* Adds the <code>Point2D</code> object <code>pt</code> to this
* <code>Rectangle2D</code>.
* The resulting <code>Rectangle2D</code> is the smallest
* <code>Rectangle2D</code> that contains both the original
* <code>Rectangle2D</code> and the specified <code>Point2D</code>.
* <p>
* After adding a point, a call to <code>contains</code> with the
* added point as an argument does not necessarily return
* <code>true</code>. The <code>contains</code>
* method does not return <code>true</code> for points on the right
* or bottom edges of a rectangle. Therefore, if the added point falls
* on the left or bottom edge of the enlarged rectangle,
* <code>contains</code> returns <code>false</code> for that point.
* @param pt the new <code>Point2D</code> to add to this
* <code>Rectangle2D</code>.
* @since 1.2
*/
}
/**
* Adds a <code>Rectangle2D</code> object to this
* <code>Rectangle2D</code>. The resulting <code>Rectangle2D</code>
* is the union of the two <code>Rectangle2D</code> objects.
* @param r the <code>Rectangle2D</code> to add to this
* <code>Rectangle2D</code>.
* @since 1.2
*/
}
/**
* Returns an iteration object that defines the boundary of this
* <code>Rectangle2D</code>.
* The iterator for this class is multi-threaded safe, which means
* that this <code>Rectangle2D</code> class guarantees that
* modifications to the geometry of this <code>Rectangle2D</code>
* object do not affect any iterations of that geometry that
* are already in process.
* @param at an optional <code>AffineTransform</code> to be applied to
* the coordinates as they are returned in the iteration, or
* <code>null</code> if untransformed coordinates are desired
* @return the <code>PathIterator</code> object that returns the
* geometry of the outline of this
* <code>Rectangle2D</code>, one segment at a time.
* @since 1.2
*/
return new RectIterator(this, at);
}
/**
* Returns an iteration object that defines the boundary of the
* flattened <code>Rectangle2D</code>. Since rectangles are already
* flat, the <code>flatness</code> parameter is ignored.
* The iterator for this class is multi-threaded safe, which means
* that this <code>Rectangle2D</code> class guarantees that
* modifications to the geometry of this <code>Rectangle2D</code>
* object do not affect any iterations of that geometry that
* are already in process.
* @param at an optional <code>AffineTransform</code> to be applied to
* the coordinates as they are returned in the iteration, or
* <code>null</code> if untransformed coordinates are desired
* @param flatness the maximum distance that the line segments used to
* approximate the curved segments are allowed to deviate from any
* point on the original curve. Since rectangles are already flat,
* the <code>flatness</code> parameter is ignored.
* @return the <code>PathIterator</code> object that returns the
* geometry of the outline of this
* <code>Rectangle2D</code>, one segment at a time.
* @since 1.2
*/
return new RectIterator(this, at);
}
/**
* Returns the hashcode for this <code>Rectangle2D</code>.
* @return the hashcode for this <code>Rectangle2D</code>.
* @since 1.2
*/
public int hashCode() {
}
/**
* Determines whether or not the specified <code>Object</code> is
* equal to this <code>Rectangle2D</code>. The specified
* <code>Object</code> is equal to this <code>Rectangle2D</code>
* if it is an instance of <code>Rectangle2D</code> and if its
* location and size are the same as this <code>Rectangle2D</code>.
* @param obj an <code>Object</code> to be compared with this
* <code>Rectangle2D</code>.
* @return <code>true</code> if <code>obj</code> is an instance
* of <code>Rectangle2D</code> and has
* the same values; <code>false</code> otherwise.
* @since 1.2
*/
if (obj == this) {
return true;
}
if (obj instanceof Rectangle2D) {
}
return false;
}
}