Skip to content

Commit

Permalink
refact: improved javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaphoriker committed Oct 1, 2024
1 parent fc69b81 commit 53da8fe
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,38 @@
import com.google.common.eventbus.EventBus;
import lombok.experimental.UtilityClass;

/**
* Utility class for publishing and managing events using the Google Guava EventBus. This class
* provides methods to raise events and register/unregister event listeners.
*/
@UtilityClass
public class EventPublisher {

private static final EventBus eventBus = new EventBus();

/**
* Raises an event by posting it to the EventBus.
*
* @param pathingEvent the event to be raised
*/
public static void raiseEvent(PathingEvent pathingEvent) {
eventBus.post(pathingEvent);
}

/**
* Registers an event listener with the EventBus.
*
* @param listener the listener to be registered
*/
public static void registerListener(Object listener) {
eventBus.register(listener);
}

/**
* Unregisters an event listener from the EventBus.
*
* @param listener the listener to be unregistered
*/
public static void unregisterListener(Object listener) {
eventBus.unregister(listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@

import lombok.experimental.UtilityClass;

/** Utility class for common number operations. */
@UtilityClass
public final class NumberUtils {

/**
* Interpolates between two values based on the given progress.
*
* @param a the start value
* @param b the end value
* @param progress the interpolation progress (0.0 to 1.0)
* @return the interpolated value
*/
public static double interpolate(double a, double b, double progress) {
return a + (b - a) * progress;
}

/**
* Squares the given value.
*
* @param value the value to be squared
* @return the squared value
*/
public static double square(double value) {
return value * value;
}

/**
* Computes the square root of the given value using an approximation method.
*
* @param input the value to compute the square root of
* @return the approximated square root
*/
public static double sqrt(double input) {

double sqrt =
Double.longBitsToDouble((Double.doubleToLongBits(input) - (1L << 52) >> 1) + (1L << 61));
double better = (sqrt + input / sqrt) / 2.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class PathPosition implements Cloneable {
private double y;
private double z;

/**
* Interpolates between two positions based on the given progress.
*
* @param other The other position to interpolate with
* @param progress The interpolation progress (0.0 to 1.0)
* @return The interpolated position
*/
public PathPosition interpolate(PathPosition other, double progress) {
double x = NumberUtils.interpolate(this.x, other.x, progress);
double y = NumberUtils.interpolate(this.y, other.y, progress);
Expand Down

0 comments on commit 53da8fe

Please sign in to comment.