61 lines
1.2 KiB
Java
61 lines
1.2 KiB
Java
package com.danitheskunk.skunkworks;
|
|
|
|
public final class Vec2f {
|
|
public final static Vec2f ZERO = new Vec2f(0, 0);
|
|
private final double x, y;
|
|
|
|
//constructors
|
|
public Vec2f(double x, double y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
//static functions
|
|
public static Vec2f add(Vec2f a, Vec2f b) {
|
|
return new Vec2f(a.x + b.x, a.y + b.y);
|
|
}
|
|
|
|
public static Vec2f div(Vec2f a, double b) {
|
|
return new Vec2f(a.x / b, a.y / b);
|
|
}
|
|
|
|
public static Vec2f div(Vec2i a, Vec2i b) {
|
|
return new Vec2f(
|
|
(double) a.getX() / (double) b.getX(),
|
|
(double) a.getY() / (double) b.getY()
|
|
);
|
|
}
|
|
|
|
public static Vec2f mul(Vec2f a, double b) {
|
|
return new Vec2f(a.x * b, a.y * b);
|
|
}
|
|
|
|
public static Vec2f mul(Vec2f a, Vec2f b) {
|
|
return new Vec2f(a.x * b.x, a.y * b.y);
|
|
}
|
|
|
|
public static Vec2f sub(Vec2f a, Vec2f b) {
|
|
return new Vec2f(a.x - b.x, a.y - b.y);
|
|
}
|
|
|
|
public static Vec2f tween(Vec2f a, Vec2f b, double amount) {
|
|
return new Vec2f(
|
|
Util.tweenDouble(a.x, b.x, amount),
|
|
Util.tweenDouble(a.y, b.y, amount)
|
|
);
|
|
}
|
|
|
|
//getters and setters
|
|
public double getX() {
|
|
return x;
|
|
}
|
|
|
|
public double getY() {
|
|
return y;
|
|
}
|
|
|
|
public Vec2i toVec2i() {
|
|
return new Vec2i((int) x, (int) y);
|
|
}
|
|
}
|