Skip to content

Commit

Permalink
add vec4f and quatf
Browse files Browse the repository at this point in the history
  • Loading branch information
iTitus committed May 24, 2021
1 parent b4afd7e commit 119ec86
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/main/java/io/github/ititus/math/quaternion/QuatF.java
Original file line number Diff line number Diff line change
@@ -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 + ')';
}
}
65 changes: 65 additions & 0 deletions src/main/java/io/github/ititus/math/vector/Vec4f.java
Original file line number Diff line number Diff line change
@@ -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 + ')';
}
}
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 119ec86

Please sign in to comment.