commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1555174 [1/2] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/geometry/euclidean/oned/ main/java/org/apache/commons/math3/geometry/euclidean/threed/ main/java/org/apache/commons/math3/geometry/euclidean/twod/ main/j...
Date Fri, 03 Jan 2014 18:06:20 GMT
Author: luc
Date: Fri Jan  3 18:06:20 2014
New Revision: 1555174

URL: http://svn.apache.org/r1555174
Log:
Generalized use of customizable tolerance in BSP trees.

Added:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSetTest.java   (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/Hyperplane.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSetTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/LineTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PlaneTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/LineTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SegmentTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/IntervalsSet.java Fri Jan  3 18:06:20 2014
@@ -32,10 +32,15 @@ import org.apache.commons.math3.util.Pre
  */
 public class IntervalsSet extends AbstractRegion<Euclidean1D, Euclidean1D> {
 
+    /** Default value for tolerance. */
+    private static final double DEFAULT_TOLERANCE = 1.0e-10;
+
     /** Build an intervals set representing the whole real line.
+     * @param tolerance tolerance below which points are considered identical.
+     * @since 3.3
      */
-    public IntervalsSet() {
-        super();
+    public IntervalsSet(final double tolerance) {
+        super(tolerance);
     }
 
     /** Build an intervals set corresponding to a single interval.
@@ -43,9 +48,11 @@ public class IntervalsSet extends Abstra
      * to {@code upper} (may be {@code Double.NEGATIVE_INFINITY})
      * @param upper upper bound of the interval, must be greater or equal
      * to {@code lower} (may be {@code Double.POSITIVE_INFINITY})
+     * @param tolerance tolerance below which points are considered identical.
+     * @since 3.3
      */
-    public IntervalsSet(final double lower, final double upper) {
-        super(buildTree(lower, upper));
+    public IntervalsSet(final double lower, final double upper, final double tolerance) {
+        super(buildTree(lower, upper, tolerance), tolerance);
     }
 
     /** Build an intervals set from an inside/outside BSP tree.
@@ -56,9 +63,11 @@ public class IntervalsSet extends Abstra
      * recommended to use the predefined constants
      * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
      * @param tree inside/outside BSP tree representing the intervals set
+     * @param tolerance tolerance below which points are considered identical.
+     * @since 3.3
      */
-    public IntervalsSet(final BSPTree<Euclidean1D> tree) {
-        super(tree);
+    public IntervalsSet(final BSPTree<Euclidean1D> tree, final double tolerance) {
+        super(tree, tolerance);
     }
 
     /** Build an intervals set from a Boundary REPresentation (B-rep).
@@ -79,19 +88,76 @@ public class IntervalsSet extends Abstra
      * <p>If the boundary is empty, the region will represent the whole
      * space.</p>
      * @param boundary collection of boundary elements
+     * @param tolerance tolerance below which points are considered identical.
+     * @since 3.3
      */
-    public IntervalsSet(final Collection<SubHyperplane<Euclidean1D>> boundary) {
-        super(boundary);
-    }
+    public IntervalsSet(final Collection<SubHyperplane<Euclidean1D>> boundary,
+                        final double tolerance) {
+        super(boundary, tolerance);
+    }
+
+//    /** Build an intervals set representing the whole real line.
+//     */
+//    public IntervalsSet() {
+//        super();
+//    }
+//
+//    /** Build an intervals set corresponding to a single interval.
+//     * @param lower lower bound of the interval, must be lesser or equal
+//     * to {@code upper} (may be {@code Double.NEGATIVE_INFINITY})
+//     * @param upper upper bound of the interval, must be greater or equal
+//     * to {@code lower} (may be {@code Double.POSITIVE_INFINITY})
+//     */
+//    public IntervalsSet(final double lower, final double upper) {
+//        super(buildTree(lower, upper));
+//    }
+//
+//    /** Build an intervals set from an inside/outside BSP tree.
+//     * <p>The leaf nodes of the BSP tree <em>must</em> have a
+//     * {@code Boolean} attribute representing the inside status of
+//     * the corresponding cell (true for inside cells, false for outside
+//     * cells). In order to avoid building too many small objects, it is
+//     * recommended to use the predefined constants
+//     * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
+//     * @param tree inside/outside BSP tree representing the intervals set
+//     */
+//    public IntervalsSet(final BSPTree<Euclidean1D> tree) {
+//        super(tree);
+//    }
+//
+//    /** Build an intervals set from a Boundary REPresentation (B-rep).
+//     * <p>The boundary is provided as a collection of {@link
+//     * SubHyperplane sub-hyperplanes}. Each sub-hyperplane has the
+//     * interior part of the region on its minus side and the exterior on
+//     * its plus side.</p>
+//     * <p>The boundary elements can be in any order, and can form
+//     * several non-connected sets (like for example polygons with holes
+//     * or a set of disjoints polyhedrons considered as a whole). In
+//     * fact, the elements do not even need to be connected together
+//     * (their topological connections are not used here). However, if the
+//     * boundary does not really separate an inside open from an outside
+//     * open (open having here its topological meaning), then subsequent
+//     * calls to the {@link
+//     * org.apache.commons.math3.geometry.partitioning.Region#checkPoint(org.apache.commons.math3.geometry.Point)
+//     * checkPoint} method will not be meaningful anymore.</p>
+//     * <p>If the boundary is empty, the region will represent the whole
+//     * space.</p>
+//     * @param boundary collection of boundary elements
+//     */
+//    public IntervalsSet(final Collection<SubHyperplane<Euclidean1D>> boundary) {
+//        super(boundary);
+//    }
 
     /** Build an inside/outside tree representing a single interval.
      * @param lower lower bound of the interval, must be lesser or equal
      * to {@code upper} (may be {@code Double.NEGATIVE_INFINITY})
      * @param upper upper bound of the interval, must be greater or equal
      * to {@code lower} (may be {@code Double.POSITIVE_INFINITY})
+     * @param tolerance tolerance below which points are considered identical.
      * @return the built tree
      */
-    private static BSPTree<Euclidean1D> buildTree(final double lower, final double upper) {
+    private static BSPTree<Euclidean1D> buildTree(final double lower, final double upper,
+                                                  final double tolerance) {
         if (Double.isInfinite(lower) && (lower < 0)) {
             if (Double.isInfinite(upper) && (upper > 0)) {
                 // the tree must cover the whole real line
@@ -99,14 +165,14 @@ public class IntervalsSet extends Abstra
             }
             // the tree must be open on the negative infinity side
             final SubHyperplane<Euclidean1D> upperCut =
-                new OrientedPoint(new Vector1D(upper), true).wholeHyperplane();
+                new OrientedPoint(new Vector1D(upper), true, tolerance).wholeHyperplane();
             return new BSPTree<Euclidean1D>(upperCut,
                                new BSPTree<Euclidean1D>(Boolean.FALSE),
                                new BSPTree<Euclidean1D>(Boolean.TRUE),
                                null);
         }
         final SubHyperplane<Euclidean1D> lowerCut =
-            new OrientedPoint(new Vector1D(lower), false).wholeHyperplane();
+            new OrientedPoint(new Vector1D(lower), false, tolerance).wholeHyperplane();
         if (Double.isInfinite(upper) && (upper > 0)) {
             // the tree must be open on the positive infinity side
             return new BSPTree<Euclidean1D>(lowerCut,
@@ -117,7 +183,7 @@ public class IntervalsSet extends Abstra
 
         // the tree must be bounded on the two sides
         final SubHyperplane<Euclidean1D> upperCut =
-            new OrientedPoint(new Vector1D(upper), true).wholeHyperplane();
+            new OrientedPoint(new Vector1D(upper), true, tolerance).wholeHyperplane();
         return new BSPTree<Euclidean1D>(lowerCut,
                                         new BSPTree<Euclidean1D>(Boolean.FALSE),
                                         new BSPTree<Euclidean1D>(upperCut,
@@ -131,7 +197,7 @@ public class IntervalsSet extends Abstra
     /** {@inheritDoc} */
     @Override
     public IntervalsSet buildNew(final BSPTree<Euclidean1D> tree) {
-        return new IntervalsSet(tree);
+        return new IntervalsSet(tree, getTolerance());
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/oned/OrientedPoint.java Fri Jan  3 18:06:20 2014
@@ -35,15 +35,31 @@ public class OrientedPoint implements Hy
     /** Orientation. */
     private boolean direct;
 
+    /** Tolerance below which points are considered to belong to the hyperplane. */
+    private final double tolerance;
+
     /** Simple constructor.
      * @param location location of the hyperplane
      * @param direct if true, the plus side of the hyperplane is towards
      * abscissas greater than {@code location}
+     * @param tolerance tolerance below which points are considered to belong to the hyperplane
+     * @since 3.3
      */
-    public OrientedPoint(final Vector1D location, final boolean direct) {
-        this.location = location;
-        this.direct   = direct;
-    }
+    public OrientedPoint(final Vector1D location, final boolean direct, final double tolerance) {
+        this.location  = location;
+        this.direct    = direct;
+        this.tolerance = tolerance;
+    }
+
+//    /** Simple constructor.
+//     * @param location location of the hyperplane
+//     * @param direct if true, the plus side of the hyperplane is towards
+//     * abscissas greater than {@code location}
+//     */
+//    public OrientedPoint(final Vector1D location, final boolean direct) {
+//        this.location = location;
+//        this.direct   = direct;
+//    }
 
     /** Copy the instance.
      * <p>Since instances are immutable, this method directly returns
@@ -90,7 +106,7 @@ public class OrientedPoint implements Hy
      * IntervalsSet IntervalsSet} instance)
      */
     public IntervalsSet wholeSpace() {
-        return new IntervalsSet();
+        return new IntervalsSet(tolerance);
     }
 
     /** {@inheritDoc} */
@@ -98,6 +114,11 @@ public class OrientedPoint implements Hy
         return !(direct ^ ((OrientedPoint) other).direct);
     }
 
+    /** {@inheritDoc} */
+    public double getTolerance() {
+        return tolerance;
+    }
+
     /** Get the hyperplane location on the real line.
      * @return the hyperplane location
      */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Line.java Fri Jan  3 18:06:20 2014
@@ -47,13 +47,20 @@ public class Line implements Embedding<E
     /** Line point closest to the origin. */
     private Vector3D zero;
 
+    /** Tolerance below which points are considered identical. */
+    private final double tolerance;
+
     /** Build a line from two points.
      * @param p1 first point belonging to the line (this can be any point)
      * @param p2 second point belonging to the line (this can be any point, different from p1)
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathIllegalArgumentException if the points are equal
+     * @since 3.3
      */
-    public Line(final Vector3D p1, final Vector3D p2) throws MathIllegalArgumentException {
+    public Line(final Vector3D p1, final Vector3D p2, final double tolerance)
+        throws MathIllegalArgumentException {
         reset(p1, p2);
+        this.tolerance = tolerance;
     }
 
     /** Copy constructor.
@@ -64,8 +71,18 @@ public class Line implements Embedding<E
     public Line(final Line line) {
         this.direction = line.direction;
         this.zero      = line.zero;
+        this.tolerance = line.tolerance;
     }
 
+//    /** Build a line from two points.
+//     * @param p1 first point belonging to the line (this can be any point)
+//     * @param p2 second point belonging to the line (this can be any point, different from p1)
+//     * @exception MathIllegalArgumentException if the points are equal
+//     */
+//    public Line(final Vector3D p1, final Vector3D p2) throws MathIllegalArgumentException {
+//        reset(p1, p2);
+//    }
+
     /** Reset the instance as if built from two points.
      * @param p1 first point belonging to the line (this can be any point)
      * @param p2 second point belonging to the line (this can be any point, different from p1)
@@ -81,6 +98,14 @@ public class Line implements Embedding<E
         zero = new Vector3D(1.0, p1, -p1.dotProduct(delta) / norm2, delta);
     }
 
+    /** Get the tolerance below which points are considered identical.
+     * @return tolerance below which points are considered identical
+     * @since 3.3
+     */
+    public double getTolerance() {
+        return tolerance;
+    }
+
     /** Get a line with reversed direction.
      * @return a new instance, with reversed direction
      */
@@ -168,7 +193,7 @@ public class Line implements Embedding<E
      */
     public boolean isSimilarTo(final Line line) {
         final double angle = Vector3D.angle(direction, line.direction);
-        return ((angle < 1.0e-10) || (angle > (FastMath.PI - 1.0e-10))) && contains(line.zero);
+        return ((angle < tolerance) || (angle > (FastMath.PI - tolerance))) && contains(line.zero);
     }
 
     /** Check if the instance contains a point.
@@ -176,7 +201,7 @@ public class Line implements Embedding<E
      * @return true if p belongs to the line
      */
     public boolean contains(final Vector3D p) {
-        return distance(p) < 1.0e-10;
+        return distance(p) < tolerance;
     }
 
     /** Compute the distance between the instance and a point.
@@ -244,7 +269,7 @@ public class Line implements Embedding<E
      * @return a sub-line covering the whole line
      */
     public SubLine wholeLine() {
-        return new SubLine(this, new IntervalsSet());
+        return new SubLine(this, new IntervalsSet(tolerance));
     }
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/OutlineExtractor.java Fri Jan  3 18:06:20 2014
@@ -64,7 +64,7 @@ public class OutlineExtractor {
     public Vector2D[][] getOutline(final PolyhedronsSet polyhedronsSet) {
 
         // project all boundary facets into one polygons set
-        final BoundaryProjector projector = new BoundaryProjector();
+        final BoundaryProjector projector = new BoundaryProjector(polyhedronsSet.getTolerance());
         polyhedronsSet.getTree(true).visit(projector);
         final PolygonsSet projected = projector.getProjected();
 
@@ -125,10 +125,15 @@ public class OutlineExtractor {
         /** Projection of the polyhedrons set on the plane. */
         private PolygonsSet projected;
 
+        /** Tolerance below which points are considered identical. */
+        private final double tolerance;
+
         /** Simple constructor.
+         * @param tolerance tolerance below which points are considered identical
          */
-        public BoundaryProjector() {
-            projected = new PolygonsSet(new BSPTree<Euclidean2D>(Boolean.FALSE));
+        public BoundaryProjector(final double tolerance) {
+            this.projected = new PolygonsSet(new BSPTree<Euclidean2D>(Boolean.FALSE), tolerance);
+            this.tolerance = tolerance;
         }
 
         /** {@inheritDoc} */
@@ -210,7 +215,7 @@ public class OutlineExtractor {
                         final Vector2D  cPoint    = new Vector2D(current3D.dotProduct(u),
                                                                  current3D.dotProduct(v));
                         final org.apache.commons.math3.geometry.euclidean.twod.Line line =
-                            new org.apache.commons.math3.geometry.euclidean.twod.Line(pPoint, cPoint);
+                            new org.apache.commons.math3.geometry.euclidean.twod.Line(pPoint, cPoint, tolerance);
                         SubHyperplane<Euclidean2D> edge = line.wholeHyperplane();
 
                         if (closed || (previous != 1)) {
@@ -218,7 +223,7 @@ public class OutlineExtractor {
                             // it defines one bounding point of the edge
                             final double angle = line.getAngle() + 0.5 * FastMath.PI;
                             final org.apache.commons.math3.geometry.euclidean.twod.Line l =
-                                new org.apache.commons.math3.geometry.euclidean.twod.Line(pPoint, angle);
+                                new org.apache.commons.math3.geometry.euclidean.twod.Line(pPoint, angle, tolerance);
                             edge = edge.split(l).getPlus();
                         }
 
@@ -227,7 +232,7 @@ public class OutlineExtractor {
                             // it defines one bounding point of the edge
                             final double angle = line.getAngle() + 0.5 * FastMath.PI;
                             final org.apache.commons.math3.geometry.euclidean.twod.Line l =
-                                new org.apache.commons.math3.geometry.euclidean.twod.Line(cPoint, angle);
+                                new org.apache.commons.math3.geometry.euclidean.twod.Line(cPoint, angle, tolerance);
                             edge = edge.split(l).getMinus();
                         }
 
@@ -239,7 +244,7 @@ public class OutlineExtractor {
 
                     }
                 }
-                final PolygonsSet projectedFacet = new PolygonsSet(edges);
+                final PolygonsSet projectedFacet = new PolygonsSet(edges, tolerance);
 
                 // add the contribution of the facet to the global outline
                 projected = (PolygonsSet) new RegionFactory<Euclidean2D>().union(projected, projectedFacet);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/Plane.java Fri Jan  3 18:06:20 2014
@@ -50,12 +50,19 @@ public class Plane implements Hyperplane
     /** Third vector of the plane frame (plane normal). */
     private Vector3D w;
 
+    /** Tolerance below which points are considered identical. */
+    private final double tolerance;
+
     /** Build a plane normal to a given direction and containing the origin.
      * @param normal normal direction to the plane
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathArithmeticException if the normal norm is too small
+     * @since 3.3
      */
-    public Plane(final Vector3D normal) throws MathArithmeticException {
+    public Plane(final Vector3D normal, final double tolerance)
+        throws MathArithmeticException {
         setNormal(normal);
+        this.tolerance = tolerance;
         originOffset = 0;
         setFrame();
     }
@@ -63,10 +70,14 @@ public class Plane implements Hyperplane
     /** Build a plane from a point and a normal.
      * @param p point belonging to the plane
      * @param normal normal direction to the plane
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathArithmeticException if the normal norm is too small
+     * @since 3.3
      */
-    public Plane(final Vector3D p, final Vector3D normal) throws MathArithmeticException {
+    public Plane(final Vector3D p, final Vector3D normal, final double tolerance)
+        throws MathArithmeticException {
         setNormal(normal);
+        this.tolerance = tolerance;
         originOffset = -p.dotProduct(w);
         setFrame();
     }
@@ -77,13 +88,49 @@ public class Plane implements Hyperplane
      * @param p1 first point belonging to the plane
      * @param p2 second point belonging to the plane
      * @param p3 third point belonging to the plane
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathArithmeticException if the points do not constitute a plane
+     * @since 3.3
      */
-    public Plane(final Vector3D p1, final Vector3D p2, final Vector3D p3)
+    public Plane(final Vector3D p1, final Vector3D p2, final Vector3D p3, final double tolerance)
         throws MathArithmeticException {
-        this(p1, p2.subtract(p1).crossProduct(p3.subtract(p1)));
+        this(p1, p2.subtract(p1).crossProduct(p3.subtract(p1)), tolerance);
     }
 
+//    /** Build a plane normal to a given direction and containing the origin.
+//     * @param normal normal direction to the plane
+//     * @exception MathArithmeticException if the normal norm is too small
+//     */
+//    public Plane(final Vector3D normal) throws MathArithmeticException {
+//        setNormal(normal);
+//        originOffset = 0;
+//        setFrame();
+//    }
+//
+//    /** Build a plane from a point and a normal.
+//     * @param p point belonging to the plane
+//     * @param normal normal direction to the plane
+//     * @exception MathArithmeticException if the normal norm is too small
+//     */
+//    public Plane(final Vector3D p, final Vector3D normal) throws MathArithmeticException {
+//        setNormal(normal);
+//        originOffset = -p.dotProduct(w);
+//        setFrame();
+//    }
+//
+//    /** Build a plane from three points.
+//     * <p>The plane is oriented in the direction of
+//     * {@code (p2-p1) ^ (p3-p1)}</p>
+//     * @param p1 first point belonging to the plane
+//     * @param p2 second point belonging to the plane
+//     * @param p3 third point belonging to the plane
+//     * @exception MathArithmeticException if the points do not constitute a plane
+//     */
+//    public Plane(final Vector3D p1, final Vector3D p2, final Vector3D p3)
+//        throws MathArithmeticException {
+//        this(p1, p2.subtract(p1).crossProduct(p3.subtract(p1)));
+//    }
+
     /** Copy constructor.
      * <p>The instance created is completely independant of the original
      * one. A deep copy is used, none of the underlying object are
@@ -92,10 +139,11 @@ public class Plane implements Hyperplane
      */
     public Plane(final Plane plane) {
         originOffset = plane.originOffset;
-        origin = plane.origin;
-        u      = plane.u;
-        v      = plane.v;
-        w      = plane.w;
+        origin       = plane.origin;
+        u            = plane.u;
+        v            = plane.v;
+        w            = plane.w;
+        tolerance    = plane.tolerance;
     }
 
     /** Copy the instance.
@@ -199,6 +247,11 @@ public class Plane implements Hyperplane
         return v;
     }
 
+    /** {@inheritDoc} */
+    public double getTolerance() {
+        return tolerance;
+    }
+
     /** Revert the plane.
      * <p>Replace the instance by a similar plane with opposite orientation.</p>
      * <p>The new plane frame is chosen in such a way that a 3D point that had
@@ -297,7 +350,7 @@ public class Plane implements Hyperplane
 
         final Vector3D delta = origin.subtract(center);
         final Plane plane = new Plane(center.add(rotation.applyTo(delta)),
-                                      rotation.applyTo(w));
+                                      rotation.applyTo(w), tolerance);
 
         // make sure the frame is transformed as desired
         plane.u = rotation.applyTo(u);
@@ -314,7 +367,7 @@ public class Plane implements Hyperplane
      */
     public Plane translate(final Vector3D translation) {
 
-        final Plane plane = new Plane(origin.add(translation), w);
+        final Plane plane = new Plane(origin.add(translation), w, tolerance);
 
         // make sure the frame is transformed as desired
         plane.u = u;
@@ -350,8 +403,8 @@ public class Plane implements Hyperplane
         if (direction.getNorm() < 1.0e-10) {
             return null;
         }
-        final Vector3D point = intersection(this, other, new Plane(direction));
-        return new Line(point, point.add(direction));
+        final Vector3D point = intersection(this, other, new Plane(direction, tolerance));
+        return new Line(point, point.add(direction), tolerance);
     }
 
     /** Get the intersection point of three planes.
@@ -400,7 +453,7 @@ public class Plane implements Hyperplane
      * @return a region covering the whole hyperplane
      */
     public SubPlane wholeHyperplane() {
-        return new SubPlane(this, new PolygonsSet());
+        return new SubPlane(this, new PolygonsSet(tolerance));
     }
 
     /** Build a region covering the whole space.
@@ -408,7 +461,7 @@ public class Plane implements Hyperplane
      * PolyhedronsSet PolyhedronsSet} instance)
      */
     public PolyhedronsSet wholeSpace() {
-        return new PolyhedronsSet();
+        return new PolyhedronsSet(tolerance);
     }
 
     /** Check if the instance contains a point.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java Fri Jan  3 18:06:20 2014
@@ -42,9 +42,11 @@ import org.apache.commons.math3.util.Fas
 public class PolyhedronsSet extends AbstractRegion<Euclidean3D, Euclidean2D> {
 
     /** Build a polyhedrons set representing the whole real line.
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public PolyhedronsSet() {
-        super();
+    public PolyhedronsSet(final double tolerance) {
+        super(tolerance);
     }
 
     /** Build a polyhedrons set from a BSP tree.
@@ -55,9 +57,11 @@ public class PolyhedronsSet extends Abst
      * recommended to use the predefined constants
      * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
      * @param tree inside/outside BSP tree representing the region
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public PolyhedronsSet(final BSPTree<Euclidean3D> tree) {
-        super(tree);
+    public PolyhedronsSet(final BSPTree<Euclidean3D> tree, final double tolerance) {
+        super(tree, tolerance);
     }
 
     /** Build a polyhedrons set from a Boundary REPresentation (B-rep).
@@ -78,9 +82,12 @@ public class PolyhedronsSet extends Abst
      * space.</p>
      * @param boundary collection of boundary elements, as a
      * collection of {@link SubHyperplane SubHyperplane} objects
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public PolyhedronsSet(final Collection<SubHyperplane<Euclidean3D>> boundary) {
-        super(boundary);
+    public PolyhedronsSet(final Collection<SubHyperplane<Euclidean3D>> boundary,
+                          final double tolerance) {
+        super(boundary, tolerance);
     }
 
     /** Build a parallellepipedic box.
@@ -90,12 +97,71 @@ public class PolyhedronsSet extends Abst
      * @param yMax high bound along the y direction
      * @param zMin low bound along the z direction
      * @param zMax high bound along the z direction
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
     public PolyhedronsSet(final double xMin, final double xMax,
                           final double yMin, final double yMax,
-                          final double zMin, final double zMax) {
-        super(buildBoundary(xMin, xMax, yMin, yMax, zMin, zMax));
-    }
+                          final double zMin, final double zMax,
+                          final double tolerance) {
+        super(buildBoundary(xMin, xMax, yMin, yMax, zMin, zMax, tolerance), tolerance);
+    }
+
+//    /** Build a polyhedrons set representing the whole real line.
+//     */
+//    public PolyhedronsSet() {
+//        super();
+//    }
+//
+//    /** Build a polyhedrons set from a BSP tree.
+//     * <p>The leaf nodes of the BSP tree <em>must</em> have a
+//     * {@code Boolean} attribute representing the inside status of
+//     * the corresponding cell (true for inside cells, false for outside
+//     * cells). In order to avoid building too many small objects, it is
+//     * recommended to use the predefined constants
+//     * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
+//     * @param tree inside/outside BSP tree representing the region
+//     */
+//    public PolyhedronsSet(final BSPTree<Euclidean3D> tree) {
+//        super(tree);
+//    }
+//
+//    /** Build a polyhedrons set from a Boundary REPresentation (B-rep).
+//     * <p>The boundary is provided as a collection of {@link
+//     * SubHyperplane sub-hyperplanes}. Each sub-hyperplane has the
+//     * interior part of the region on its minus side and the exterior on
+//     * its plus side.</p>
+//     * <p>The boundary elements can be in any order, and can form
+//     * several non-connected sets (like for example polyhedrons with holes
+//     * or a set of disjoint polyhedrons considered as a whole). In
+//     * fact, the elements do not even need to be connected together
+//     * (their topological connections are not used here). However, if the
+//     * boundary does not really separate an inside open from an outside
+//     * open (open having here its topological meaning), then subsequent
+//     * calls to the {@link Region#checkPoint(Point) checkPoint} method will
+//     * not be meaningful anymore.</p>
+//     * <p>If the boundary is empty, the region will represent the whole
+//     * space.</p>
+//     * @param boundary collection of boundary elements, as a
+//     * collection of {@link SubHyperplane SubHyperplane} objects
+//     */
+//    public PolyhedronsSet(final Collection<SubHyperplane<Euclidean3D>> boundary) {
+//        super(boundary);
+//    }
+//
+//    /** Build a parallellepipedic box.
+//     * @param xMin low bound along the x direction
+//     * @param xMax high bound along the x direction
+//     * @param yMin low bound along the y direction
+//     * @param yMax high bound along the y direction
+//     * @param zMin low bound along the z direction
+//     * @param zMax high bound along the z direction
+//     */
+//    public PolyhedronsSet(final double xMin, final double xMax,
+//                          final double yMin, final double yMax,
+//                          final double zMin, final double zMax) {
+//        super(buildBoundary(xMin, xMax, yMin, yMax, zMin, zMax));
+//    }
 
     /** Build a parallellepipedic box boundary.
      * @param xMin low bound along the x direction
@@ -104,17 +170,20 @@ public class PolyhedronsSet extends Abst
      * @param yMax high bound along the y direction
      * @param zMin low bound along the z direction
      * @param zMax high bound along the z direction
+     * @param tolerance tolerance below which points are considered identical
      * @return boundary tree
+     * @since 3.3
      */
     private static BSPTree<Euclidean3D> buildBoundary(final double xMin, final double xMax,
                                                       final double yMin, final double yMax,
-                                                      final double zMin, final double zMax) {
-        final Plane pxMin = new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I);
-        final Plane pxMax = new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I);
-        final Plane pyMin = new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J);
-        final Plane pyMax = new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J);
-        final Plane pzMin = new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K);
-        final Plane pzMax = new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K);
+                                                      final double zMin, final double zMax,
+                                                      final double tolerance) {
+        final Plane pxMin = new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I, tolerance);
+        final Plane pxMax = new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I,  tolerance);
+        final Plane pyMin = new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J, tolerance);
+        final Plane pyMax = new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J,  tolerance);
+        final Plane pzMin = new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K, tolerance);
+        final Plane pzMax = new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K,  tolerance);
         @SuppressWarnings("unchecked")
         final Region<Euclidean3D> boundary =
         new RegionFactory<Euclidean3D>().buildConvex(pxMin, pxMax, pyMin, pyMax, pzMin, pzMax);
@@ -124,7 +193,7 @@ public class PolyhedronsSet extends Abst
     /** {@inheritDoc} */
     @Override
     public PolyhedronsSet buildNew(final BSPTree<Euclidean3D> tree) {
-        return new PolyhedronsSet(tree);
+        return new PolyhedronsSet(tree, getTolerance());
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java Fri Jan  3 18:06:20 2014
@@ -51,19 +51,33 @@ public class SubLine {
     /** Create a sub-line from two endpoints.
      * @param start start point
      * @param end end point
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathIllegalArgumentException if the points are equal
+     * @since 3.3
      */
-    public SubLine(final Vector3D start, final Vector3D end)
+    public SubLine(final Vector3D start, final Vector3D end, final double tolerance)
         throws MathIllegalArgumentException {
-        this(new Line(start, end), buildIntervalSet(start, end));
+        this(new Line(start, end, tolerance), buildIntervalSet(start, end, tolerance));
     }
 
+//    /** Create a sub-line from two endpoints.
+//     * @param start start point
+//     * @param end end point
+//     * @exception MathIllegalArgumentException if the points are equal
+//     * @deprecated as of 3.3, replaced with {@link #SubLine(Vector3D, Vector3D, double)}
+//     */
+//    public SubLine(final Vector3D start, final Vector3D end)
+//        throws MathIllegalArgumentException {
+//        this(start, end, 1.0e-10);
+//    }
+
     /** Create a sub-line from a segment.
      * @param segment single segment forming the sub-line
      * @exception MathIllegalArgumentException if the segment endpoints are equal
      */
     public SubLine(final Segment segment) throws MathIllegalArgumentException {
-        this(segment.getLine(), buildIntervalSet(segment.getStart(), segment.getEnd()));
+        this(segment.getLine(),
+             buildIntervalSet(segment.getStart(), segment.getEnd(), segment.getLine().getTolerance()));
     }
 
     /** Get the endpoints of the sub-line.
@@ -135,13 +149,15 @@ public class SubLine {
      * @param start start point
      * @param end end point
      * @return an interval set
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathIllegalArgumentException if the points are equal
      */
-    private static IntervalsSet buildIntervalSet(final Vector3D start, final Vector3D end)
+    private static IntervalsSet buildIntervalSet(final Vector3D start, final Vector3D end, final double tolerance)
         throws MathIllegalArgumentException {
-        final Line line = new Line(start, end);
+        final Line line = new Line(start, end, tolerance);
         return new IntervalsSet(line.toSubSpace((Point<Euclidean3D>) start).getX(),
-                                line.toSubSpace((Point<Euclidean3D>) end).getX());
+                                line.toSubSpace((Point<Euclidean3D>) end).getX(),
+                                tolerance);
     }
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubPlane.java Fri Jan  3 18:06:20 2014
@@ -58,6 +58,7 @@ public class SubPlane extends AbstractSu
         final Plane otherPlane = (Plane) hyperplane;
         final Plane thisPlane  = (Plane) getHyperplane();
         final Line  inter      = otherPlane.intersection(thisPlane);
+        final double tolerance = thisPlane.getTolerance();
 
         if (inter == null) {
             // the hyperplanes are parallel,
@@ -82,7 +83,7 @@ public class SubPlane extends AbstractSu
             q           = tmp;
         }
         final org.apache.commons.math3.geometry.euclidean.twod.Line line2D =
-            new org.apache.commons.math3.geometry.euclidean.twod.Line(p, q);
+            new org.apache.commons.math3.geometry.euclidean.twod.Line(p, q, tolerance);
 
         // check the side on the 2D plane
         return getRemainingRegion().side(line2D);
@@ -101,6 +102,7 @@ public class SubPlane extends AbstractSu
         final Plane otherPlane = (Plane) hyperplane;
         final Plane thisPlane  = (Plane) getHyperplane();
         final Line  inter      = otherPlane.intersection(thisPlane);
+        final double tolerance = thisPlane.getTolerance();
 
         if (inter == null) {
             // the hyperplanes are parallel
@@ -120,9 +122,9 @@ public class SubPlane extends AbstractSu
             q           = tmp;
         }
         final SubHyperplane<Euclidean2D> l2DMinus =
-            new org.apache.commons.math3.geometry.euclidean.twod.Line(p, q).wholeHyperplane();
+            new org.apache.commons.math3.geometry.euclidean.twod.Line(p, q, tolerance).wholeHyperplane();
         final SubHyperplane<Euclidean2D> l2DPlus =
-            new org.apache.commons.math3.geometry.euclidean.twod.Line(q, p).wholeHyperplane();
+            new org.apache.commons.math3.geometry.euclidean.twod.Line(q, p, tolerance).wholeHyperplane();
 
         final BSPTree<Euclidean2D> splitTree = getRemainingRegion().getTree(false).split(l2DMinus);
         final BSPTree<Euclidean2D> plusTree  = getRemainingRegion().isEmpty(splitTree.getPlus()) ?
@@ -135,8 +137,8 @@ public class SubPlane extends AbstractSu
                                                    new BSPTree<Euclidean2D>(l2DMinus, new BSPTree<Euclidean2D>(Boolean.FALSE),
                                                                             splitTree.getMinus(), null);
 
-        return new SplitSubHyperplane<Euclidean3D>(new SubPlane(thisPlane.copySelf(), new PolygonsSet(plusTree)),
-                                                   new SubPlane(thisPlane.copySelf(), new PolygonsSet(minusTree)));
+        return new SplitSubHyperplane<Euclidean3D>(new SubPlane(thisPlane.copySelf(), new PolygonsSet(plusTree, tolerance)),
+                                                   new SubPlane(thisPlane.copySelf(), new PolygonsSet(minusTree, tolerance)));
 
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java Fri Jan  3 18:06:20 2014
@@ -74,21 +74,30 @@ public class Line implements Hyperplane<
     /** Offset of the frame origin. */
     private double originOffset;
 
+    /** Tolerance below which points are considered identical. */
+    private final double tolerance;
+
     /** Build a line from two points.
      * <p>The line is oriented from p1 to p2</p>
      * @param p1 first point
      * @param p2 second point
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public Line(final Vector2D p1, final Vector2D p2) {
+    public Line(final Vector2D p1, final Vector2D p2, final double tolerance) {
         reset(p1, p2);
+        this.tolerance = tolerance;
     }
 
     /** Build a line from a point and an angle.
      * @param p point belonging to the line
      * @param angle angle of the line with respect to abscissa axis
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public Line(final Vector2D p, final double angle) {
+    public Line(final Vector2D p, final double angle, final double tolerance) {
         reset(p, angle);
+        this.tolerance = tolerance;
     }
 
     /** Build a line from its internal characteristics.
@@ -96,14 +105,48 @@ public class Line implements Hyperplane<
      * @param cos cosine of the angle
      * @param sin sine of the angle
      * @param originOffset offset of the origin
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    private Line(final double angle, final double cos, final double sin, final double originOffset) {
+    private Line(final double angle, final double cos, final double sin,
+                 final double originOffset, final double tolerance) {
         this.angle        = angle;
         this.cos          = cos;
         this.sin          = sin;
         this.originOffset = originOffset;
+        this.tolerance    = tolerance;
     }
 
+//    /** Build a line from two points.
+//     * <p>The line is oriented from p1 to p2</p>
+//     * @param p1 first point
+//     * @param p2 second point
+//     */
+//    public Line(final Vector2D p1, final Vector2D p2) {
+//        reset(p1, p2);
+//    }
+//
+//    /** Build a line from a point and an angle.
+//     * @param p point belonging to the line
+//     * @param angle angle of the line with respect to abscissa axis
+//     */
+//    public Line(final Vector2D p, final double angle) {
+//        reset(p, angle);
+//    }
+//
+//    /** Build a line from its internal characteristics.
+//     * @param angle angle of the line with respect to abscissa axis
+//     * @param cos cosine of the angle
+//     * @param sin sine of the angle
+//     * @param originOffset offset of the origin
+//     */
+//    private Line(final double angle, final double cos, final double sin, final double originOffset) {
+//        this.angle        = angle;
+//        this.cos          = cos;
+//        this.sin          = sin;
+//        this.originOffset = originOffset;
+//    }
+
     /** Copy constructor.
      * <p>The created instance is completely independent from the
      * original instance, it is a deep copy.</p>
@@ -114,6 +157,7 @@ public class Line implements Hyperplane<
         cos          = FastMath.cos(angle);
         sin          = FastMath.sin(angle);
         originOffset = line.originOffset;
+        tolerance    = line.tolerance;
     }
 
     /** {@inheritDoc} */
@@ -174,7 +218,7 @@ public class Line implements Hyperplane<
      */
     public Line getReverse() {
         return new Line((angle < FastMath.PI) ? (angle + FastMath.PI) : (angle - FastMath.PI),
-                        -cos, -sin, -originOffset);
+                        -cos, -sin, -originOffset, tolerance);
     }
 
     /** Transform a space point into a sub-space point.
@@ -219,7 +263,7 @@ public class Line implements Hyperplane<
      */
     public Vector2D intersection(final Line other) {
         final double d = sin * other.cos - other.sin * cos;
-        if (FastMath.abs(d) < 1.0e-10) {
+        if (FastMath.abs(d) < tolerance) {
             return null;
         }
         return new Vector2D((cos * other.originOffset - other.cos * originOffset) / d,
@@ -227,8 +271,13 @@ public class Line implements Hyperplane<
     }
 
     /** {@inheritDoc} */
+    public double getTolerance() {
+        return tolerance;
+    }
+
+    /** {@inheritDoc} */
     public SubLine wholeHyperplane() {
-        return new SubLine(this, new IntervalsSet());
+        return new SubLine(this, new IntervalsSet(tolerance));
     }
 
     /** Build a region covering the whole space.
@@ -236,7 +285,7 @@ public class Line implements Hyperplane<
      * PolygonsSet PolygonsSet} instance)
      */
     public PolygonsSet wholeSpace() {
-        return new PolygonsSet();
+        return new PolygonsSet(tolerance);
     }
 
     /** Get the offset (oriented distance) of a parallel line.
@@ -293,7 +342,7 @@ public class Line implements Hyperplane<
      * @return true if p belongs to the line
      */
     public boolean contains(final Vector2D p) {
-        return FastMath.abs(getOffset(p)) < 1.0e-10;
+        return FastMath.abs(getOffset(p)) < tolerance;
     }
 
     /** Compute the distance between the instance and a point.
@@ -315,7 +364,7 @@ public class Line implements Hyperplane<
      * (they can have either the same or opposite orientations)
      */
     public boolean isParallelTo(final Line line) {
-        return FastMath.abs(sin * line.cos - cos * line.sin) < 1.0e-10;
+        return FastMath.abs(sin * line.cos - cos * line.sin) < tolerance;
     }
 
     /** Translate the line to force it passing by a point.
@@ -440,7 +489,7 @@ public class Line implements Hyperplane<
             final double inv     = 1.0 / FastMath.sqrt(rSin * rSin + rCos * rCos);
             return new Line(FastMath.PI + FastMath.atan2(-rSin, -rCos),
                             inv * rCos, inv * rSin,
-                            inv * rOffset);
+                            inv * rOffset, line.tolerance);
         }
 
         /** {@inheritDoc} */
@@ -452,7 +501,7 @@ public class Line implements Hyperplane<
             final Line transformedLine = (Line) transformed;
             final Vector1D newLoc =
                 transformedLine.toSubSpace(apply(originalLine.toSpace(op.getLocation())));
-            return new OrientedPoint(newLoc, op.isDirect()).wholeHyperplane();
+            return new OrientedPoint(newLoc, op.isDirect(), originalLine.tolerance).wholeHyperplane();
         }
 
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/NestedLoops.java Fri Jan  3 18:06:20 2014
@@ -59,29 +59,39 @@ class NestedLoops {
     /** Indicator for original loop orientation. */
     private boolean originalIsClockwise;
 
+    /** Tolerance below which points are considered identical. */
+    private final double tolerance;
+
     /** Simple Constructor.
      * <p>Build an empty tree of nested loops. This instance will become
      * the root node of a complete tree, it is not associated with any
      * loop by itself, the outermost loops are in the root tree child
      * nodes.</p>
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public NestedLoops() {
-        surrounded = new ArrayList<NestedLoops>();
+    public NestedLoops(final double tolerance) {
+        this.surrounded = new ArrayList<NestedLoops>();
+        this.tolerance  = tolerance;
     }
 
     /** Constructor.
      * <p>Build a tree node with neither parent nor children</p>
      * @param loop boundary loop (will be reversed in place if needed)
+     * @param tolerance tolerance below which points are considered identical
      * @exception MathIllegalArgumentException if an outline has an open boundary loop
+     * @since 3.3
      */
-    private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {
+    private NestedLoops(final Vector2D[] loop, final double tolerance)
+        throws MathIllegalArgumentException {
 
         if (loop[0] == null) {
             throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
         }
 
-        this.loop = loop;
-        surrounded = new ArrayList<NestedLoops>();
+        this.loop       = loop;
+        this.surrounded = new ArrayList<NestedLoops>();
+        this.tolerance  = tolerance;
 
         // build the polygon defined by the loop
         final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
@@ -89,13 +99,14 @@ class NestedLoops {
         for (int i = 0; i < loop.length; ++i) {
             final Vector2D previous = current;
             current = loop[i];
-            final Line   line   = new Line(previous, current);
+            final Line   line   = new Line(previous, current, tolerance);
             final IntervalsSet region =
                 new IntervalsSet(line.toSubSpace((Point<Euclidean2D>) previous).getX(),
-                                 line.toSubSpace((Point<Euclidean2D>) current).getX());
+                                 line.toSubSpace((Point<Euclidean2D>) current).getX(),
+                                 tolerance);
             edges.add(new SubLine(line, region));
         }
-        polygon = new PolygonsSet(edges);
+        polygon = new PolygonsSet(edges, tolerance);
 
         // ensure the polygon encloses a finite region of the plane
         if (Double.isInfinite(polygon.getSize())) {
@@ -113,7 +124,7 @@ class NestedLoops {
      * boundary loops or open boundary loops
      */
     public void add(final Vector2D[] bLoop) throws MathIllegalArgumentException {
-        add(new NestedLoops(bLoop));
+        add(new NestedLoops(bLoop, tolerance));
     }
 
     /** Add a loop in a tree.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java Fri Jan  3 18:06:20 2014
@@ -47,9 +47,11 @@ public class PolygonsSet extends Abstrac
     private Vector2D[][] vertices;
 
     /** Build a polygons set representing the whole real line.
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public PolygonsSet() {
-        super();
+    public PolygonsSet(final double tolerance) {
+        super(tolerance);
     }
 
     /** Build a polygons set from a BSP tree.
@@ -60,9 +62,11 @@ public class PolygonsSet extends Abstrac
      * recommended to use the predefined constants
      * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
      * @param tree inside/outside BSP tree representing the region
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public PolygonsSet(final BSPTree<Euclidean2D> tree) {
-        super(tree);
+    public PolygonsSet(final BSPTree<Euclidean2D> tree, final double tolerance) {
+        super(tree, tolerance);
     }
 
     /** Build a polygons set from a Boundary REPresentation (B-rep).
@@ -84,9 +88,11 @@ public class PolygonsSet extends Abstrac
      * space.</p>
      * @param boundary collection of boundary elements, as a
      * collection of {@link SubHyperplane SubHyperplane} objects
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public PolygonsSet(final Collection<SubHyperplane<Euclidean2D>> boundary) {
-        super(boundary);
+    public PolygonsSet(final Collection<SubHyperplane<Euclidean2D>> boundary, final double tolerance) {
+        super(boundary, tolerance);
     }
 
     /** Build a parallellepipedic box.
@@ -94,10 +100,13 @@ public class PolygonsSet extends Abstrac
      * @param xMax high bound along the x direction
      * @param yMin low bound along the y direction
      * @param yMax high bound along the y direction
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
     public PolygonsSet(final double xMin, final double xMax,
-                       final double yMin, final double yMax) {
-        super(boxBoundary(xMin, xMax, yMin, yMax));
+                       final double yMin, final double yMax,
+                       final double tolerance) {
+        super(boxBoundary(xMin, xMax, yMin, yMax, tolerance), tolerance);
     }
 
     /** Build a polygon from a simple list of vertices.
@@ -129,30 +138,85 @@ public class PolygonsSet extends Abstrac
      * @param hyperplaneThickness tolerance below which points are considered to
      * belong to the hyperplane (which is therefore more a slab)
      * @param vertices vertices of the simple loop boundary
-     * @since 3.1
      */
     public PolygonsSet(final double hyperplaneThickness, final Vector2D ... vertices) {
-        super(verticesToTree(hyperplaneThickness, vertices));
+        super(verticesToTree(hyperplaneThickness, vertices), hyperplaneThickness);
     }
 
+//    /** Build a polygons set representing the whole real line.
+//     */
+//    public PolygonsSet() {
+//        super();
+//    }
+//
+//    /** Build a polygons set from a BSP tree.
+//     * <p>The leaf nodes of the BSP tree <em>must</em> have a
+//     * {@code Boolean} attribute representing the inside status of
+//     * the corresponding cell (true for inside cells, false for outside
+//     * cells). In order to avoid building too many small objects, it is
+//     * recommended to use the predefined constants
+//     * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
+//     * @param tree inside/outside BSP tree representing the region
+//     */
+//    public PolygonsSet(final BSPTree<Euclidean2D> tree) {
+//        super(tree);
+//    }
+//
+//    /** Build a polygons set from a Boundary REPresentation (B-rep).
+//     * <p>The boundary is provided as a collection of {@link
+//     * SubHyperplane sub-hyperplanes}. Each sub-hyperplane has the
+//     * interior part of the region on its minus side and the exterior on
+//     * its plus side.</p>
+//     * <p>The boundary elements can be in any order, and can form
+//     * several non-connected sets (like for example polygons with holes
+//     * or a set of disjoint polygons considered as a whole). In
+//     * fact, the elements do not even need to be connected together
+//     * (their topological connections are not used here). However, if the
+//     * boundary does not really separate an inside open from an outside
+//     * open (open having here its topological meaning), then subsequent
+//     * calls to the {@link
+//     * org.apache.commons.math3.geometry.partitioning.Region#checkPoint(org.apache.commons.math3.geometry.Point)
+//     * checkPoint} method will not be meaningful anymore.</p>
+//     * <p>If the boundary is empty, the region will represent the whole
+//     * space.</p>
+//     * @param boundary collection of boundary elements, as a
+//     * collection of {@link SubHyperplane SubHyperplane} objects
+//     */
+//    public PolygonsSet(final Collection<SubHyperplane<Euclidean2D>> boundary) {
+//        super(boundary);
+//    }
+//
+//    /** Build a parallellepipedic box.
+//     * @param xMin low bound along the x direction
+//     * @param xMax high bound along the x direction
+//     * @param yMin low bound along the y direction
+//     * @param yMax high bound along the y direction
+//     */
+//    public PolygonsSet(final double xMin, final double xMax,
+//                       final double yMin, final double yMax) {
+//        super(boxBoundary(xMin, xMax, yMin, yMax));
+//    }
+//
     /** Create a list of hyperplanes representing the boundary of a box.
      * @param xMin low bound along the x direction
      * @param xMax high bound along the x direction
      * @param yMin low bound along the y direction
      * @param yMax high bound along the y direction
+     * @param tolerance tolerance below which points are considered identical
      * @return boundary of the box
      */
     private static Line[] boxBoundary(final double xMin, final double xMax,
-                                      final double yMin, final double yMax) {
+                                      final double yMin, final double yMax,
+                                      final double tolerance) {
         final Vector2D minMin = new Vector2D(xMin, yMin);
         final Vector2D minMax = new Vector2D(xMin, yMax);
         final Vector2D maxMin = new Vector2D(xMax, yMin);
         final Vector2D maxMax = new Vector2D(xMax, yMax);
         return new Line[] {
-            new Line(minMin, maxMin),
-            new Line(maxMin, maxMax),
-            new Line(maxMax, minMax),
-            new Line(minMax, minMin)
+            new Line(minMin, maxMin, tolerance),
+            new Line(maxMin, maxMax, tolerance),
+            new Line(maxMax, minMax, tolerance),
+            new Line(minMax, minMin, tolerance)
         };
     }
 
@@ -199,7 +263,7 @@ public class PolygonsSet extends Abstrac
             // with the current one
             Line line = start.sharedLineWith(end);
             if (line == null) {
-                line = new Line(start.getLocation(), end.getLocation());
+                line = new Line(start.getLocation(), end.getLocation(), hyperplaneThickness);
             }
 
             // create the edge and store it
@@ -514,7 +578,7 @@ public class PolygonsSet extends Abstrac
     /** {@inheritDoc} */
     @Override
     public PolygonsSet buildNew(final BSPTree<Euclidean2D> tree) {
-        return new PolygonsSet(tree);
+        return new PolygonsSet(tree, getTolerance());
     }
 
     /** {@inheritDoc} */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java Fri Jan  3 18:06:20 2014
@@ -52,16 +52,27 @@ public class SubLine extends AbstractSub
     /** Create a sub-line from two endpoints.
      * @param start start point
      * @param end end point
+     * @param tolerance tolerance below which points are considered identical
+     * @since 3.3
      */
-    public SubLine(final Vector2D start, final Vector2D end) {
-        super(new Line(start, end), buildIntervalSet(start, end));
+    public SubLine(final Vector2D start, final Vector2D end, final double tolerance) {
+        super(new Line(start, end, tolerance), buildIntervalSet(start, end, tolerance));
     }
 
+//  /** Create a sub-line from two endpoints.
+//  * @param start start point
+//  * @param end end point
+//  */
+// public SubLine(final Vector2D start, final Vector2D end) {
+//     super(new Line(start, end), buildIntervalSet(start, end));
+// }
+
     /** Create a sub-line from a segment.
      * @param segment single segment forming the sub-line
      */
     public SubLine(final Segment segment) {
-        super(segment.getLine(), buildIntervalSet(segment.getStart(), segment.getEnd()));
+        super(segment.getLine(),
+              buildIntervalSet(segment.getStart(), segment.getEnd(), segment.getLine().getTolerance()));
     }
 
     /** Get the endpoints of the sub-line.
@@ -137,12 +148,14 @@ public class SubLine extends AbstractSub
     /** Build an interval set from two points.
      * @param start start point
      * @param end end point
+     * @param tolerance tolerance below which points are considered identical
      * @return an interval set
      */
-    private static IntervalsSet buildIntervalSet(final Vector2D start, final Vector2D end) {
-        final Line line = new Line(start, end);
+    private static IntervalsSet buildIntervalSet(final Vector2D start, final Vector2D end, final double tolerance) {
+        final Line line = new Line(start, end, tolerance);
         return new IntervalsSet(line.toSubSpace((Point<Euclidean2D>) start).getX(),
-                                line.toSubSpace((Point<Euclidean2D>) end).getX());
+                                line.toSubSpace((Point<Euclidean2D>) end).getX(),
+                                tolerance);
     }
 
     /** {@inheritDoc} */
@@ -169,7 +182,7 @@ public class SubLine extends AbstractSub
         // the lines do intersect
         final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
         final Vector1D x = thisLine.toSubSpace((Point<Euclidean2D>) crossing);
-        return getRemainingRegion().side(new OrientedPoint(x, direct));
+        return getRemainingRegion().side(new OrientedPoint(x, direct, thisLine.getTolerance()));
 
     }
 
@@ -179,7 +192,8 @@ public class SubLine extends AbstractSub
 
         final Line    thisLine  = (Line) getHyperplane();
         final Line    otherLine = (Line) hyperplane;
-        final Vector2D crossing  = thisLine.intersection(otherLine);
+        final Vector2D crossing = thisLine.intersection(otherLine);
+        final double tolerance  = thisLine.getTolerance();
 
         if (crossing == null) {
             // the lines are parallel
@@ -192,8 +206,10 @@ public class SubLine extends AbstractSub
         // the lines do intersect
         final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
         final Vector1D x      = thisLine.toSubSpace((Point<Euclidean2D>) crossing);
-        final SubHyperplane<Euclidean1D> subPlus  = new OrientedPoint(x, !direct).wholeHyperplane();
-        final SubHyperplane<Euclidean1D> subMinus = new OrientedPoint(x,  direct).wholeHyperplane();
+        final SubHyperplane<Euclidean1D> subPlus  =
+                new OrientedPoint(x, !direct, tolerance).wholeHyperplane();
+        final SubHyperplane<Euclidean1D> subMinus =
+                new OrientedPoint(x,  direct, tolerance).wholeHyperplane();
 
         final BSPTree<Euclidean1D> splitTree = getRemainingRegion().getTree(false).split(subMinus);
         final BSPTree<Euclidean1D> plusTree  = getRemainingRegion().isEmpty(splitTree.getPlus()) ?
@@ -205,8 +221,8 @@ public class SubLine extends AbstractSub
                                                new BSPTree<Euclidean1D>(subMinus, new BSPTree<Euclidean1D>(Boolean.FALSE),
                                                                         splitTree.getMinus(), null);
 
-        return new SplitSubHyperplane<Euclidean2D>(new SubLine(thisLine.copySelf(), new IntervalsSet(plusTree)),
-                                                   new SubLine(thisLine.copySelf(), new IntervalsSet(minusTree)));
+        return new SplitSubHyperplane<Euclidean2D>(new SubLine(thisLine.copySelf(), new IntervalsSet(plusTree, tolerance)),
+                                                   new SubLine(thisLine.copySelf(), new IntervalsSet(minusTree, tolerance)));
 
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/AbstractRegion.java Fri Jan  3 18:06:20 2014
@@ -42,6 +42,9 @@ public abstract class AbstractRegion<S e
     /** Inside/Outside BSP tree. */
     private BSPTree<S> tree;
 
+    /** Tolerance below which points are considered to belong to hyperplanes. */
+    private final double tolerance;
+
     /** Size of the instance. */
     private double size;
 
@@ -49,9 +52,11 @@ public abstract class AbstractRegion<S e
     private Point<S> barycenter;
 
     /** Build a region representing the whole space.
+     * @param tolerance tolerance below which points are considered identical.
      */
-    protected AbstractRegion() {
-        tree = new BSPTree<S>(Boolean.TRUE);
+    protected AbstractRegion(final double tolerance) {
+        this.tree      = new BSPTree<S>(Boolean.TRUE);
+        this.tolerance = tolerance;
     }
 
     /** Build a region from an inside/outside BSP tree.
@@ -65,9 +70,11 @@ public abstract class AbstractRegion<S e
      * internal nodes representing the boundary as specified in the
      * {@link #getTree getTree} method).</p>
      * @param tree inside/outside BSP tree representing the region
+     * @param tolerance tolerance below which points are considered identical.
      */
-    protected AbstractRegion(final BSPTree<S> tree) {
-        this.tree = tree;
+    protected AbstractRegion(final BSPTree<S> tree, final double tolerance) {
+        this.tree      = tree;
+        this.tolerance = tolerance;
     }
 
     /** Build a Region from a Boundary REPresentation (B-rep).
@@ -88,8 +95,11 @@ public abstract class AbstractRegion<S e
      * space.</p>
      * @param boundary collection of boundary elements, as a
      * collection of {@link SubHyperplane SubHyperplane} objects
+     * @param tolerance tolerance below which points are considered identical.
      */
-    protected AbstractRegion(final Collection<SubHyperplane<S>> boundary) {
+    protected AbstractRegion(final Collection<SubHyperplane<S>> boundary, final double tolerance) {
+
+        this.tolerance = tolerance;
 
         if (boundary.size() == 0) {
 
@@ -143,8 +153,10 @@ public abstract class AbstractRegion<S e
     /** Build a convex region from an array of bounding hyperplanes.
      * @param hyperplanes array of bounding hyperplanes (if null, an
      * empty region will be built)
+     * @param tolerance tolerance below which points are considered identical.
      */
-    public AbstractRegion(final Hyperplane<S>[] hyperplanes) {
+    public AbstractRegion(final Hyperplane<S>[] hyperplanes, final double tolerance) {
+        this.tolerance = tolerance;
         if ((hyperplanes == null) || (hyperplanes.length == 0)) {
             tree = new BSPTree<S>(Boolean.FALSE);
         } else {
@@ -171,6 +183,13 @@ public abstract class AbstractRegion<S e
     /** {@inheritDoc} */
     public abstract AbstractRegion<S, T> buildNew(BSPTree<S> newTree);
 
+    /** Get the tolerance below which points are considered to belong to hyperplanes.
+     * @return tolerance below which points are considered to belong to hyperplanes
+     */
+    public double getTolerance() {
+        return tolerance;
+    }
+
     /** Recursively build a tree by inserting cut sub-hyperplanes.
      * @param node current tree node (it is a leaf node at the beginning
      * of the call)
@@ -291,7 +310,7 @@ public abstract class AbstractRegion<S e
      * OUTSIDE} or {@link Region.Location#BOUNDARY BOUNDARY}
      */
     protected Location checkPoint(final BSPTree<S> node, final Point<S> point) {
-        final BSPTree<S> cell = node.getCell(point);
+        final BSPTree<S> cell = node.getCell(point, tolerance);
         if (cell.getCut() == null) {
             // the point is in the interior of a cell, just check the attribute
             return ((Boolean) cell.getAttribute()) ? Location.INSIDE : Location.OUTSIDE;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java Fri Jan  3 18:06:20 2014
@@ -310,11 +310,11 @@ public class BSPTree<S extends Space> {
      * belongs to the node cut sub-hyperplane.</p>
      * @param point point to check
      * @return the tree cell to which the point belongs
-     * @deprecated as of 3.3, replaced with {@link #getCell(Point)}
+     * @deprecated as of 3.3, replaced with {@link #getCell(Point, double)}
      */
     @Deprecated
     public BSPTree<S> getCell(final Vector<S> point) {
-        return getCell((Point<S>) point);
+        return getCell((Point<S>) point, 1.0e-10);
     }
 
     /** Get the cell to which a point belongs.
@@ -322,9 +322,11 @@ public class BSPTree<S extends Space> {
      * interior of the node, if the cell is an internal node the points
      * belongs to the node cut sub-hyperplane.</p>
      * @param point point to check
+     * @param tolerance tolerance below which points close to a cut hyperplane
+     * are considered to belong to the hyperplane itself
      * @return the tree cell to which the point belongs
      */
-    public BSPTree<S> getCell(final Point<S> point) {
+    public BSPTree<S> getCell(final Point<S> point, final double tolerance) {
 
         if (cut == null) {
             return this;
@@ -333,14 +335,14 @@ public class BSPTree<S extends Space> {
         // position of the point with respect to the cut hyperplane
         final double offset = cut.getHyperplane().getOffset(point);
 
-        if (FastMath.abs(offset) < 1.0e-10) {
+        if (FastMath.abs(offset) < tolerance) {
             return this;
         } else if (offset <= 0) {
             // point is on the minus side of the cut hyperplane
-            return minus.getCell(point);
+            return minus.getCell(point, tolerance);
         } else {
             // point is on the plus side of the cut hyperplane
-            return plus.getCell(point);
+            return plus.getCell(point, tolerance);
         }
 
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/Hyperplane.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/Hyperplane.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/Hyperplane.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/Hyperplane.java Fri Jan  3 18:06:20 2014
@@ -55,6 +55,12 @@ public interface Hyperplane<S extends Sp
      */
     double getOffset(Point<S> point);
 
+    /** Get the tolerance below which points are considered to belong to the hyperplane.
+     * @return tolerance below which points are considered to belong to the hyperplane
+     * @since 3.3
+     */
+    double getTolerance();
+
     /** Check if the instance has the same orientation as another hyperplane.
      * <p>This method is expected to be called on parallel hyperplanes. The
      * method should <em>not</em> re-check for parallelism, only for

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/oned/ArcsSet.java Fri Jan  3 18:06:20 2014
@@ -46,14 +46,11 @@ import org.apache.commons.math3.util.Pre
  */
 public class ArcsSet extends AbstractRegion<Sphere1D, Sphere1D> implements Iterable<double[]> {
 
-    /** Tolerance below which close sub-arcs are merged together. */
-    private final double tolerance;
-
     /** Build an arcs set representing the whole circle.
      * @param tolerance tolerance below which close sub-arcs are merged together
      */
     public ArcsSet(final double tolerance) {
-        this.tolerance = tolerance;
+        super(tolerance);
     }
 
     /** Build an arcs set corresponding to a single arc.
@@ -71,8 +68,7 @@ public class ArcsSet extends AbstractReg
      */
     public ArcsSet(final double lower, final double upper, final double tolerance)
         throws NumberIsTooLargeException {
-        super(buildTree(lower, upper, tolerance));
-        this.tolerance = tolerance;
+        super(buildTree(lower, upper, tolerance), tolerance);
     }
 
     /** Build an arcs set from an inside/outside BSP tree.
@@ -86,8 +82,7 @@ public class ArcsSet extends AbstractReg
      * @param tolerance tolerance below which close sub-arcs are merged together
      */
     public ArcsSet(final BSPTree<Sphere1D> tree, final double tolerance) {
-        super(tree);
-        this.tolerance = tolerance;
+        super(tree, tolerance);
     }
 
     /** Build an arcs set from a Boundary REPresentation (B-rep).
@@ -111,8 +106,7 @@ public class ArcsSet extends AbstractReg
      * @param tolerance tolerance below which close sub-arcs are merged together
      */
     public ArcsSet(final Collection<SubHyperplane<Sphere1D>> boundary, final double tolerance) {
-        super(boundary);
-        this.tolerance = tolerance;
+        super(boundary, tolerance);
     }
 
     /** Build an inside/outside tree representing a single arc.
@@ -166,13 +160,6 @@ public class ArcsSet extends AbstractReg
 
     }
 
-    /** Get the tolerance below which angles are considered identical.
-     * @return tolerance below which angles are considered identical
-     */
-    public double getTolerance() {
-        return tolerance;
-    }
-
     /** Get the node corresponding to the first arc start.
      * @return smallest internal node (i.e. first after 0.0 radians, in trigonometric direction),
      * or null if there are no internal nodes (i.e. the set is either empty or covers the full circle)
@@ -390,7 +377,7 @@ public class ArcsSet extends AbstractReg
      * @return sub-hyperplane for start of arc
      */
     private SubLimitAngle arcStart(final double alpha) {
-        return new LimitAngle(new S1Point(alpha), false, tolerance).wholeHyperplane();
+        return new LimitAngle(new S1Point(alpha), false, getTolerance()).wholeHyperplane();
     }
 
     /** Build a sub-hyperplane corresponding to an arc end.
@@ -398,13 +385,13 @@ public class ArcsSet extends AbstractReg
      * @return sub-hyperplane for end of arc
      */
     private SubLimitAngle arcEnd(final double alpha) {
-        return new LimitAngle(new S1Point(alpha), true, tolerance).wholeHyperplane();
+        return new LimitAngle(new S1Point(alpha), true, getTolerance()).wholeHyperplane();
     }
 
     /** {@inheritDoc} */
     @Override
     public ArcsSet buildNew(final BSPTree<Sphere1D> tree) {
-        return new ArcsSet(tree, tolerance);
+        return new ArcsSet(tree, getTolerance());
     }
 
     /** {@inheritDoc} */
@@ -443,7 +430,7 @@ public class ArcsSet extends AbstractReg
     public List<Arc> asList() {
         final List<Arc> list = new ArrayList<Arc>();
         for (final double[] a : this) {
-            list.add(new Arc(a[0], a[1], tolerance));
+            list.add(new Arc(a[0], a[1], getTolerance()));
         }
         return list;
     }
@@ -693,8 +680,8 @@ public class ArcsSet extends AbstractReg
             }
         }
 
-        return new Split(plus.isEmpty()  ? null : new ArcsSet(plus, tolerance),
-                         minus.isEmpty() ? null : new ArcsSet(minus,tolerance));
+        return new Split(plus.isEmpty()  ? null : new ArcsSet(plus, getTolerance()),
+                         minus.isEmpty() ? null : new ArcsSet(minus,getTolerance()));
 
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java?rev=1555174&r1=1555173&r2=1555174&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java Fri Jan  3 18:06:20 2014
@@ -42,9 +42,6 @@ import org.apache.commons.math3.util.Mat
  */
 public class SphericalPolygonsSet extends AbstractRegion<Sphere2D, Sphere1D> {
 
-    /** Tolerance below which points are consider to be identical. */
-    private final double tolerance;
-
     /** Boundary defined as an array of closed loops start vertices. */
     private List<Vertex> loops;
 
@@ -52,7 +49,19 @@ public class SphericalPolygonsSet extend
      * @param tolerance below which points are consider to be identical
      */
     public SphericalPolygonsSet(final double tolerance) {
-        this.tolerance = tolerance;
+        super(tolerance);
+    }
+
+    /** Build a polygons set representing a hemisphere.
+     * @param pole pole of the hemisphere (the pole is in the inside half)
+     * @param tolerance below which points are consider to be identical
+     */
+    public SphericalPolygonsSet(final Vector3D pole, final double tolerance) {
+        super(new BSPTree<Sphere2D>(new Circle(pole, tolerance).wholeHyperplane(),
+                                    new BSPTree<Sphere2D>(Boolean.FALSE),
+                                    new BSPTree<Sphere2D>(Boolean.TRUE),
+                                    null),
+              tolerance);
     }
 
     /** Build a polygons set from a BSP tree.
@@ -66,8 +75,7 @@ public class SphericalPolygonsSet extend
      * @param tolerance below which points are consider to be identical
      */
     public SphericalPolygonsSet(final BSPTree<Sphere2D> tree, final double tolerance) {
-        super(tree);
-        this.tolerance = tolerance;
+        super(tree, tolerance);
     }
 
     /** Build a polygons set from a Boundary REPresentation (B-rep).
@@ -92,8 +100,7 @@ public class SphericalPolygonsSet extend
      * @param tolerance below which points are consider to be identical
      */
     public SphericalPolygonsSet(final Collection<SubHyperplane<Sphere2D>> boundary, final double tolerance) {
-        super(boundary);
-        this.tolerance = tolerance;
+        super(boundary, tolerance);
     }
 
     /** Build a polygon from a simple list of vertices.
@@ -127,8 +134,7 @@ public class SphericalPolygonsSet extend
      * @param vertices vertices of the simple loop boundary
      */
     public SphericalPolygonsSet(final double hyperplaneThickness, final S2Point ... vertices) {
-        super(verticesToTree(hyperplaneThickness, vertices));
-        this.tolerance = hyperplaneThickness;
+        super(verticesToTree(hyperplaneThickness, vertices), hyperplaneThickness);
     }
 
     /** Build the BSP tree of a polygons set from a simple list of vertices.
@@ -575,7 +581,7 @@ public class SphericalPolygonsSet extend
     /** {@inheritDoc} */
     @Override
     public SphericalPolygonsSet buildNew(final BSPTree<Sphere2D> tree) {
-        return new SphericalPolygonsSet(tree, tolerance);
+        return new SphericalPolygonsSet(tree, getTolerance());
     }
 
     /** {@inheritDoc}
@@ -675,7 +681,7 @@ public class SphericalPolygonsSet extend
 
                 // sort the arcs according to their start point
                 final BSPTree<Sphere2D> root = getTree(true);
-                final EdgesBuilder visitor = new EdgesBuilder(root, tolerance);
+                final EdgesBuilder visitor = new EdgesBuilder(root, getTolerance());
                 root.visit(visitor);
                 final List<Edge> edges = visitor.getEdges();
 



Mime
View raw message