From the java sources:
Point2D:
public static double distance(double x1, double y1,
double x2, double y2)
{
x1 -= x2;
y1 -= y2;
return Math.sqrt(x1 * x1 + y1 * y1);
}
Ellipse2D:
public boolean contains(double x, double y) {
// 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;
}
So the ellipse has little more to do but no sqrt().
But why don't you put a loop around it and let us know? ;)
EDIT:
So let me do this complex stuff of informational technology for you: (I'm young and need the Points)
Point2D A = new Point2D.Double( 1.0, 2.0 );
Point2D B = new Point2D.Double( 2.0, 1.0 );
Ellipse2D E = new Ellipse2D.Double( 1.0, 2.0, 2.0, 1.0 );
double x = 1.0;
double c=0; // Keep compiler from optimizing
boolean y = false;
long start = System.currentTimeMillis();
for( long i=0; i<1000000000L; i++ ){
y |= E.contains( B );
}
long durA = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
for( long i=0; i<1000000000L; i++ ){
c += A.distance( B ) - x/2.0;
}
long durB = System.currentTimeMillis() - start;
System.out.println( y ); // Keep compiler from optimizing
System.out.println( c );
System.out.printf( "%d / %d", durA, durB );
Will result on my system in:
324 / 946
As others have pointed out: The main difference in speed would be because of the usage of sqrt() which is needed to return the distance. The comparison in Ellipse2D don't need to return the distance and can use a faster method.
So the second method is faster. Note that this are 1,000,000,000 runs. So in reality this difference would hardly be noticeable. And of cause this is way no "real" benchmark. There are many effects which can lead to noticeable different results.