Skip to content

Commit 7360556

Browse files
author
Luc Maisonobe
committed
Fixed accuracy of 3D Line.revert().
JIRA: MATH-938 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1453218 13f79535-47bb-0310-9956-ffa450edef68
1 parent 43a6f15 commit 7360556

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ This is a minor release: It combines bug fixes and new features.
5555
Changes to existing features were made in a backwards-compatible
5656
way such as to allow drop-in replacement of the v3.1[.1] JAR file.
5757
">
58+
<action dev="luc" type="fix" issue="MATH-938" >
59+
Fixed accuracy of 3D Line.revert().
60+
</action>
5861
<action dev="luc" type="fix" issue="MATH-937" >
5962
Improved javadoc to explain how switching functions should
6063
behave across events in ODE events detection.

src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public void reset(final Vector3D p1, final Vector3D p2) throws MathIllegalArgume
8484
* @return a new instance, with reversed direction
8585
*/
8686
public Line revert() {
87-
return new Line(zero, zero.subtract(direction));
87+
final Line reverted = new Line(this);
88+
reverted.direction = reverted.direction.negate();
89+
return reverted;
8890
}
8991

9092
/** Get the normalized direction vector.

src/test/java/org/apache/commons/math3/geometry/euclidean/threed/LineTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,20 @@ public void testIntersection() throws MathIllegalArgumentException {
129129
Assert.assertNull(l.intersection(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0))));
130130
}
131131

132+
@Test
133+
public void testRevert() {
134+
135+
// setup
136+
Line line = new Line(new Vector3D(1653345.6696423641, 6170370.041579291, 90000),
137+
new Vector3D(1650757.5050732433, 6160710.879908984, 0.9));
138+
Vector3D expected = line.getDirection().negate();
139+
140+
// action
141+
Line reverted = line.revert();
142+
143+
// verify
144+
Assert.assertArrayEquals(expected.toArray(), reverted.getDirection().toArray(), 0);
145+
146+
}
147+
132148
}

0 commit comments

Comments
 (0)