-
Enhancement
-
Resolution: Won't Fix
-
P4
-
8, 11, 17, 21, 25, 26
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
java.awt.geom.Point2D has several overloads of methods to compute the distance between points. Currently, these methods use Math.sqrt:
public double distance(Point2D pt) {
double px = pt.getX() - this.getX();
double py = pt.getY() - this.getY();
return Math.sqrt(px * px + py * py);
}
But there is an opportunity to use Math.hypot:
public double distance(Point2D pt) {
double px = pt.getX() - this.getX();
double py = pt.getY() - this.getY();
return Math.hypot(px, py);
}
This is a minor improvement to accuracy, by avoiding overflow or underflow in computing the intermediate squared value.
java.awt.geom.Point2D has several overloads of methods to compute the distance between points. Currently, these methods use Math.sqrt:
public double distance(Point2D pt) {
double px = pt.getX() - this.getX();
double py = pt.getY() - this.getY();
return Math.sqrt(px * px + py * py);
}
But there is an opportunity to use Math.hypot:
public double distance(Point2D pt) {
double px = pt.getX() - this.getX();
double py = pt.getY() - this.getY();
return Math.hypot(px, py);
}
This is a minor improvement to accuracy, by avoiding overflow or underflow in computing the intermediate squared value.