[wpimath] Rename FindNearestPoint() to Nearest() (#7513)

This is easier to type and follows the naming of Pose2d::Nearest().

Since Ellipse2d and Rectangle2d were added for the 2025 season, we don't
need to add deprecation notices.
This commit is contained in:
Tyler Veness
2024-12-07 23:01:18 -08:00
committed by GitHub
parent 544553a58f
commit e08fdeba21
11 changed files with 43 additions and 43 deletions

View File

@@ -199,7 +199,7 @@ public class Ellipse2d implements ProtobufSerializable, StructSerializable {
* @return The distance (0, if the point is contained by the ellipse)
*/
public double getDistance(Translation2d point) {
return findNearestPoint(point).getDistance(point);
return nearest(point).getDistance(point);
}
/**
@@ -218,7 +218,7 @@ public class Ellipse2d implements ProtobufSerializable, StructSerializable {
* @param point The point that this will find the nearest point to.
* @return A new point that is nearest to {@code point} and contained in the ellipse.
*/
public Translation2d findNearestPoint(Translation2d point) {
public Translation2d nearest(Translation2d point) {
// Check if already in ellipse
if (contains(point)) {
return point;
@@ -226,7 +226,7 @@ public class Ellipse2d implements ProtobufSerializable, StructSerializable {
// Find nearest point
var nearestPoint = new double[2];
Ellipse2dJNI.findNearestPoint(
Ellipse2dJNI.nearest(
m_center.getX(),
m_center.getY(),
m_center.getRotation().getRadians(),

View File

@@ -186,7 +186,7 @@ public class Rectangle2d implements ProtobufSerializable, StructSerializable {
* @return The distance (0, if the point is contained by the rectangle)
*/
public double getDistance(Translation2d point) {
return findNearestPoint(point).getDistance(point);
return nearest(point).getDistance(point);
}
/**
@@ -205,7 +205,7 @@ public class Rectangle2d implements ProtobufSerializable, StructSerializable {
* @param point The point that this will find the nearest point to.
* @return A new point that is nearest to {@code point} and contained in the rectangle.
*/
public Translation2d findNearestPoint(Translation2d point) {
public Translation2d nearest(Translation2d point) {
// Check if already in rectangle
if (contains(point)) {
return point;

View File

@@ -9,7 +9,7 @@ public final class Ellipse2dJNI extends WPIMathJNI {
/**
* Returns the nearest point that is contained within the ellipse.
*
* <p>Constructs an Ellipse2d object and runs its FindNearestPoint() method.
* <p>Constructs an Ellipse2d object and runs its nearest() method.
*
* @param centerX The x coordinate of the center of the ellipse in meters.
* @param centerY The y coordinate of the center of the ellipse in meters.
@@ -20,7 +20,7 @@ public final class Ellipse2dJNI extends WPIMathJNI {
* @param pointY The y coordinate of the point that this will find the nearest point to.
* @param nearestPoint Array to store nearest point into.
*/
public static native void findNearestPoint(
public static native void nearest(
double centerX,
double centerY,
double centerHeading,

View File

@@ -8,7 +8,7 @@
using namespace frc;
Translation2d Ellipse2d::FindNearestPoint(const Translation2d& point) const {
Translation2d Ellipse2d::Nearest(const Translation2d& point) const {
// Check if already in ellipse
if (Contains(point)) {
return point;

View File

@@ -16,11 +16,11 @@ extern "C" {
/*
* Class: edu_wpi_first_math_jni_Ellipse2dJNI
* Method: findNearestPoint
* Method: nearest
* Signature: (DDDDDDD[D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_math_jni_Ellipse2dJNI_findNearestPoint
Java_edu_wpi_first_math_jni_Ellipse2dJNI_nearest
(JNIEnv* env, jclass, jdouble centerX, jdouble centerY, jdouble centerHeading,
jdouble xSemiAxis, jdouble ySemiAxis, jdouble pointX, jdouble pointY,
jdoubleArray nearestPoint)
@@ -30,7 +30,7 @@ Java_edu_wpi_first_math_jni_Ellipse2dJNI_findNearestPoint
frc::Pose2d{units::meter_t{centerX}, units::meter_t{centerY},
units::radian_t{centerHeading}},
units::meter_t{xSemiAxis}, units::meter_t{ySemiAxis}}
.FindNearestPoint({units::meter_t{pointX}, units::meter_t{pointY}});
.Nearest({units::meter_t{pointX}, units::meter_t{pointY}});
wpi::array buf{point.X().value(), point.Y().value()};
env->SetDoubleArrayRegion(nearestPoint, 0, 2, buf.data());

View File

@@ -154,7 +154,7 @@ class WPILIB_DLLEXPORT Ellipse2d {
* @return The distance (0, if the point is contained by the ellipse)
*/
units::meter_t Distance(const Translation2d& point) const {
return FindNearestPoint(point).Distance(point);
return Nearest(point).Distance(point);
}
/**
@@ -164,7 +164,7 @@ class WPILIB_DLLEXPORT Ellipse2d {
* @return A new point that is nearest to {@code point} and contained in the
* ellipse.
*/
Translation2d FindNearestPoint(const Translation2d& point) const;
Translation2d Nearest(const Translation2d& point) const;
/**
* Checks equality between this Ellipse2d and another object.

View File

@@ -155,7 +155,7 @@ class WPILIB_DLLEXPORT Rectangle2d {
* @return The distance (0, if the point is contained by the rectangle)
*/
constexpr units::meter_t Distance(const Translation2d& point) const {
return FindNearestPoint(point).Distance(point);
return Nearest(point).Distance(point);
}
/**
@@ -165,7 +165,7 @@ class WPILIB_DLLEXPORT Rectangle2d {
* @return A new point that is nearest to {@code point} and contained in the
* rectangle.
*/
constexpr Translation2d FindNearestPoint(const Translation2d& point) const {
constexpr Translation2d Nearest(const Translation2d& point) const {
// Check if already in rectangle
if (Contains(point)) {
return point;