cleanup: Math.hypot()

This commit is contained in:
Alexey Kudravtsev
2016-12-08 15:07:54 +03:00
parent 10dd5478f6
commit d06c4c6328
3 changed files with 4 additions and 4 deletions
@@ -270,7 +270,7 @@ public class GeometryUtil implements SwingConstants {
double deltaX = aX2 - aX1;
double deltaY = aY2 - aY1;
return Math.sqrt(deltaX * deltaX + deltaY * deltaY);
return Math.hypot(deltaX, deltaY);
}
public static double cos(Line2D aLine) {
@@ -21,7 +21,7 @@ import java.awt.*;
public class PositionUtil {
private static float distance(int x1, int y1, int x2, int y2) {
return (float)Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
return (float)Math.hypot(x1 - x2, y1 - y2);
}
public static boolean overUpEdge(int upPosition, int downPosition, int x, int y, int rowHeight, int nodeWidth, float lineThickness) {
@@ -146,7 +146,7 @@ public class SimpleGraphCellPainter implements GraphCellPainter {
boolean isSelected) {
g2.setColor(color);
int length = (x1 == x2) ? getRowHeight() : (int)Math.ceil(Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
int length = (x1 == x2) ? getRowHeight() : (int)Math.ceil(Math.hypot(x1 - x2, y1 - y2));
setStroke(g2, isUsual || hasArrow, isSelected, length);
g2.drawLine(x1, y1, x2, y2);
@@ -173,7 +173,7 @@ public class SimpleGraphCellPainter implements GraphCellPainter {
double translateX = (x - centerX);
double translateY = (y - centerY);
double d = Math.sqrt(translateX * translateX + translateY * translateY);
double d = Math.hypot(translateX, translateY);
double scaleX = arrowLength * translateX / d;
double scaleY = arrowLength * translateY / d;