[wpimath] Add scalar multiply and divide operators to all geometry classes (#4438)

Closes #4435.
This commit is contained in:
Tyler Veness
2022-09-28 21:34:29 -07:00
committed by GitHub
parent 3937ff8221
commit 38bb23eb18
16 changed files with 180 additions and 4 deletions

View File

@@ -115,6 +115,26 @@ public class Pose2d implements Interpolatable<Pose2d> {
return m_rotation;
}
/**
* Multiplies the current pose by a scalar.
*
* @param scalar The scalar.
* @return The new scaled Pose2d.
*/
public Pose2d times(double scalar) {
return new Pose2d(m_translation.times(scalar), m_rotation.times(scalar));
}
/**
* Divides the current pose by a scalar.
*
* @param scalar The scalar.
* @return The new scaled Pose2d.
*/
public Pose2d div(double scalar) {
return times(1.0 / scalar);
}
/**
* Transforms the pose by the given transformation and returns the new pose. See + operator for
* the matrix multiplication performed.

View File

@@ -114,6 +114,26 @@ public class Pose3d implements Interpolatable<Pose3d> {
return m_rotation;
}
/**
* Multiplies the current pose by a scalar.
*
* @param scalar The scalar.
* @return The new scaled Pose3d.
*/
public Pose3d times(double scalar) {
return new Pose3d(m_translation.times(scalar), m_rotation.times(scalar));
}
/**
* Divides the current pose by a scalar.
*
* @param scalar The scalar.
* @return The new scaled Pose3d.
*/
public Pose3d div(double scalar) {
return times(1.0 / scalar);
}
/**
* Transforms the pose by the given transformation and returns the new pose. See + operator for
* the matrix multiplication performed.

View File

@@ -136,6 +136,16 @@ public class Rotation2d implements Interpolatable<Rotation2d> {
return new Rotation2d(m_value * scalar);
}
/**
* Divides the current rotation by a scalar.
*
* @param scalar The scalar.
* @return The new scaled Rotation2d.
*/
public Rotation2d div(double scalar) {
return times(1.0 / scalar);
}
/**
* Adds the new rotation to the current rotation using a rotation matrix.
*

View File

@@ -245,6 +245,16 @@ public class Rotation3d implements Interpolatable<Rotation3d> {
}
}
/**
* Divides the current rotation by a scalar.
*
* @param scalar The scalar.
* @return The new scaled Rotation3d.
*/
public Rotation3d div(double scalar) {
return times(1.0 / scalar);
}
/**
* Adds the new rotation to the current rotation.
*

View File

@@ -47,7 +47,7 @@ public class Transform2d {
}
/**
* Scales the transform by the scalar.
* Multiplies the transform by the scalar.
*
* @param scalar The scalar.
* @return The scaled Transform2d.
@@ -56,6 +56,16 @@ public class Transform2d {
return new Transform2d(m_translation.times(scalar), m_rotation.times(scalar));
}
/**
* Divides the transform by the scalar.
*
* @param scalar The scalar.
* @return The scaled Transform2d.
*/
public Transform2d div(double scalar) {
return times(1.0 / scalar);
}
/**
* Composes two transformations.
*

View File

@@ -47,7 +47,7 @@ public class Transform3d {
}
/**
* Scales the transform by the scalar.
* Multiplies the transform by the scalar.
*
* @param scalar The scalar.
* @return The scaled Transform3d.
@@ -56,6 +56,16 @@ public class Transform3d {
return new Transform3d(m_translation.times(scalar), m_rotation.times(scalar));
}
/**
* Divides the transform by the scalar.
*
* @param scalar The scalar.
* @return The scaled Transform3d.
*/
public Transform3d div(double scalar) {
return times(1.0 / scalar);
}
/**
* Composes two transformations.
*