package coffee.liz.ecs.math; import java.util.function.Function; /** * Cartesian vectors. * * @param * the numeric type of vector components */ public interface Vec2 { /** * @return the x coordinate */ T getX(); /** * @return the y coordinate */ T getY(); /** * Adds another vector to this vector. * * @param other * the vector to add * @return a new vector with the result */ Vec2 plus(final Vec2 other); /** * Subtracts another vector from this vector. * * @param other * the vector to subtract * @return a new vector with the result */ Vec2 minus(final Vec2 other); /** * Scales this vector by the given factors. * * @param scaleX * the x scale factor * @param scaleY * the y scale factor * @return a new scaled vector */ Vec2 scale(final T scaleX, final T scaleY); /** * Scales this vector by the given vector. * * @param scale * scale vec. * @return a new scaled vector */ default Vec2 scale(final Vec2 scale) { return scale(scale.getX(), scale.getY()); } /** * Length of the vector. * * @return length. */ float length(); /** * @return Vec2 components of {@link Vec2} */ Vec2 intValue(); /** * @return Vec2 components of {@link Vec2} */ Vec2 floatValue(); /** * @param xTransform * transform of x component. * @param yTransform * transform of y component. * @return transformed vec applying {@param xTransform} to x component, * {@param yTransform} to y component. */ Vec2 transform(final Function xTransform, final Function yTransform); }