mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Add scalar multiply and divide operators to all geometry classes (#4438)
Closes #4435.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user