Skip to content

Commit

Permalink
Fixed accuracy of 3D Line.revert().
Browse files Browse the repository at this point in the history
JIRA: MATH-938

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1453218 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Luc Maisonobe committed Mar 6, 2013
1 parent 43a6f15 commit 7360556
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ This is a minor release: It combines bug fixes and new features.
Changes to existing features were made in a backwards-compatible
way such as to allow drop-in replacement of the v3.1[.1] JAR file.
">
<action dev="luc" type="fix" issue="MATH-938" >
Fixed accuracy of 3D Line.revert().
</action>
<action dev="luc" type="fix" issue="MATH-937" >
Improved javadoc to explain how switching functions should
behave across events in ODE events detection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public void reset(final Vector3D p1, final Vector3D p2) throws MathIllegalArgume
* @return a new instance, with reversed direction
*/
public Line revert() {
return new Line(zero, zero.subtract(direction));
final Line reverted = new Line(this);
reverted.direction = reverted.direction.negate();
return reverted;
}

/** Get the normalized direction vector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,20 @@ public void testIntersection() throws MathIllegalArgumentException {
Assert.assertNull(l.intersection(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0))));
}

@Test
public void testRevert() {

// setup
Line line = new Line(new Vector3D(1653345.6696423641, 6170370.041579291, 90000),
new Vector3D(1650757.5050732433, 6160710.879908984, 0.9));
Vector3D expected = line.getDirection().negate();

// action
Line reverted = line.revert();

// verify
Assert.assertArrayEquals(expected.toArray(), reverted.getDirection().toArray(), 0);

}

}

0 comments on commit 7360556

Please sign in to comment.