commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1563204 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/geometry/enclosing/ test/java/org/apache/commons/math3/geometry/enclosing/
Date Fri, 31 Jan 2014 18:33:22 GMT
Author: luc
Date: Fri Jan 31 18:33:22 2014
New Revision: 1563204

URL: http://svn.apache.org/r1563204
Log:
USer should not provide space dimension, it should be automatic.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser2DTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser3DTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser.java?rev=1563204&r1=1563203&r2=1563204&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser.java
Fri Jan 31 18:33:22 2014
@@ -46,21 +46,15 @@ public class WelzlEncloser<S extends Spa
     /** Tolerance below which points are consider to be identical. */
     private final double tolerance;
 
-    /** Maximum number of points to define a ball. */
-    private final int max;
-
     /** Generator for balls on support. */
     private final SupportBallGenerator<S, P> generator;
 
     /** Simple constructor.
      * @param tolerance below which points are consider to be identical
-     * @param dimension dimension of the space
      * @param generator generator for balls on support
      */
-    protected WelzlEncloser(final double tolerance, final int dimension,
-                            final SupportBallGenerator<S, P> generator) {
+    public WelzlEncloser(final double tolerance, final SupportBallGenerator<S, P> generator)
{
         this.tolerance = tolerance;
-        this.max       = dimension + 1;
         this.generator = generator;
     }
 
@@ -83,11 +77,12 @@ public class WelzlEncloser<S extends Spa
      */
     private EnclosingBall<S, P> pivotingBall(final Iterable<P> points) {
 
-        List<P> extreme = new ArrayList<P>(max);
-        List<P> support = new ArrayList<P>(max);
+        final P first = points.iterator().next();
+        final List<P> extreme = new ArrayList<P>(first.getSpace().getDimension()
+ 1);
+        final List<P> support = new ArrayList<P>(first.getSpace().getDimension()
+ 1);
 
         // start with only first point selected as a candidate support
-        extreme.add(points.iterator().next());
+        extreme.add(first);
         EnclosingBall<S, P> ball = moveToFrontBall(extreme, extreme.size(), support);
 
         while (true) {
@@ -132,7 +127,7 @@ public class WelzlEncloser<S extends Spa
         // create a new ball on the prescribed support
         EnclosingBall<S, P> ball = generator.ballOnSupport(support);
 
-        if (ball.getSupportSize() < max) {
+        if (ball.getSupportSize() <= ball.getCenter().getSpace().getDimension()) {
 
             for (int i = 0; i < nbExtreme; ++i) {
                 final P pi = extreme.get(i);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser2DTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser2DTest.java?rev=1563204&r1=1563203&r2=1563204&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser2DTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser2DTest.java
Fri Jan 31 18:33:22 2014
@@ -35,7 +35,7 @@ public class WelzlEncloser2DTest {
     public void testNullList() {
         DiskGenerator generator = new DiskGenerator();
         WelzlEncloser<Euclidean2D, Vector2D> encloser =
-                new WelzlEncloser<Euclidean2D, Vector2D>(1.0e-10, 2, generator);
+                new WelzlEncloser<Euclidean2D, Vector2D>(1.0e-10, generator);
         EnclosingBall<Euclidean2D, Vector2D> ball = encloser.enclose(null);
         Assert.assertTrue(ball.getRadius() < 0);
     }
@@ -44,7 +44,7 @@ public class WelzlEncloser2DTest {
     public void testNoPoints() {
         DiskGenerator generator = new DiskGenerator();
         WelzlEncloser<Euclidean2D, Vector2D> encloser =
-                new WelzlEncloser<Euclidean2D, Vector2D>(1.0e-10, 2, generator);
+                new WelzlEncloser<Euclidean2D, Vector2D>(1.0e-10, generator);
         EnclosingBall<Euclidean2D, Vector2D> ball = encloser.enclose(new ArrayList<Vector2D>());
         Assert.assertTrue(ball.getRadius() < 0);
     }
@@ -149,7 +149,7 @@ public class WelzlEncloser2DTest {
     private EnclosingBall<Euclidean2D, Vector2D> checkDisk(List<Vector2D> points)
{
 
         WelzlEncloser<Euclidean2D, Vector2D> encloser =
-                new WelzlEncloser<Euclidean2D, Vector2D>(1.0e-10, 2, new DiskGenerator());
+                new WelzlEncloser<Euclidean2D, Vector2D>(1.0e-10, new DiskGenerator());
         EnclosingBall<Euclidean2D, Vector2D> disk = encloser.enclose(points);
 
         // all points are enclosed

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser3DTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser3DTest.java?rev=1563204&r1=1563203&r2=1563204&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser3DTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/enclosing/WelzlEncloser3DTest.java
Fri Jan 31 18:33:22 2014
@@ -17,7 +17,6 @@
 package org.apache.commons.math3.geometry.enclosing;
 
 import java.io.IOException;
-import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -39,7 +38,7 @@ public class WelzlEncloser3DTest {
     public void testNullList() {
         SphereGenerator generator = new SphereGenerator();
         WelzlEncloser<Euclidean3D, Vector3D> encloser =
-                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, 3, generator);
+                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, generator);
         EnclosingBall<Euclidean3D, Vector3D> ball = encloser.enclose(null);
         Assert.assertTrue(ball.getRadius() < 0);
     }
@@ -48,7 +47,7 @@ public class WelzlEncloser3DTest {
     public void testNoPoints() {
         SphereGenerator generator = new SphereGenerator();
         WelzlEncloser<Euclidean3D, Vector3D> encloser =
-                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, 3, generator);
+                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, generator);
         EnclosingBall<Euclidean3D, Vector3D> ball = encloser.enclose(new ArrayList<Vector3D>());
         Assert.assertTrue(ball.getRadius() < 0);
     }
@@ -69,7 +68,7 @@ public class WelzlEncloser3DTest {
                               new Vector3D(-7.140322188726825, -16.574152894557717,  11.710305611121410),
                               new Vector3D(-7.141116131477088, -16.574061164624560,  11.712938509321699));
         WelzlEncloser<Euclidean3D, Vector3D> encloser =
-                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, 3, new SphereGenerator());
+                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, new SphereGenerator());
         EnclosingBall<Euclidean3D, Vector3D> ball = encloser.enclose(list);
         Assert.assertTrue(ball.getRadius() > 0);
     }
@@ -98,7 +97,7 @@ public class WelzlEncloser3DTest {
                               new Vector3D( -0.98034899533935820,  -3.34004481162763960,
 13.03245014017556800));
 
         WelzlEncloser<Euclidean3D, Vector3D> encloser =
-                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, 3, new SphereGenerator());
+                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, new SphereGenerator());
         EnclosingBall<Euclidean3D, Vector3D> ball = encloser.enclose(list);
         Assert.assertTrue(ball.getRadius() > 0);
     }
@@ -159,7 +158,7 @@ public class WelzlEncloser3DTest {
     private EnclosingBall<Euclidean3D, Vector3D> checkSphere(List<Vector3D> points)
{
 
         WelzlEncloser<Euclidean3D, Vector3D> encloser =
-                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, 3, new SphereGenerator());
+                new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, new SphereGenerator());
         EnclosingBall<Euclidean3D, Vector3D> Sphere = encloser.enclose(points);
 
         // all points are enclosed



Mime
View raw message