Skip to content

Commit

Permalink
Reverted back to vecmath 1.3.1 to be compatible with JRE on OSX.
Browse files Browse the repository at this point in the history
  • Loading branch information
immortius committed May 23, 2014
1 parent 68effcc commit 457f0e7
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ dependencies {
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl_util', version: LwjglVersion
compile group: 'io.netty', name: 'netty', version: '3.6.5.Final'
compile group: 'org.reflections', name: 'reflections', version: '0.9.9-RC1'
compile group: 'java3d', name: 'vecmath', version: '1.5.2'
compile group: 'java3d', name: 'vecmath', version: '1.3.1'
//compile group: 'com.github.jponge', name: 'lzma-java', version: '1.2'
compile group: 'net.java.dev.jna', name: 'jna', version: '3.5.2'
compile group: 'net.java.dev.jna', name: 'platform', version: '3.5.2'
Expand Down
183 changes: 176 additions & 7 deletions engine/src/main/java/org/terasology/math/Vector2i.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package org.terasology.math;

import javax.vecmath.Tuple2i;
import com.google.common.base.Preconditions;

import javax.vecmath.Vector2d;
import javax.vecmath.Vector2f;

Expand All @@ -26,9 +27,10 @@
*
* @author Immortius
*/
public class Vector2i extends Tuple2i {
public class Vector2i {

private static final long serialVersionUID = 3862467945178721785L;
public int x;
public int y;

/**
* Constructs and initializes a Vector2i from the specified
Expand All @@ -38,7 +40,8 @@ public class Vector2i extends Tuple2i {
* @param y the y coordinate
*/
public Vector2i(int x, int y) {
super(x, y);
this.x = x;
this.y = y;
}

/**
Expand All @@ -47,7 +50,10 @@ public Vector2i(int x, int y) {
* @param values the array of length 2 containing x and y in order.
*/
public Vector2i(int[] values) {
super(values);
Preconditions.checkNotNull(values);
Preconditions.checkArgument(values.length == 2);
this.x = values[0];
this.y = values[1];
}

/**
Expand All @@ -57,14 +63,14 @@ public Vector2i(int[] values) {
* data.
*/
public Vector2i(Vector2i other) {
super(other);
this.x = other.x;
this.y = other.y;
}

/**
* Constructs and initializes a Vector2i to (0,0).
*/
public Vector2i() {
super();
}

/**
Expand All @@ -91,5 +97,168 @@ public static Vector2i zero() {
public int gridDistance(Vector2i other) {
return Math.abs(other.x - x) + Math.abs(other.y - y);
}

public void absolute() {
x = TeraMath.fastAbs(x);
y = TeraMath.fastAbs(y);
}

public void absolute(Vector2i other) {
this.x = TeraMath.fastAbs(other.x);
this.y = TeraMath.fastAbs(other.y);
}

public void add(Vector2i other) {
this.x += other.x;
this.y += other.y;
}

public void add(Vector2i a, Vector2i b) {
this.x = a.x + b.x;
this.y = a.y + b.y;
}

public void clamp(int min, int max) {
this.x = TeraMath.clamp(this.x, min, max);
this.y = TeraMath.clamp(this.y, min, max);
}

public void clamp(int min, int max, Vector2i other) {
this.x = TeraMath.clamp(other.x, min, max);
this.y = TeraMath.clamp(other.y, min, max);
}

public void clampMax(int max) {
this.x = Math.min(this.x, max);
this.y = Math.min(this.y, max);
}

public void clampMax(int max, Vector2i other) {
this.x = Math.min(other.x, max);
this.y = Math.min(other.y, max);
}

public void clampMin(int min) {
this.x = Math.max(this.x, min);
this.y = Math.max(this.y, min);
}

public void clampMin(int min, Vector2i other) {
this.x = Math.max(other.x, min);
this.y = Math.max(other.y, min);
}

public void get(int[] out) {
Preconditions.checkNotNull(out);
Preconditions.checkArgument(out.length == 2);
out[0] = x;
out[1] = y;
}

public void get(Vector2i other) {
other.x = x;
other.y = y;
}

public int getX() {
return x;
}

public int getY() {
return y;
}

public void negate() {
this.x *= -1;
this.y *= -1;
}

public void negate(Vector2i other) {
this.x = -other.x;
this.y = -other.y;
}

public void scale(int s) {
this.x *= s;
this.y *= s;
}

public void scale(int s, Vector2i other) {
this.x = s * other.x;
this.y = s * other.y;
}

public void scaleAdd(int s, Vector2i add) {
this.x = s * this.x + add.x;
this.y = s * this.y + add.y;
}

public void scaleAdd(int s, Vector2i a, Vector2i b) {
this.x = s * a.x + b.x;
this.y = s * a.y + b.y;
}

public void set(int[] values) {
Preconditions.checkNotNull(values);
Preconditions.checkArgument(values.length == 2);
this.x = values[0];
this.y = values[1];
}

public void set(int newX, int newY) {
this.x = newX;
this.y = newY;
}

public void set(Vector2i other) {
this.x = other.x;
this.y = other.y;
}

public void setX(int x) {
this.x = x;
}

public void setY(int y) {
this.y = y;
}

public void sub(Vector2i other) {
this.x -= other.x;
this.y -= other.y;
}

public void sub(Vector2i a, Vector2i b) {
this.x = a.x - b.x;
this.y = a.y - b.y;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Vector2i) {
Vector2i other = (Vector2i) obj;
return this.x == other.x && this.y == other.y;
}
return false;
}

@Override
public int hashCode() {
int hash = 0;

hash += (x - Integer.MIN_VALUE) & 0xFFFF;
hash <<= 16;
hash += (y - Integer.MIN_VALUE) & 0xFFFF;

return hash;
}

@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
}

0 comments on commit 457f0e7

Please sign in to comment.