Couple of bugs found!!!

Posts regarding potential bugs, enhancement requests, and general feedback on use of dyn4j
maheshkurmi
Posts: 63
Joined: Tue Mar 27, 2012 7:20 am
Location: India
Contact:

Couple of bugs found!!!

Hello William,

while developing simulator I found couple of small bugs in dyn4j library

1. Rectangle class in Geometry package

Code: Select all

`/**    * Returns the rotation about the local center in radians.    * @return double the rotation in radians    * @since 3.0.1    */   public double getRotation() {      // when the shape is created normals[1] will always be the positive x-axis      // we can get the rotation by comparing it to the positive x-axis      // since the normal vectors are rotated with the vertices when      // a shape is rotated      // return this.normals[1].getAngleBetween(Vector2.X_AXIS); //original                    return -this.normals[1].getAngleBetween(Vector2.X_AXIS); //corrected   }`

2. Polygon Class in Geometry package

Code: Select all

` @Override   public void rotate(double theta, double x, double y) {      super.rotate(theta, x, y);      int size = this.vertices.length;      for (int i = 0; i < size; i++) {         this.vertices[i].rotate(theta, x, y);         // this.normals[i].rotate(theta, x,y);//original         this.normals[i].rotate(theta); //corrected==>normals are not supposed to be rotated about point      }   }`

These bugs create problem in multi-fixture body with fixture as rectangle rotated by some angle. The angle of rotation is then calculated about wrongly transformed normals.
Anyway Dyn4j is one of the best thing I learnt so far.
Regards..
Last edited by maheshkurmi on Mon Nov 23, 2015 12:35 pm, edited 1 time in total.

zoom
Posts: 145
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: Couple of bugs found!!!

maheshkurmi wrote:return -this.normals[1].getAngleBetween(Vector2.X_AXIS); //original
return -this.normals[1].getAngleBetween(Vector2.X_AXIS); //corrected

I can't spot the difference

I'm sure William will appreciate a JUnit test case that can be included in the Dyn4J build if you have one.

maheshkurmi
Posts: 63
Joined: Tue Mar 27, 2012 7:20 am
Location: India
Contact:

Re: Couple of bugs found!!!

Oh.. i am sorry ..
edited
Actually I have modified dyn4j library quite a lot according to my use, so it will be confusing to include some test cases. I was just trying to find out bug related to polygon
fixture rotation, while adding facility for copy/paste in my physics simulator, and I finally found out these errors as the culprits.

William
Posts: 378
Joined: Sat Feb 06, 2010 10:23 pm

Re: Couple of bugs found!!!

Thank you very much for these bug reports. Both are quite embarrassing since I was doing these the right way in some other shape classes....

I've fixed the code, added some JUnit tests, and generated a new jar if you'd like to do testing. I'll try to get this released as a new version on Maven asap.

William
Attachments
dyn4j-v3.2.1-rc1.jar
dyn4j v3.2.1 RC1

William
Posts: 378
Joined: Sat Feb 06, 2010 10:23 pm

Re: Couple of bugs found!!!

A new version of dyn4j has been released with these fixes applied. Thanks again for reporting!

William