FileDocCategorySizeDatePackage
Ellipse2D.javaAPI DocJava SE 6 API11505Tue Jun 10 00:25:26 BST 2008java.awt.geom

Ellipse2D

public abstract class Ellipse2D extends RectangularShape
The Ellipse2D class describes an ellipse that is defined by a framing rectangle.

This class is only the abstract superclass for all objects which store a 2D ellipse. The actual storage representation of the coordinates is left to the subclass.

version
1.20, 02/24/06
author
Jim Graham
since
1.2

Fields Summary
Constructors Summary
protected Ellipse2D()
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.Ellipse2D.Float
see
java.awt.geom.Ellipse2D.Double
since
1.2

    

                                                  
      
    
Methods Summary
public booleancontains(double x, double y)
{@inheritDoc}

since
1.2

	// Normalize the coordinates compared to the ellipse
	// having a center at 0,0 and a radius of 0.5.
	double ellw = getWidth();
	if (ellw <= 0.0) {
	    return false;
	}
	double normx = (x - getX()) / ellw - 0.5;
	double ellh = getHeight();
	if (ellh <= 0.0) {
	    return false;
	}
	double normy = (y - getY()) / ellh - 0.5;
	return (normx * normx + normy * normy) < 0.25;
    
public booleancontains(double x, double y, double w, double h)
{@inheritDoc}

since
1.2

	return (contains(x, y) &&
		contains(x + w, y) &&
		contains(x, y + h) &&
		contains(x + w, y + h));
    
public booleanequals(java.lang.Object obj)
Determines whether or not the specified Object is equal to this Ellipse2D. The specified Object is equal to this Ellipse2D if it is an instance of Ellipse2D and if its location and size are the same as this Ellipse2D.

param
obj an Object to be compared with this Ellipse2D.
return
true if obj is an instance of Ellipse2D and has the same values; false otherwise.
since
1.6

        if (obj == this) {
            return true;
        }
        if (obj instanceof Ellipse2D) {
            Ellipse2D e2d = (Ellipse2D) obj;
            return ((getX() == e2d.getX()) &&
                    (getY() == e2d.getY()) &&
                    (getWidth() == e2d.getWidth()) &&
                    (getHeight() == e2d.getHeight()));
        }
        return false;
    
public java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at)
Returns an iteration object that defines the boundary of this Ellipse2D. The iterator for this class is multi-threaded safe, which means that this Ellipse2D class guarantees that modifications to the geometry of this Ellipse2D object do not affect any iterations of that geometry that are already in process.

param
at an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
return
the PathIterator object that returns the geometry of the outline of this Ellipse2D, one segment at a time.
since
1.2

	return new EllipseIterator(this, at);
    
public inthashCode()
Returns the hashcode for this Ellipse2D.

return
the hashcode for this Ellipse2D.
since
1.6

        long bits = java.lang.Double.doubleToLongBits(getX());
        bits += java.lang.Double.doubleToLongBits(getY()) * 37;
        bits += java.lang.Double.doubleToLongBits(getWidth()) * 43;
        bits += java.lang.Double.doubleToLongBits(getHeight()) * 47;
        return (((int) bits) ^ ((int) (bits >> 32)));
    
public booleanintersects(double x, double y, double w, double h)
{@inheritDoc}

since
1.2

	if (w <= 0.0 || h <= 0.0) {
	    return false;
	}
	// Normalize the rectangular coordinates compared to the ellipse
	// having a center at 0,0 and a radius of 0.5.
	double ellw = getWidth();
	if (ellw <= 0.0) {
	    return false;
	}
	double normx0 = (x - getX()) / ellw - 0.5;
	double normx1 = normx0 + w / ellw;
	double ellh = getHeight();
	if (ellh <= 0.0) {
	    return false;
	}
	double normy0 = (y - getY()) / ellh - 0.5;
	double normy1 = normy0 + h / ellh;
	// find nearest x (left edge, right edge, 0.0)
	// find nearest y (top edge, bottom edge, 0.0)
	// if nearest x,y is inside circle of radius 0.5, then intersects
	double nearx, neary;
	if (normx0 > 0.0) {
	    // center to left of X extents
	    nearx = normx0;
	} else if (normx1 < 0.0) {
	    // center to right of X extents
	    nearx = normx1;
	} else {
	    nearx = 0.0;
	}
	if (normy0 > 0.0) {
	    // center above Y extents
	    neary = normy0;
	} else if (normy1 < 0.0) {
	    // center below Y extents
	    neary = normy1;
	} else {
	    neary = 0.0;
	}
	return (nearx * nearx + neary * neary) < 0.25;