mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-30 02:31:40 +00:00
Use Math.hypot instead of Math.sqrt(a^2 + b^2)
This commit is contained in:
@@ -52,7 +52,7 @@ public class UICameraCalibrationCoefficients extends CameraCalibrationCoefficien
|
||||
.map(
|
||||
it2 ->
|
||||
it2.reprojectionErrors.stream()
|
||||
.mapToDouble(it -> Math.sqrt(it.x * it.x + it.y * it.y))
|
||||
.mapToDouble(it -> Math.hypot(it.x, it.y))
|
||||
.average()
|
||||
.orElse(0))
|
||||
.toList();
|
||||
|
||||
@@ -85,9 +85,7 @@ public class CornerDetectionPipe
|
||||
* @return The straight line distance between them.
|
||||
*/
|
||||
private static double distanceBetween(Point a, Point b) {
|
||||
double xDelta = a.x - b.x;
|
||||
double yDelta = a.y - b.y;
|
||||
return Math.sqrt(xDelta * xDelta + yDelta * yDelta);
|
||||
return Math.hypot(a.x - b.x, a.y - b.y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -170,9 +170,7 @@ public class FindBoardCornersPipe
|
||||
// +1 idx Neighbor distance
|
||||
double[] startPoint = inPoints.get(pointIdx, 0);
|
||||
double[] endPoint = inPoints.get(pointIdx + 1, 0);
|
||||
double deltaX = startPoint[0] - endPoint[0];
|
||||
double deltaY = startPoint[1] - endPoint[1];
|
||||
double distToNext = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
double distToNext = Math.hypot(startPoint[0] - endPoint[0], startPoint[1] - endPoint[1]);
|
||||
|
||||
minSpacing = Math.min(distToNext, minSpacing);
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ public class SortContoursPipe
|
||||
}
|
||||
|
||||
private double calcSquareCenterDistance(PotentialTarget tgt) {
|
||||
return Math.sqrt(
|
||||
Math.pow(params.frameStaticProperties().centerX - tgt.getMinAreaRect().center.x, 2)
|
||||
+ Math.pow(params.frameStaticProperties().centerY - tgt.getMinAreaRect().center.y, 2));
|
||||
return Math.hypot(
|
||||
params.frameStaticProperties().centerX - tgt.getMinAreaRect().center.x,
|
||||
params.frameStaticProperties().centerY - tgt.getMinAreaRect().center.y);
|
||||
}
|
||||
|
||||
public static record SortContoursParams(
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SimCameraProperties {
|
||||
DriverStation.reportError(
|
||||
"Requested invalid FOV! Clamping between (1, 179) degrees...", false);
|
||||
}
|
||||
double resDiag = Math.sqrt(resWidth * resWidth + resHeight * resHeight);
|
||||
double resDiag = Math.hypot(resWidth, resHeight);
|
||||
double diagRatio = Math.tan(fovDiag.getRadians() / 2);
|
||||
var fovWidth = new Rotation2d(Math.atan(diagRatio * (resWidth / resDiag)) * 2);
|
||||
var fovHeight = new Rotation2d(Math.atan(diagRatio * (resHeight / resDiag)) * 2);
|
||||
|
||||
Reference in New Issue
Block a user