Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:tzaeschke/ode4j.git
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke committed Mar 8, 2014
2 parents b93917d + bac36ee commit 7484318
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 43 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

0.2.9
=====
- Fixed possible infinite loop when calling dxQuickStepParameters.clone()
- fixed problem in low level check in Cstdio.fprintf()
- Deprecated equals() methods for DVector3, DVector6 and DQuaternion
- fixed NaN Check in Common.java
- Migration to Java 7!!!!
- Set version to 0.2.9
- Cleaned up javadoc (@remarks/note/warning to <p>REMARKS:/...) and removed @brief/@ingroup/@defgroup
Expand All @@ -16,4 +20,4 @@
0.2.7
=====
- Merged 'cpp' package into 'core' package
- Issue #3: porting typo in space collider
- Issue #3: porting typo in space collider
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Copyright of GIMPACT (c) 2006 Francisco Leon. C.C. 80087371.
email: projectileman(AT)yahoo.com

LIBCCD:
Copyright (c)2010 Daniel Fiser <danfis(AT)danfis.cz>
Copyright (c) 2010 Daniel Fiser <danfis(AT)danfis.cz>


Contact
Expand Down
34 changes: 26 additions & 8 deletions core/src/main/java/org/ode4j/math/DMatrix3.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ public final int dimJ() {
* Compares two matrices for equality.
* This is marginally faster than <tt>equals(Object o)</tt>.
*/
public final boolean isEqual(DMatrix3C m) {
@Override
public final boolean isEq(DMatrix3C m) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (get(i, j) != m.get(i, j)) return false;
Expand All @@ -599,23 +600,39 @@ public final boolean isEqual(DMatrix3C m) {
}

/**
* Please use isEq() instead.
*/
@Deprecated
public final boolean isEqual(DMatrix3C m) {
return isEq(m);
}

/**
* Do not use. This can be slow, use isEquals() instead.
* Compares two objects for equality.
* This is marginally slower than <tt>isEquals(DMatrix3C m)</tt>.
*/
@Override
@Deprecated
public final boolean equals(Object o) {
if (! (o instanceof DMatrix3C)) {
if (o == null) {
return false;
}
DMatrix3C m = (DMatrix3C) o;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (get(i, j) != m.get(i, j)) return false;
}
if (! (o instanceof DMatrix3C)) {
return false;
}
return true;
return isEq((DMatrix3C) o);
}

@Override
public int hashCode() {
int h = 0;
for (double d: v) {
h |= Double.doubleToRawLongBits(d);
h <<= 2;
}
return h;
}

public final void eqIdentity() {
eqZero();
Expand Down Expand Up @@ -678,6 +695,7 @@ public final DMatrix3 eqTranspose() {
* Create a new transposed version of this matrix.
* @return The transposed copy of this matrix.
*/
@Override
public final DMatrix3 reTranspose() {
return new DMatrix3(
get00(), get10(), get20(),
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/ode4j/math/DMatrix3C.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ public interface DMatrix3C {
public double dotRowCol(int row, DMatrix3C m2, int col2);
public double dotRowRow(int row, DMatrix3C m2, int row2);
public DVector3 columnAsNewVector(int column);
public boolean isEq(DMatrix3C m);
public DMatrix3 reTranspose();
}
23 changes: 20 additions & 3 deletions core/src/main/java/org/ode4j/math/DQuaternion.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,30 @@ public void set3(double d) {
v[3] = d;
}

public boolean equals(DQuaternion q) {
public boolean isEq(DQuaternion q) {
return get0()==q.get0() && get1()==q.get1() && get2()==q.get2() && get3()==q.get3();
}

/**
* Do not use. This can be slow, use isEq() instead.
*/
@Override
@Deprecated
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof DQuaternion)) return false;
return isEq((DQuaternion)obj);
}

@Override
public boolean equals(Object q) {
return false;
public int hashCode() {
int h = 0;
for (double d: v) {
h |= Double.doubleToRawLongBits(d);
h <<= 6;
}
return h;
}

public void add(double d0, double d1, double d2, double d3) {
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/org/ode4j/math/DVector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ public final double distance(DVector3C a) {
* @param a
* @return quality
*/
public final boolean isEq(DVector3 a) {
@Override
public final boolean isEq(DVector3C a) {
return get0()==a.get0() && get1()==a.get1() && get2()==a.get2();
}

Expand Down Expand Up @@ -636,10 +637,13 @@ public final double dotCol(DMatrix3C m, int col) {


/**
* Do not use. This can be slow, use isEq() instead.
*
* Any implementation of DVector3I will return true if get0(), get1()
* and get2() return the same values.
*/
@Override
@Deprecated
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/ode4j/math/DVector3C.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface DVector3C {
public double get2();
public float[] toFloatArray();
public DVector3 clone();
public boolean isEq(DVector3C v);
public double lengthSquared();
public double length();
/**
Expand Down
24 changes: 23 additions & 1 deletion core/src/main/java/org/ode4j/math/DVector6.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,32 @@ public final double get(int i) {
return v[i];
}

public boolean equals(DVector6 v2) {
public boolean isEq(DVector6 v2) {
return Arrays.equals(v, v2.v);
}

/**
* Do not use. This can be slow, use isEq() instead.
*/
@Override
@Deprecated
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof DVector6)) return false;
return isEq((DVector6)obj);
}

@Override
public int hashCode() {
int h = 0;
for (double d: v) {
h |= Double.doubleToRawLongBits(d);
h <<= 4;
}
return h;
}

public void set0(double d) {
v[0] = d;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/ode4j/ode/internal/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public static final double dNextAfter(double start, double direction) {
//#else
//#define dIsNan(x) (_isnan(x))
//#endif
public final boolean dIsNan(double x) { return x == Double.NaN; }
public final boolean dIsNan(double x) { return Double.isNaN(x); }

//#define dCopySign(a,b) (copysign((a),(b)))
public final double dCopySign(double a, double b) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/ode4j/ode/internal/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public static void dMultiply1(DVector3 A, final DMatrix3C B,
public static void dMultiply1(DMatrix3 A, final DMatrix3C B,
final DMatrix3C C) {
// dMultiply1(A.v, ((DMatrix3)B).v, ((DMatrix3)C).v, 3, 3, 3);
dMultiply0(A, B.clone().eqTranspose(), C);
dMultiply0(A, B.reTranspose(), C);
// int i, j, k;
// double sum;
// // dAASSERT (A , B, C);
Expand Down Expand Up @@ -333,7 +333,7 @@ public static void dMultiply1(double[] A, final double[] B,
public static void dMultiply2(DMatrix3 A, final DMatrix3C B,
final DMatrix3C C) {
//dMultiply2(A.v, ((DMatrix3) B).v, ((DMatrix3) C).v, 3, 3, 3);
dMultiply0(A, B, C.clone().eqTranspose());
dMultiply0(A, B, C.reTranspose());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/ode4j/ode/internal/Objects_H.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static class dxQuickStepParameters extends CloneableParameter {
public double w; // the SOR over-relaxation parameter
@Override
protected dxQuickStepParameters clone() {
return clone();
return cloneThis();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void fprintf(OutputStream out, String fmt, Object ... args) {
//FileWriter fw = new FileWriter(f);
PrintWriter pw = new PrintWriter(out);
pw.printf(fmt, args);
if (out.equals(stderr)) pw.flush();
if (out.equals(stderr.out())) pw.flush();
}

public static void fprintf(FILE out, String fmt, Object ... args) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/ode4j/ode/internal/libccd/CCD.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static void penEPAPos(final ccd_pt_t pt, final ccd_pt_el_t<?> nearest,

ccdVec3Set(pos, CCD_ZERO, CCD_ZERO, CCD_ZERO);
scale = CCD_ZERO;
if (len % 2 == 1)
if ((len & 1) == 1)
len++;

for (i = 0; i < len / 2; i++){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ public final class Performator {
*/
public static final void begin(String key) {
Entry e = data.get(key);
//funny construct for theoretical thread safety
if (e == null) {
e = new Entry();
data.put(key, e);
data.putIfAbsent(key, e);
e = data.get(key);
}
e.begin();
}
Expand Down
18 changes: 9 additions & 9 deletions demo-cpp/src/test/java/org/ode4j/tests/math/TestDMatrix3.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public void testEqual(){
DMatrix3 x = newM3();
DMatrix3 xx = newM3();
DMatrix3 x1 = new DMatrix3();
assertTrue(x.isEqual(xx));
assertTrue(x.isEq(xx));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
x1.set(xx);
x1.set(i, j, 0);
assertFalse(x.isEqual(x1));
assertFalse(x.isEq(x1));
}
}
}
Expand Down Expand Up @@ -127,16 +127,16 @@ public void testSet(){
// assertEquals(x, new DMatrix3(2, 2, 2, 2, 2, 2, 2, 2, 2));

x = new DMatrix3();
assertFalse(x.isEqual(x2));
assertFalse(x.isEq(x2));
}

@Test
public void testInit(){
DMatrix3 x = newM3();
DMatrix3 y = new DMatrix3();
DMatrix3 z = new DMatrix3(x);
assertTrue(x.isEqual(z));
assertFalse(x.isEqual(y));
assertTrue(x.isEq(z));
assertFalse(x.isEq(y));

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Expand All @@ -150,10 +150,10 @@ public void testInit(){
public void testAdd(){
DMatrix3 x = newM3();
DMatrix3 t = new DMatrix3();
assertFalse(x.isEqual(t));
assertFalse(x.isEq(t));

t.add(x);
assertTrue(t.isEqual(x));
assertTrue(t.isEq(x));

// t = new dMatrix3();
// t.add(1, 2, 3, 4, 5, 6, 7, 8, 9);
Expand All @@ -165,7 +165,7 @@ public void testAdd(){
t.add(i, j, 1 + j + 3*i);
}
}
assertTrue(t.isEqual(x));
assertTrue(t.isEq(x));

// t.add0(3);
// t.add1(6);
Expand Down Expand Up @@ -209,7 +209,7 @@ public void testScale(){
// assertTrue(t.equals(y));
t.set(x);
t.scale(-2);
assertTrue(t.isEqual( new DMatrix3(-2, -4, -6, -8, -10, -12, -14, -16, -18) ));
assertTrue(t.isEq( new DMatrix3(-2, -4, -6, -8, -10, -12, -14, -16, -18) ));

// t.sub(0, 3);
// t.sub(1, 6);
Expand Down
24 changes: 12 additions & 12 deletions demo-cpp/src/test/java/org/ode4j/tests/math/TestDQuaternion.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public void testEqual(){
DQuaternion x2 = new DQuaternion(1, 0, 3, 4);
DQuaternion x3 = new DQuaternion(1, 2, 0, 4);
DQuaternion x4 = new DQuaternion(1, 2, 3, 0);
assertTrue(x.equals(xx));
assertFalse(x.equals(x1));
assertFalse(x.equals(x2));
assertFalse(x.equals(x3));
assertFalse(x.equals(x4));
assertTrue(x.isEq(xx));
assertFalse(x.isEq(x1));
assertFalse(x.isEq(x2));
assertFalse(x.isEq(x3));
assertFalse(x.isEq(x4));
}

@Test
Expand Down Expand Up @@ -106,8 +106,8 @@ public void testInit(){
DQuaternion x = new DQuaternion(1, 2, 3, 4);
DQuaternion y = new DQuaternion();
DQuaternion z = new DQuaternion(x);
assertTrue(x.equals(z));
assertFalse(x.equals(y));
assertTrue(x.isEq(z));
assertFalse(x.isEq(y));
assertEquals(y.get0(), 0.);
assertEquals(y.get1(), 0.);
assertEquals(y.get2(), 0.);
Expand All @@ -124,12 +124,12 @@ public void testAdd(){
DQuaternion x = new DQuaternion(1, 2, 3, 4);
DQuaternion y = new DQuaternion(4, 8, -1, -7);
DQuaternion t = new DQuaternion();
assertFalse(x.equals(y));
assertFalse(x.isEq(y));

t.add(x);
assertTrue(t.equals(x));
assertTrue(t.isEq(x));
t.add(3, 6, -4, -11);
assertTrue(t.equals(y));
assertTrue(t.isEq(y));

// t.add(0, -3);
// t.add(1, -6);
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testSub(){
DQuaternion x = new DQuaternion(1, 2, 3, 4);
DQuaternion y = new DQuaternion(4, 8, -1, -7);
DQuaternion t = new DQuaternion();
assertFalse(x.equals(y));
assertFalse(x.isEq(y));

t.add(x);
t.add(x);
Expand All @@ -195,7 +195,7 @@ public void testScale(){

t.set(y);
t.scale(0.5);
assertTrue(t.equals( new DQuaternion(2, 5, -3, -6.5) ));
assertTrue(t.isEq( new DQuaternion(2, 5, -3, -6.5) ));
}

// @Test
Expand Down

0 comments on commit 7484318

Please sign in to comment.