Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(JOML): migrate Direction #4363

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 23 additions & 23 deletions engine/src/main/java/org/terasology/math/Direction.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
/*
* Copyright 2013 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.math;

import com.google.common.collect.Maps;
import org.joml.Math;
import org.joml.Vector3fc;
import org.joml.Vector3ic;
import org.terasology.math.geom.Vector3f;
Expand Down Expand Up @@ -65,20 +52,31 @@ public enum Direction {
}

public static Direction inDirection(int x, int y, int z) {
if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) {
if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) {
if (Math.abs(x) > Math.abs(y)) {
if (Math.abs(x) > Math.abs(z)) {
return (x > 0) ? LEFT : RIGHT;
}
} else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) {
} else if (Math.abs(y) > Math.abs(z)) {
return (y > 0) ? UP : DOWN;
}
return (z > 0) ? FORWARD : BACKWARD;
}

/**
* @param dir
* @return
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #inDirection(Vector3fc)}.
*/
@Deprecated
public static Direction inDirection(Vector3f dir) {
return inDirection(dir.x, dir.y, dir.z);
}

public static Direction inDirection(Vector3fc dir) {
return inDirection(dir.x(), dir.y(), dir.z());
}

public Side toSide() {
return CONVERSION_MAP.get(this);
}
Expand All @@ -92,11 +90,11 @@ public Side toSide() {
* @return Side enum with the appropriate direction
*/
public static Direction inDirection(float x, float y, float z) {
if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) {
if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) {
if (Math.abs(x) > Math.abs(y)) {
if (Math.abs(x) > Math.abs(z)) {
return (x > 0) ? LEFT : RIGHT;
}
} else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) {
} else if (Math.abs(y) > Math.abs(z)) {
return (y > 0) ? UP : DOWN;
}
return (z > 0) ? FORWARD : BACKWARD;
Expand All @@ -110,7 +108,7 @@ public static Direction inDirection(float x, float y, float z) {
* @return Side enum with the appropriate direction
*/
public static Direction inHorizontalDirection(float x, float z) {
if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) {
if (Math.abs(x) > Math.abs(z)) {
return (x > 0) ? LEFT : RIGHT;
}
return (z > 0) ? FORWARD : BACKWARD;
Expand Down Expand Up @@ -141,6 +139,7 @@ public Vector3fc asVector3f() {
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #asVector3i()}.
*/
@Deprecated
public Vector3i getVector3i() {
return new Vector3i(vector3iDir);
}
Expand All @@ -150,6 +149,7 @@ public Vector3i getVector3i() {
* @deprecated This is scheduled for removal in an upcoming version method will be replaced with JOML implementation
* {@link #asVector3f()}
*/
@Deprecated
public Vector3f getVector3f() {
return new Vector3f(vector3fDir);
}
Expand Down