From e9e111f1c4e303e43c311ee3a44b43e91490fba5 Mon Sep 17 00:00:00 2001 From: Ray Healy Date: Sat, 7 Feb 2026 15:44:50 -0500 Subject: [PATCH] src/robolib/trajectory/Velocity3d.java: hashCode(), toString(), and equals() --- .../frc/robolib/trajectory/Velocity3d.java | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/Velocity3d.java b/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/Velocity3d.java index a6edc71..32b0b60 100644 --- a/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/Velocity3d.java +++ b/lib/src/main/java/org/fairportrobotics/frc/robolib/trajectory/Velocity3d.java @@ -59,9 +59,9 @@ public class Velocity3d { } - /* - * Cartesian Coordinate Getters - */ + // + // Cartesian Coordinate Getters + // /** * @return The x-axis component of the velocity @@ -104,9 +104,9 @@ public class Velocity3d { } - /* - * Cylindrical Coordinate getters - */ + // + // Cylindrical Coordinate getters + // /** @@ -144,9 +144,9 @@ public class Velocity3d { } - /* - * Spherical Coordinate getters - */ + // + // Spherical Coordinate getters + // /** @@ -176,10 +176,15 @@ public class Velocity3d { } - /* - * Mathematical operations - */ + // + // Mathematical operations + // + /** + * Subtract other from this vector and return the resulting vector + * @param other The vector to subtract from this one + * @return The difference of this vector from other + */ public Velocity3d minus(Velocity3d other) { return new Velocity3d( this.vX.minus(other.vX), @@ -189,6 +194,11 @@ public class Velocity3d { } + /** + * Multiply the velocity by time in order to get a displacement + * @param time The time to compute over + * @return The resulting displacement + */ public Translation3d times(Time time) { return new Translation3d( this.vX.times(time), @@ -198,4 +208,31 @@ public class Velocity3d { } + // + // Overrides + // + + @Override + public int hashCode() { + return this.vX.hashCode() ^ this.vY.hashCode() ^ this.vZ.hashCode(); + } + + + @Override + public String toString() { + return String.format("Velocity3d(X: %s, Y: %s, Z: %s)", vX, vY, vZ); + } + + + @Override + public boolean equals(Object obj) { + if(Velocity3d.class.isInstance(obj)) { + Velocity3d otherVelocity = (Velocity3d) obj; + return + this.vX == otherVelocity.getVX() && + this.vY == otherVelocity.getVY() && + this.vZ == otherVelocity.getVZ(); + } + return false; + } }