From e81af5e193a6032aa235490f75add85672bf9a34 Mon Sep 17 00:00:00 2001 From: DaniTheSkunk Date: Tue, 11 Oct 2022 01:52:59 +0000 Subject: [PATCH] vec2f and vec2i conversion functions --- com/danitheskunk/skunkworks/Vec2f.java | 22 ++++++++------- com/danitheskunk/skunkworks/Vec2i.java | 37 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/com/danitheskunk/skunkworks/Vec2f.java b/com/danitheskunk/skunkworks/Vec2f.java index 293f979..8a4e7c1 100644 --- a/com/danitheskunk/skunkworks/Vec2f.java +++ b/com/danitheskunk/skunkworks/Vec2f.java @@ -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); + } } diff --git a/com/danitheskunk/skunkworks/Vec2i.java b/com/danitheskunk/skunkworks/Vec2i.java index caba1b7..f9dbd13 100644 --- a/com/danitheskunk/skunkworks/Vec2i.java +++ b/com/danitheskunk/skunkworks/Vec2i.java @@ -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); + 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); + 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); } }