[MATH-1135] Fix MonotoneChain algorithm in case of collinear hull points. Thanks to Guillaume Marceau.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1609577 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2014-07-10 21:39:53 +00:00
parent ad882055ed
commit a7363a2ae6
3 changed files with 27 additions and 1 deletions

View File

@ -73,6 +73,11 @@ Users are encouraged to upgrade to this version as this release not
2. A few methods in the FastMath class are in fact slower that their 2. A few methods in the FastMath class are in fact slower that their
counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901). counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
"> ">
<action dev="tn" type="fix" issue="MATH-1135" due-to="Guillaume Marceau">
"MonotoneChain" failed to generate a convex hull if only a minimal hull
shall be created (includeCollinearPoints=false) and collinear hull points
were present in the input.
</action>
<action dev="tn" type="fix" issue="MATH-1131" due-to="Schalk W. Cronjé"> <action dev="tn" type="fix" issue="MATH-1131" due-to="Schalk W. Cronjé">
Improve performance of "KolmogorovSmirnovTest#kolmogorovSmirnovTest(...)" for Improve performance of "KolmogorovSmirnovTest#kolmogorovSmirnovTest(...)" for
large samples. large samples.

View File

@ -160,8 +160,8 @@ public class MonotoneChain extends AbstractConvexHullGenerator2D {
} else { } else {
if (distanceToCurrent > distanceToLast) { if (distanceToCurrent > distanceToLast) {
hull.remove(size - 1); hull.remove(size - 1);
hull.add(point);
} }
hull.add(point);
} }
return; return;
} else if (offset > 0) { } else if (offset > 0) {

View File

@ -53,6 +53,7 @@ public abstract class ConvexHullGenerator2DAbstractTest {
@Before @Before
public void setUp() { public void setUp() {
// by default, do not include collinear points
generator = createConvexHullGenerator(false); generator = createConvexHullGenerator(false);
random = new MersenneTwister(10); random = new MersenneTwister(10);
} }
@ -203,6 +204,26 @@ public abstract class ConvexHullGenerator2DAbstractTest {
checkConvexHull(points, hull); checkConvexHull(points, hull);
} }
@Test
public void testCollinearPointOnExistingBoundary() {
// MATH-1135: check that collinear points on the hull are handled correctly
// when only a minimal hull shall be constructed
final Collection<Vector2D> points = new ArrayList<Vector2D>();
points.add(new Vector2D(7.3152, 34.7472));
points.add(new Vector2D(6.400799999999997, 34.747199999999985));
points.add(new Vector2D(5.486399999999997, 34.7472));
points.add(new Vector2D(4.876799999999999, 34.7472));
points.add(new Vector2D(4.876799999999999, 34.1376));
points.add(new Vector2D(4.876799999999999, 30.48));
points.add(new Vector2D(6.0959999999999965, 30.48));
points.add(new Vector2D(6.0959999999999965, 34.1376));
points.add(new Vector2D(7.315199999999996, 34.1376));
points.add(new Vector2D(7.3152, 30.48));
final ConvexHull2D hull = createConvexHullGenerator(false).generate(points);
checkConvexHull(points, hull);
}
@Test @Test
public void testIssue1123() { public void testIssue1123() {