From 119ec86f04ea46346d290f2ddaeed0bbc4da26b5 Mon Sep 17 00:00:00 2001 From: iTitus Date: Mon, 24 May 2021 22:54:55 +0200 Subject: [PATCH] add vec4f and quatf --- .../github/ititus/math/quaternion/QuatF.java | 61 +++++++++++++++++ .../io/github/ititus/math/vector/Vec4f.java | 65 +++++++++++++++++++ src/main/java/module-info.java | 1 + 3 files changed, 127 insertions(+) create mode 100644 src/main/java/io/github/ititus/math/quaternion/QuatF.java create mode 100644 src/main/java/io/github/ititus/math/vector/Vec4f.java diff --git a/src/main/java/io/github/ititus/math/quaternion/QuatF.java b/src/main/java/io/github/ititus/math/quaternion/QuatF.java new file mode 100644 index 0000000..80861b4 --- /dev/null +++ b/src/main/java/io/github/ititus/math/quaternion/QuatF.java @@ -0,0 +1,61 @@ +package io.github.ititus.math.quaternion; + +import io.github.ititus.data.ArrayUtil; +import io.github.ititus.math.vector.Vec4f; + +public final class QuatF { + + private final float x; + private final float y; + private final float z; + private final float w; + + public QuatF(Vec4f vec4f) { + this(vec4f.x(), vec4f.y(), vec4f.z(), vec4f.w()); + } + + public QuatF(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + public float x() { + return x; + } + + public float y() { + return y; + } + + public float z() { + return z; + } + + public float w() { + return w; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof QuatF)) { + return false; + } + + QuatF quatF = (QuatF) o; + return Float.compare(quatF.x, x) == 0 && Float.compare(quatF.y, y) == 0 && Float.compare(quatF.z, z) == 0 && Float.compare(quatF.w, w) == 0; + } + + @Override + public int hashCode() { + return ArrayUtil.hash(x, y, z, w); + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ", " + w + ')'; + } +} diff --git a/src/main/java/io/github/ititus/math/vector/Vec4f.java b/src/main/java/io/github/ititus/math/vector/Vec4f.java new file mode 100644 index 0000000..3f25668 --- /dev/null +++ b/src/main/java/io/github/ititus/math/vector/Vec4f.java @@ -0,0 +1,65 @@ +package io.github.ititus.math.vector; + +import io.github.ititus.data.ArrayUtil; +import io.github.ititus.math.quaternion.QuatF; + +public final class Vec4f { + + private final float x; + private final float y; + private final float z; + private final float w; + + public Vec4f() { + this(0, 0, 0, 0); + } + + public Vec4f(QuatF quatF) { + this(quatF.x(), quatF.y(), quatF.z(), quatF.w()); + } + + public Vec4f(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + public float x() { + return x; + } + + public float y() { + return y; + } + + public float z() { + return z; + } + + public float w() { + return w; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof Vec4f)) { + return false; + } + + Vec4f vec4f = (Vec4f) o; + return Float.compare(vec4f.x, x) == 0 && Float.compare(vec4f.y, y) == 0 && Float.compare(vec4f.z, z) == 0 && Float.compare(vec4f.w, w) == 0; + } + + @Override + public int hashCode() { + return ArrayUtil.hash(x, y, z, w); + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ", " + w + ')'; + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index cc969bf..a5ba23b 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -21,6 +21,7 @@ exports io.github.ititus.math.modulus; exports io.github.ititus.math.number; exports io.github.ititus.math.permutation; + exports io.github.ititus.math.quaternion; exports io.github.ititus.math.random; exports io.github.ititus.math.statistics; exports io.github.ititus.math.time;