vec2f and vec2i conversion functions

This commit is contained in:
DaniTheSkunk 2022-10-11 01:52:59 +00:00
parent 2809079025
commit e81af5e193
2 changed files with 36 additions and 23 deletions

View File

@ -9,15 +9,6 @@ public final class Vec2f {
this.y = y;
}
//getters and setters
public double getX() {
return x;
}
public double getY() {
return y;
}
//static functions
public static Vec2f add(Vec2f a, Vec2f b) {
return new Vec2f(a.x + b.x, a.y + b.y);
@ -34,4 +25,17 @@ public final class Vec2f {
public static Vec2f div(Vec2f a, double b) {
return new Vec2f(a.x / b, a.y / b);
}
//getters and setters
public double getX() {
return x;
}
public double getY() {
return y;
}
public Vec2i toVec2i() {
return new Vec2i((int) x, (int) y);
}
}

View File

@ -2,9 +2,8 @@ package com.danitheskunk.skunkworks;
@SuppressWarnings("SpellCheckingInspection")
public final class Vec2i {
private final int x, y;
public final static Vec2i ZERO = new Vec2i(0, 0);
private final int x, y;
//constructors
@ -15,16 +14,6 @@ public final class Vec2i {
//getters and setters
public int getX() {
return x;
}
public int getY() {
return y;
}
//static functions
public static Vec2i add(Vec2i a, Vec2i b) {
return new Vec2i(a.x + b.x, a.y + b.y);
}
@ -33,6 +22,8 @@ public final class Vec2i {
return new Vec2i(a.x + b.x + c.x, a.y + b.y + c.y);
}
//static functions
public static Vec2i add(Vec2i a, Vec2i b, Vec2i c, Vec2i d) {
return new Vec2i(a.x + b.x + c.x + d.x, a.y + b.y + c.y + d.y);
}
@ -44,6 +35,7 @@ public final class Vec2i {
public static Vec2i mul(Vec2i a, int b) {
return new Vec2i(a.x * b, a.y * b);
}
public static Vec2i mul(Vec2i a, Vec2i b) {
return new Vec2i(a.x * b.x, a.y * b.y);
}
@ -51,19 +43,36 @@ public final class Vec2i {
public static Vec2i div(Vec2i a, int b) {
return new Vec2i(a.x / b, a.y / b);
}
public static Vec2i div(Vec2i a, Vec2i b) {
return new Vec2i(a.x / b.x, a.y / b.y);
}
public static Vec2f divf(Vec2i a, double b) {
return new Vec2f(a.x / b, a.y / b);
}
public static Vec2f divf(Vec2i a, Vec2f b) {
return new Vec2f(a.x / b.getX(), a.y / b.getY());
}
public static Vec2f divf(Vec2i a, int b) {
return new Vec2f(a.x / (double) b, a.y / (double) b);
}
public static Vec2f divf(Vec2i a, Vec2i b) {
return new Vec2f(a.x / (double) b.x, a.y / (double) b.y);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public Vec2f toVec2f() {
return new Vec2f((double) x, (double) y);
}
}