skunkworks/com/danitheskunk/skunkworks/Vec2f.java

61 lines
1.2 KiB
Java
Raw Normal View History

2022-09-14 05:44:38 +02:00
package com.danitheskunk.skunkworks;
public final class Vec2f {
2022-10-11 04:15:14 +02:00
public final static Vec2f ZERO = new Vec2f(0, 0);
2022-09-18 19:11:23 +02:00
private final double x, y;
2022-09-14 05:44:38 +02:00
//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);
}
2022-11-22 23:10:56 +01:00
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()
);
2022-09-14 05:44:38 +02:00
}
public static Vec2f mul(Vec2f a, double b) {
return new Vec2f(a.x * b, a.y * b);
}
2022-11-23 09:03:20 +01:00
public static Vec2f mul(Vec2f a, Vec2f b) {
return new Vec2f(a.x * b.x, a.y * b.y);
}
2022-11-22 23:10:56 +01:00
public static Vec2f sub(Vec2f a, Vec2f b) {
return new Vec2f(a.x - b.x, a.y - b.y);
2022-09-14 05:44:38 +02:00
}
2022-10-11 03:52:59 +02:00
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)
);
}
2022-10-11 03:52:59 +02:00
//getters and setters
public double getX() {
return x;
}
public double getY() {
return y;
}
public Vec2i toVec2i() {
return new Vec2i((int) x, (int) y);
}
2022-09-14 05:44:38 +02:00
}