You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2011/06/03 20:08:13 UTC

svn commit: r1131127 [1/3] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/geometry/euclidean/oned/ main/java/org/apache/commons/math/geometry/euclidean/threed/ main/java/org/apache/commons/math/geometry/euclidean/twod/ test/java...

Author: luc
Date: Fri Jun  3 18:08:12 2011
New Revision: 1131127

URL: http://svn.apache.org/viewvc?rev=1131127&view=rev
Log:
use the reorganized Binary Space Partitioning framework for Euclidean spaces 1D, 2D and 3D.

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java   (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java   (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java   (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/Interval.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/OrientedPoint.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Line.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/OutlineExtractor.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Plane.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Line.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSetTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/Interval.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/Interval.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/Interval.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/Interval.java Fri Jun  3 18:08:12 2011
@@ -19,7 +19,8 @@ package org.apache.commons.math.geometry
 
 /** This class represents a 1D interval.
  * @see IntervalsSet
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
 public class Interval {
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSet.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSet.java Fri Jun  3 18:08:12 2011
@@ -20,14 +20,16 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.commons.math.geometry.partitioning.AbstractRegion;
 import org.apache.commons.math.geometry.partitioning.BSPTree;
 import org.apache.commons.math.geometry.partitioning.Region;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
 
 /** This class represents a 1D region: a set of intervals.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class IntervalsSet extends Region {
+public class IntervalsSet extends AbstractRegion<Euclidean1D, Euclidean1D> {
 
     /** Build an intervals set representing the whole real line.
      */
@@ -54,7 +56,7 @@ public class IntervalsSet extends Region
      * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
      * @param tree inside/outside BSP tree representing the intervals set
      */
-    public IntervalsSet(final BSPTree tree) {
+    public IntervalsSet(final BSPTree<Euclidean1D> tree) {
         super(tree);
     }
 
@@ -77,7 +79,7 @@ public class IntervalsSet extends Region
      * space.</p>
      * @param boundary collection of boundary elements
      */
-    public IntervalsSet(final Collection<SubHyperplane> boundary) {
+    public IntervalsSet(final Collection<SubHyperplane<Euclidean1D>> boundary) {
         super(boundary);
     }
 
@@ -88,52 +90,52 @@ public class IntervalsSet extends Region
      * to {@code lower} (may be {@code Double.POSITIVE_INFINITY})
      * @return the built tree
      */
-    private static BSPTree buildTree(final double lower, final double upper) {
+    private static BSPTree<Euclidean1D> buildTree(final double lower, final double upper) {
         if (Double.isInfinite(lower) && (lower < 0)) {
             if (Double.isInfinite(upper) && (upper > 0)) {
                 // the tree must cover the whole real line
-                return new BSPTree(Boolean.TRUE);
+                return new BSPTree<Euclidean1D>(Boolean.TRUE);
             }
             // the tree must be open on the negative infinity side
-            final SubHyperplane upperCut =
-                new SubHyperplane(new OrientedPoint(new Point1D(upper), true));
-            return new BSPTree(upperCut,
-                               new BSPTree(Boolean.FALSE),
-                               new BSPTree(Boolean.TRUE),
+            final SubHyperplane<Euclidean1D> upperCut =
+                new OrientedPoint(new Vector1D(upper), true).wholeHyperplane();
+            return new BSPTree<Euclidean1D>(upperCut,
+                               new BSPTree<Euclidean1D>(Boolean.FALSE),
+                               new BSPTree<Euclidean1D>(Boolean.TRUE),
                                null);
         }
-        final SubHyperplane lowerCut =
-            new SubHyperplane(new OrientedPoint(new Point1D(lower), false));
+        final SubHyperplane<Euclidean1D> lowerCut =
+            new OrientedPoint(new Vector1D(lower), false).wholeHyperplane();
         if (Double.isInfinite(upper) && (upper > 0)) {
             // the tree must be open on the positive infinity side
-            return new BSPTree(lowerCut,
-                               new BSPTree(Boolean.FALSE),
-                               new BSPTree(Boolean.TRUE),
+            return new BSPTree<Euclidean1D>(lowerCut,
+                               new BSPTree<Euclidean1D>(Boolean.FALSE),
+                               new BSPTree<Euclidean1D>(Boolean.TRUE),
                                null);
         }
 
         // the tree must be bounded on the two sides
-        final SubHyperplane upperCut =
-            new SubHyperplane(new OrientedPoint(new Point1D(upper), true));
-        return new BSPTree(lowerCut,
-                           new BSPTree(Boolean.FALSE),
-                           new BSPTree(upperCut,
-                                       new BSPTree(Boolean.FALSE),
-                                       new BSPTree(Boolean.TRUE),
+        final SubHyperplane<Euclidean1D> upperCut =
+            new OrientedPoint(new Vector1D(upper), true).wholeHyperplane();
+        return new BSPTree<Euclidean1D>(lowerCut,
+                           new BSPTree<Euclidean1D>(Boolean.FALSE),
+                           new BSPTree<Euclidean1D>(upperCut,
+                                       new BSPTree<Euclidean1D>(Boolean.FALSE),
+                                       new BSPTree<Euclidean1D>(Boolean.TRUE),
                                        null),
                                        null);
 
     }
 
     /** {@inheritDoc} */
-    public Region buildNew(final BSPTree tree) {
+    public IntervalsSet buildNew(final BSPTree<Euclidean1D> tree) {
         return new IntervalsSet(tree);
     }
 
     /** {@inheritDoc} */
     protected void computeGeometricalProperties() {
         if (getTree(false).getCut() == null) {
-            setBarycenter(Point1D.UNDEFINED);
+            setBarycenter(Vector1D.NaN);
             setSize(((Boolean) getTree(false).getAttribute()) ? Double.POSITIVE_INFINITY : 0);
         } else {
             double size = 0.0;
@@ -143,7 +145,7 @@ public class IntervalsSet extends Region
                 sum  += interval.getLength() * interval.getMidPoint();
             }
             setSize(size);
-            setBarycenter(Double.isInfinite(size) ? Point1D.UNDEFINED : new Point1D(sum / size));
+            setBarycenter(Double.isInfinite(size) ? Vector1D.NaN : new Vector1D(sum / size));
         }
     }
 
@@ -154,11 +156,11 @@ public class IntervalsSet extends Region
      * instance is empty)
      */
     public double getInf() {
-        BSPTree node = getTree(false);
+        BSPTree<Euclidean1D> node = getTree(false);
         double  inf  = Double.POSITIVE_INFINITY;
         while (node.getCut() != null) {
             final OrientedPoint op = (OrientedPoint) node.getCut().getHyperplane();
-            inf  = op.getLocation().getAbscissa();
+            inf  = op.getLocation().getX();
             node = op.isDirect() ? node.getMinus() : node.getPlus();
         }
         return ((Boolean) node.getAttribute()) ? Double.NEGATIVE_INFINITY : inf;
@@ -171,11 +173,11 @@ public class IntervalsSet extends Region
      * instance is empty)
      */
     public double getSup() {
-        BSPTree node = getTree(false);
+        BSPTree<Euclidean1D> node = getTree(false);
         double  sup  = Double.NEGATIVE_INFINITY;
         while (node.getCut() != null) {
             final OrientedPoint op = (OrientedPoint) node.getCut().getHyperplane();
-            sup  = op.getLocation().getAbscissa();
+            sup  = op.getLocation().getX();
             node = op.isDirect() ? node.getPlus() : node.getMinus();
         }
         return ((Boolean) node.getAttribute()) ? Double.POSITIVE_INFINITY : sup;
@@ -207,7 +209,8 @@ public class IntervalsSet extends Region
      * @param lower lower bound of the current convex cell
      * @param upper upper bound of the current convex cell
      */
-    private void recurseList(final BSPTree node, final List<Interval> list,
+    private void recurseList(final BSPTree<Euclidean1D> node,
+                             final List<Interval> list,
                              final double lower, final double upper) {
 
         if (node.getCut() == null) {
@@ -217,12 +220,14 @@ public class IntervalsSet extends Region
             }
         } else {
             final OrientedPoint op  = (OrientedPoint) node.getCut().getHyperplane();
-            final Point1D       loc = op.getLocation();
-            double        x   = loc.getAbscissa();
+            final Vector1D       loc = op.getLocation();
+            double              x   = loc.getX();
 
             // make sure we explore the tree in increasing order
-            final BSPTree low       = op.isDirect() ? node.getMinus() : node.getPlus();
-            final BSPTree high      = op.isDirect() ? node.getPlus()  : node.getMinus();
+            final BSPTree<Euclidean1D> low  =
+                op.isDirect() ? node.getMinus() : node.getPlus();
+            final BSPTree<Euclidean1D> high =
+                op.isDirect() ? node.getPlus()  : node.getMinus();
 
             recurseList(low, list, lower, x);
             if ((checkPoint(low,  loc) == Location.INSIDE) &&

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/OrientedPoint.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/OrientedPoint.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/OrientedPoint.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/OrientedPoint.java Fri Jun  3 18:08:12 2011
@@ -16,28 +16,22 @@
  */
 package org.apache.commons.math.geometry.euclidean.oned;
 
-import org.apache.commons.math.exception.MathUnsupportedOperationException;
-import org.apache.commons.math.exception.util.LocalizedFormats;
-import org.apache.commons.math.geometry.partitioning.BSPTree;
+import org.apache.commons.math.geometry.Vector;
 import org.apache.commons.math.geometry.partitioning.Hyperplane;
-import org.apache.commons.math.geometry.partitioning.Point;
 import org.apache.commons.math.geometry.partitioning.Region;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
-import org.apache.commons.math.geometry.partitioning.SubSpace;
 
 /** This class represents a 1D oriented hyperplane.
  * <p>An hyperplane in 1D is a simple point, its orientation being a
  * boolean.</p>
  * <p>Instances of this class are guaranteed to be immutable.</p>
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class OrientedPoint implements Hyperplane {
+public class OrientedPoint implements Hyperplane<Euclidean1D> {
 
-    /** Dummy region returned by the {@link #wholeHyperplane} method. */
-    private static final Region DUMMY_REGION = new DummyRegion();
-
-    /** Point location. */
-    private Point1D location;
+    /** Vector location. */
+    private Vector1D location;
 
     /** Orientation. */
     private boolean direct;
@@ -45,9 +39,9 @@ public class OrientedPoint implements Hy
     /** Simple constructor.
      * @param location location of the hyperplane
      * @param direct if true, the plus side of the hyperplane is towards
-     * abscissae greater than {@code location}
+     * abscissas greater than {@code location}
      */
-    public OrientedPoint(final Point1D location, final boolean direct) {
+    public OrientedPoint(final Vector1D location, final boolean direct) {
         this.location = location;
         this.direct   = direct;
     }
@@ -57,62 +51,16 @@ public class OrientedPoint implements Hy
      * the instance.</p>
      * @return the instance itself
      */
-    public Hyperplane copySelf() {
+    public OrientedPoint copySelf() {
         return this;
     }
 
-    /** Get the offset (oriented distance) of a point to the hyperplane.
-     * @param point point to check
-     * @return offset of the point
-     */
-    public double getOffset(final Point point) {
-        final double delta = ((Point1D) point).getAbscissa() - location.getAbscissa();
+    /** {@inheritDoc} */
+    public double getOffset(final Vector<Euclidean1D> point) {
+        final double delta = ((Vector1D) point).getX() - location.getX();
         return direct ? delta : -delta;
     }
 
-    /** Transform a space point into a sub-space point.
-     * <p>Since this class represent zero dimension spaces which does
-     * not have lower dimension sub-spaces, this method cannot be
-     * supported here. It always throws a {@code RuntimeException}
-     * when called.</p>
-     * @param point n-dimension point of the space
-     * @return (n-1)-dimension point of the sub-space corresponding to
-     * the specified space point
-     * @see #toSpace
-     */
-    public Point toSubSpace(final Point point) {
-        throw new MathUnsupportedOperationException(LocalizedFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1);
-    }
-
-    /** Transform a sub-space point into a space point.
-     * <p>Since this class represent zero dimension spaces which does
-     * not have lower dimension sub-spaces, this method cannot be
-     * supported here. It always throws a {@code RuntimeException}
-     * when called.</p>
-     * @param point (n-1)-dimension point of the sub-space
-     * @return n-dimension point of the space corresponding to the
-     * specified sub-space point
-     * @see #toSubSpace
-     */
-    public Point toSpace(final Point point) {
-        throw new MathUnsupportedOperationException(LocalizedFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1);
-    }
-
-    /** Build the sub-space shared by the instance and another hyperplane.
-     * <p>Since this class represent zero dimension spaces which does
-     * not have lower dimension sub-spaces, this method cannot be
-     * supported here. It always throws a {@code RuntimeException}
-     * when called.</p>
-     * @param other other sub-space (must have the same dimension as the
-     * instance)
-     * @return a sub-space at the intersection of the instance and the
-     * other sub-space (it has a dimension one unit less than the
-     * instance)
-     */
-    public SubSpace intersection(final Hyperplane other) {
-        throw new MathUnsupportedOperationException(LocalizedFormats.NOT_SUPPORTED_IN_DIMENSION_N, 1);
-    }
-
     /** Build a region covering the whole hyperplane.
      * <p>Since this class represent zero dimension spaces which does
      * not have lower dimension sub-spaces, this method returns a dummy
@@ -122,15 +70,15 @@ public class OrientedPoint implements Hy
      * properly, it should <em>not</em> be used otherwise.</p>
      * @return a dummy region
      */
-    public Region wholeHyperplane() {
-        return DUMMY_REGION;
+    public SubOrientedPoint wholeHyperplane() {
+        return new SubOrientedPoint(this, null);
     }
 
     /** Build a region covering the whole space.
      * @return a region containing the instance (really an {@link
      * IntervalsSet IntervalsSet} instance)
      */
-    public Region wholeSpace() {
+    public IntervalsSet wholeSpace() {
         return new IntervalsSet();
     }
 
@@ -147,40 +95,14 @@ public class OrientedPoint implements Hy
      * @return true if the instance and the other hyperplane have
      * the same orientation
      */
-    public boolean sameOrientationAs(final Hyperplane other) {
+    public boolean sameOrientationAs(final Hyperplane<Euclidean1D> other) {
         return !(direct ^ ((OrientedPoint) other).direct);
     }
 
-    /** Compute the relative position of a sub-hyperplane with respect
-     * to the instance.
-     * @param sub sub-hyperplane to check
-     * @return one of {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#PLUS PLUS},
-     * {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#MINUS MINUS}
-     * or {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#HYPER HYPER}
-     * (in dimension 1, this method <em>never</em> returns {@link
-     * org.apache.commons.math.geometry.partitioning.Hyperplane.Side#BOTH BOTH})
-     *
-     */
-    public Side side(final SubHyperplane sub) {
-        final double global = getOffset(((OrientedPoint) sub.getHyperplane()).location);
-        return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
-    }
-
-    /** Split a sub-hyperplane in two parts by the instance.
-     * @param sub sub-hyperplane to split
-     * @return an object containing both the part of the sub-hyperplane
-     * on the plus side of the instance and the part of the
-     * sub-hyperplane on the minus side of the instance
-     */
-    public SplitSubHyperplane split(final SubHyperplane sub) {
-        final double global = getOffset(((OrientedPoint) sub.getHyperplane()).location);
-        return (global < -1.0e-10) ? new SplitSubHyperplane(null, sub) : new SplitSubHyperplane(sub, null);
-    }
-
     /** Get the hyperplane location on the real line.
      * @return the hyperplane location
      */
-    public Point1D getLocation() {
+    public Vector1D getLocation() {
         return location;
     }
 
@@ -198,25 +120,4 @@ public class OrientedPoint implements Hy
         direct = !direct;
     }
 
-    /** Dummy region representing the whole set of reals. */
-    private static class DummyRegion extends Region {
-
-        /** Simple constructor.
-         */
-        public DummyRegion() {
-            super();
-        }
-
-        /** {@inheritDoc} */
-        public Region buildNew(final BSPTree tree) {
-            return this;
-        }
-
-        /** {@inheritDoc} */
-        protected void computeGeometricalProperties() {
-            setSize(0);
-            setBarycenter(Point1D.ZERO);
-        }
-    }
-
 }

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java?rev=1131127&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java Fri Jun  3 18:08:12 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.geometry.euclidean.oned;
+
+import org.apache.commons.math.geometry.partitioning.AbstractSubHyperplane;
+import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.Side;
+
+/** This class represents sub-hyperplane for {@link OrOrientedPoint}.
+ * <p>An hyperplane in 1D is a simple point, its orientation being a
+ * boolean.</p>
+ * <p>Instances of this class are guaranteed to be immutable.</p>
+ * @version $Id:$
+ * @since 3.0
+ */
+public class SubOrientedPoint extends AbstractSubHyperplane<Euclidean1D, Euclidean1D> {
+
+    /** Simple constructor.
+     * @param hyperplane underlying hyperplane
+     * @param remainingRegion remaining region of the hyperplane
+     */
+    public SubOrientedPoint(final Hyperplane<Euclidean1D> hyperplane,
+                            final Region<Euclidean1D> remainingRegion) {
+        super(hyperplane, remainingRegion);
+    }
+
+    /** {@inheritDoc} */
+    public double getSize() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    protected AbstractSubHyperplane<Euclidean1D, Euclidean1D> buildNew(final Hyperplane<Euclidean1D> hyperplane,
+                                                                       final Region<Euclidean1D> remainingRegion) {
+        return new SubOrientedPoint(hyperplane, remainingRegion);
+    }
+
+    /** {@inheritDoc} */
+    public Side side(final Hyperplane<Euclidean1D> hyperplane) {
+        final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
+        return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
+    }
+
+    /** {@inheritDoc} */
+    public SplitSubHyperplane<Euclidean1D> split(final Hyperplane<Euclidean1D> hyperplane) {
+        final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
+        return (global < -1.0e-10) ?
+                                    new SplitSubHyperplane<Euclidean1D>(null, this) :
+                                        new SplitSubHyperplane<Euclidean1D>(this, null);
+    }
+
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/oned/SubOrientedPoint.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Line.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Line.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Line.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Line.java Fri Jun  3 18:08:12 2011
@@ -16,9 +16,10 @@
  */
 package org.apache.commons.math.geometry.euclidean.threed;
 
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
-import org.apache.commons.math.geometry.partitioning.Point;
-import org.apache.commons.math.geometry.partitioning.SubSpace;
+import org.apache.commons.math.geometry.Vector;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math.geometry.partitioning.Embedding;
 import org.apache.commons.math.util.FastMath;
 
 /** The class represent lines in a three dimensional space.
@@ -30,15 +31,16 @@ import org.apache.commons.math.util.Fast
  * which is closest to the origin. Abscissa increases in the line
  * direction.</p>
 
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class Line implements SubSpace {
+public class Line implements Embedding<Euclidean3D, Euclidean1D> {
 
     /** Line direction. */
     private Vector3D direction;
 
     /** Line point closest to the origin. */
-    private Point3D zero;
+    private Vector3D zero;
 
     /** Build a line from a point and a direction.
      * @param p point belonging to the line (this can be any point)
@@ -60,13 +62,14 @@ public class Line implements SubSpace {
             throw new IllegalArgumentException("null norm");
         }
         this.direction = new Vector3D(1.0 / norm, dir);
-        zero = new Point3D(1.0, p, -Vector3D.dotProduct(p, this.direction), this.direction);
+        zero = new Vector3D(1.0, p, -Vector3D.dotProduct(p, this.direction), this.direction);
     }
 
-    /** Revert the line direction.
+    /** Get a line with reversed direction.
+     * @return a new instance, with reversed direction
      */
-    public void revertSelf() {
-        direction = direction.negate();
+    public Line revert() {
+        return new Line(zero, direction.negate());
     }
 
     /** Get the normalized direction vector.
@@ -90,21 +93,22 @@ public class Line implements SubSpace {
      * @param point point to check (must be a {@link Vector3D Vector3D}
      * instance)
      * @return abscissa of the point (really a
-     * {org.apache.commons.math.geometry.euclidean.oned.Point1D Point1D} instance)
+     * {org.apache.commons.math.geometry.euclidean.oned.Vector1D Vector1D} instance)
      */
-    public Point toSubSpace(final Point point) {
-        final double x = Vector3D.dotProduct(((Vector3D) point).subtract(zero), direction);
-        return new Point1D(x);
+    public Vector1D toSubSpace(final Vector<Euclidean3D> point) {
+        Vector3D p3 = (Vector3D) point;
+        return new Vector1D(Vector3D.dotProduct(p3.subtract(zero), direction));
     }
 
     /** Get one point from the line.
      * @param point desired abscissa for the point (must be a
-     * {org.apache.commons.math.geometry.euclidean.oned.Point1D Point1D} instance)
+     * {org.apache.commons.math.geometry.euclidean.oned.Vector1D Vector1D} instance)
      * @return one point belonging to the line, at specified abscissa
      * (really a {@link Vector3D Vector3D} instance)
      */
-    public Point toSpace(final Point point) {
-        return new Point3D(1.0, zero, ((Point1D) point).getAbscissa(), direction);
+    public Vector3D toSpace(final Vector<Euclidean1D> point) {
+        Vector1D p1 = (Vector1D) point;
+        return new Vector3D(1.0, zero, p1.getX(), direction);
     }
 
     /** Check if the instance is similar to another line.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/OutlineExtractor.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/OutlineExtractor.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/OutlineExtractor.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/OutlineExtractor.java Fri Jun  3 18:08:12 2011
@@ -16,20 +16,24 @@
  */
 package org.apache.commons.math.geometry.euclidean.threed;
 
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
+import java.util.ArrayList;
+
+import org.apache.commons.math.geometry.euclidean.twod.Euclidean2D;
 import org.apache.commons.math.geometry.euclidean.twod.PolygonsSet;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math.geometry.partitioning.AbstractSubHyperplane;
 import org.apache.commons.math.geometry.partitioning.BSPTree;
 import org.apache.commons.math.geometry.partitioning.BSPTreeVisitor;
-import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.BoundaryAttribute;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
 import org.apache.commons.math.util.FastMath;
 
-import java.util.ArrayList;
-
 /** Extractor for {@link PolygonsSet polyhedrons sets} outlines.
  * <p>This class extracts the 2D outlines from {{@link PolygonsSet
  * polyhedrons sets} in a specified projection plane.</p>
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
 public class OutlineExtractor {
 
@@ -56,7 +60,7 @@ public class OutlineExtractor {
      * @param polyhedronsSet polyhedrons set whose outline must be extracted
      * @return an outline, as an array of loops.
      */
-    public Point2D[][] getOutline(final PolyhedronsSet polyhedronsSet) {
+    public Vector2D[][] getOutline(final PolyhedronsSet polyhedronsSet) {
 
         // project all boundary facets into one polygons set
         final BoundaryProjector projector = new BoundaryProjector();
@@ -64,9 +68,9 @@ public class OutlineExtractor {
         final PolygonsSet projected = projector.getProjected();
 
         // Remove the spurious intermediate vertices from the outline
-        final Point2D[][] outline = projected.getVertices();
+        final Vector2D[][] outline = projected.getVertices();
         for (int i = 0; i < outline.length; ++i) {
-            final Point2D[] rawLoop = outline[i];
+            final Vector2D[] rawLoop = outline[i];
             int end = rawLoop.length;
             int j = 0;
             while (j < end) {
@@ -83,7 +87,7 @@ public class OutlineExtractor {
             }
             if (end != rawLoop.length) {
                 // resize the array
-                outline[i] = new Point2D[end];
+                outline[i] = new Vector2D[end];
                 System.arraycopy(rawLoop, 0, outline[i], 0, end);
             }
         }
@@ -100,14 +104,14 @@ public class OutlineExtractor {
      * @param i index of the point to check (must be between 0 and n-1)
      * @return true if the point is exactly between its neighbours
      */
-    private boolean pointIsBetween(final Point2D[] loop, final int n, final int i) {
-        final Point2D previous = loop[(i + n - 1) % n];
-        final Point2D current  = loop[i];
-        final Point2D next     = loop[(i + 1) % n];
-        final double dx1       = current.x - previous.x;
-        final double dy1       = current.y - previous.y;
-        final double dx2       = next.x    - current.x;
-        final double dy2       = next.y    - current.y;
+    private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i) {
+        final Vector2D previous = loop[(i + n - 1) % n];
+        final Vector2D current  = loop[i];
+        final Vector2D next     = loop[(i + 1) % n];
+        final double dx1       = current.getX() - previous.getX();
+        final double dy1       = current.getY() - previous.getY();
+        final double dx2       = next.getX()    - current.getX();
+        final double dy2       = next.getY()    - current.getY();
         final double cross     = dx1 * dy2 - dx2 * dy1;
         final double dot       = dx1 * dx2 + dy1 * dy2;
         final double d1d2      = FastMath.sqrt((dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2));
@@ -115,7 +119,7 @@ public class OutlineExtractor {
     }
 
     /** Visitor projecting the boundary facets on a plane. */
-    private class BoundaryProjector implements BSPTreeVisitor {
+    private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D> {
 
         /** Projection of the polyhedrons set on the plane. */
         private PolygonsSet projected;
@@ -123,18 +127,19 @@ public class OutlineExtractor {
         /** Simple constructor.
          */
         public BoundaryProjector() {
-            projected = new PolygonsSet(new BSPTree(Boolean.FALSE));
+            projected = new PolygonsSet(new BSPTree<Euclidean2D>(Boolean.FALSE));
         }
 
         /** {@inheritDoc} */
-        public Order visitOrder(final BSPTree node) {
+        public Order visitOrder(final BSPTree<Euclidean3D> node) {
             return Order.MINUS_SUB_PLUS;
         }
 
         /** {@inheritDoc} */
-        public void visitInternalNode(final BSPTree node) {
-            final Region.BoundaryAttribute attribute =
-                (Region.BoundaryAttribute) node.getAttribute();
+        public void visitInternalNode(final BSPTree<Euclidean3D> node) {
+            @SuppressWarnings("unchecked")
+            final BoundaryAttribute<Euclidean3D> attribute =
+                (BoundaryAttribute<Euclidean3D>) node.getAttribute();
             if (attribute.getPlusOutside() != null) {
                 addContribution(attribute.getPlusOutside(), false);
             }
@@ -144,19 +149,22 @@ public class OutlineExtractor {
         }
 
         /** {@inheritDoc} */
-        public void visitLeafNode(final BSPTree node) {
+        public void visitLeafNode(final BSPTree<Euclidean3D> node) {
         }
 
         /** Add he contribution of a boundary facet.
          * @param facet boundary facet
          * @param reversed if true, the facet has the inside on its plus side
          */
-        private void addContribution(final SubHyperplane facet, final boolean reversed) {
+        private void addContribution(final SubHyperplane<Euclidean3D> facet, final boolean reversed) {
 
             // extract the vertices of the facet
+            @SuppressWarnings("unchecked")
+            final AbstractSubHyperplane<Euclidean3D, Euclidean2D> absFacet =
+                (AbstractSubHyperplane<Euclidean3D, Euclidean2D>) facet;
             final Plane plane    = (Plane) facet.getHyperplane();
-            Point2D[][] vertices =
-                ((PolygonsSet) facet.getRemainingRegion()).getVertices();
+            Vector2D[][] vertices =
+                ((PolygonsSet) absFacet.getRemainingRegion()).getVertices();
 
             final double scal = Vector3D.dotProduct(plane.getNormal(), w);
             if (FastMath.abs(scal) > 1.0e-3) {
@@ -164,10 +172,10 @@ public class OutlineExtractor {
                 if ((scal < 0) ^ reversed) {
                     // the facet is seen from the inside,
                     // we need to invert its boundary orientation
-                    final Point2D[][] newVertices = new Point2D[vertices.length][];
+                    final Vector2D[][] newVertices = new Vector2D[vertices.length][];
                     for (int i = 0; i < vertices.length; ++i) {
-                        final Point2D[] loop = vertices[i];
-                        final Point2D[] newLoop = new Point2D[loop.length];
+                        final Vector2D[] loop = vertices[i];
+                        final Vector2D[] newLoop = new Vector2D[loop.length];
                         if (loop[0] == null) {
                             newLoop[0] = null;
                             for (int j = 1; j < loop.length; ++j) {
@@ -187,22 +195,22 @@ public class OutlineExtractor {
                 }
 
                 // compute the projection of the facet in the outline plane
-                final ArrayList<SubHyperplane> edges = new ArrayList<SubHyperplane>();
-                for (Point2D[] loop : vertices) {
+                final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
+                for (Vector2D[] loop : vertices) {
                     final boolean closed = loop[0] != null;
                     int previous         = closed ? (loop.length - 1) : 1;
                     Vector3D previous3D  = (Vector3D) plane.toSpace(loop[previous]);
                     int current          = (previous + 1) % loop.length;
-                    Point2D pPoint       = new Point2D(Vector3D.dotProduct(previous3D, u),
+                    Vector2D pPoint       = new Vector2D(Vector3D.dotProduct(previous3D, u),
                                                        Vector3D.dotProduct(previous3D, v));
                     while (current < loop.length) {
 
                         final Vector3D current3D = (Vector3D) plane.toSpace(loop[current]);
-                        final Point2D  cPoint    = new Point2D(Vector3D.dotProduct(current3D, u),
+                        final Vector2D  cPoint    = new Vector2D(Vector3D.dotProduct(current3D, u),
                                                                Vector3D.dotProduct(current3D, v));
                         final org.apache.commons.math.geometry.euclidean.twod.Line line =
                             new org.apache.commons.math.geometry.euclidean.twod.Line(pPoint, cPoint);
-                        SubHyperplane edge = new SubHyperplane(line);
+                        SubHyperplane<Euclidean2D> edge = line.wholeHyperplane();
 
                         if (closed || (previous != 1)) {
                             // the previous point is a real vertex
@@ -210,7 +218,7 @@ public class OutlineExtractor {
                             final double angle = line.getAngle() + 0.5 * FastMath.PI;
                             final org.apache.commons.math.geometry.euclidean.twod.Line l =
                                 new org.apache.commons.math.geometry.euclidean.twod.Line(pPoint, angle);
-                            edge = l.split(edge).getPlus();
+                            edge = edge.split(l).getPlus();
                         }
 
                         if (closed || (current != (loop.length - 1))) {
@@ -219,7 +227,7 @@ public class OutlineExtractor {
                             final double angle = line.getAngle() + 0.5 * FastMath.PI;
                             final org.apache.commons.math.geometry.euclidean.twod.Line l =
                                 new org.apache.commons.math.geometry.euclidean.twod.Line(cPoint, angle);
-                            edge = l.split(edge).getMinus();
+                            edge = edge.split(l).getMinus();
                         }
 
                         edges.add(edge);
@@ -233,7 +241,7 @@ public class OutlineExtractor {
                 final PolygonsSet projectedFacet = new PolygonsSet(edges);
 
                 // add the contribution of the facet to the global outline
-                projected = (PolygonsSet) Region.union(projected, projectedFacet);
+                projected = (PolygonsSet) new RegionFactory<Euclidean2D>().union(projected, projectedFacet);
 
             }
         }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Plane.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Plane.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Plane.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Plane.java Fri Jun  3 18:08:12 2011
@@ -16,27 +16,26 @@
  */
 package org.apache.commons.math.geometry.euclidean.threed;
 
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
+import org.apache.commons.math.geometry.Vector;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math.geometry.euclidean.twod.Euclidean2D;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
 import org.apache.commons.math.geometry.euclidean.twod.PolygonsSet;
-import org.apache.commons.math.geometry.partitioning.BSPTree;
+import org.apache.commons.math.geometry.partitioning.Embedding;
 import org.apache.commons.math.geometry.partitioning.Hyperplane;
-import org.apache.commons.math.geometry.partitioning.Point;
-import org.apache.commons.math.geometry.partitioning.Region;
-import org.apache.commons.math.geometry.partitioning.SubHyperplane;
-import org.apache.commons.math.geometry.partitioning.SubSpace;
 import org.apache.commons.math.util.FastMath;
 
 /** The class represent planes in a three dimensional space.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class Plane implements Hyperplane {
+public class Plane implements Hyperplane<Euclidean3D>, Embedding<Euclidean3D, Euclidean2D> {
 
     /** Offset of the origin with respect to the plane. */
     private double originOffset;
 
     /** Origin of the plane frame. */
-    private Point3D origin;
+    private Vector3D origin;
 
     /** First vector of the plane frame (in plane). */
     private Vector3D u;
@@ -100,7 +99,7 @@ public class Plane implements Hyperplane
      * shared (except for immutable objects).</p>
      * @return a new hyperplane, copy of the instance
      */
-    public Hyperplane copySelf() {
+    public Plane copySelf() {
         return new Plane(this);
     }
 
@@ -143,7 +142,7 @@ public class Plane implements Hyperplane
     /** Reset the plane frame.
      */
     private void setFrame() {
-        origin = new Point3D(-originOffset, w);
+        origin = new Vector3D(-originOffset, w);
         u = w.orthogonal();
         v = Vector3D.crossProduct(w, u);
     }
@@ -154,7 +153,7 @@ public class Plane implements Hyperplane
      * @return the origin point of the plane frame (point closest to the
      * 3D-space origin)
      */
-    public Point3D getOrigin() {
+    public Vector3D getOrigin() {
         return origin;
     }
 
@@ -217,24 +216,24 @@ public class Plane implements Hyperplane
      * @param point point of the space (must be a {@link Vector3D
      * Vector3D} instance)
      * @return in-plane point (really a {@link
-     * org.apache.commons.math.geometry.euclidean.twod.Point2D Point2D} instance)
+     * org.apache.commons.math.geometry.euclidean.twod.Vector2D Vector2D} instance)
      * @see #toSpace
      */
-    public Point toSubSpace(final Point point) {
+    public Vector2D toSubSpace(final Vector<Euclidean3D> point) {
         final Vector3D p3D = (Vector3D) point;
-        return new Point2D(Vector3D.dotProduct(p3D, u),
+        return new Vector2D(Vector3D.dotProduct(p3D, u),
                            Vector3D.dotProduct(p3D, v));
     }
 
     /** Transform an in-plane point into a 3D space point.
      * @param point in-plane point (must be a {@link
-     * org.apache.commons.math.geometry.euclidean.twod.Point2D Point2D} instance)
+     * org.apache.commons.math.geometry.euclidean.twod.Vector2D Vector2D} instance)
      * @return 3D space point (really a {@link Vector3D Vector3D} instance)
      * @see #toSubSpace
      */
-    public Point toSpace(final Point point) {
-        final Point2D p2D = (Point2D) point;
-        return new Point3D(p2D.x, u, p2D.y, v, -originOffset, w);
+    public Vector3D toSpace(final Vector<Euclidean2D> point) {
+        final Vector2D p2D = (Vector2D) point;
+        return new Vector3D(p2D.getX(), u, p2D.getY(), v, -originOffset, w);
     }
 
     /** Get one point from the 3D-space.
@@ -244,8 +243,8 @@ public class Plane implements Hyperplane
      * @return one point in the 3D-space, with given coordinates and offset
      * relative to the plane
      */
-    public Vector3D getPointAt(final Point2D inPlane, final double offset) {
-        return new Vector3D(inPlane.x, u, inPlane.y, v, offset - originOffset, w);
+    public Vector3D getPointAt(final Vector2D inPlane, final double offset) {
+        return new Vector3D(inPlane.getX(), u, inPlane.getY(), v, offset - originOffset, w);
     }
 
     /** Check if the instance is similar to another plane.
@@ -303,15 +302,15 @@ public class Plane implements Hyperplane
      * @return intersection point between between the line and the
      * instance (null if the line is parallel to the instance)
      */
-    public Point3D intersection(final Line line) {
+    public Vector3D intersection(final Line line) {
         final Vector3D direction = line.getDirection();
         final double   dot       = Vector3D.dotProduct(w, direction);
         if (FastMath.abs(dot) < 1.0e-10) {
             return null;
         }
-        final Vector3D point = (Vector3D) line.toSpace(Point1D.ZERO);
+        final Vector3D point = (Vector3D) line.toSpace(Vector1D.ZERO);
         final double   k     = -(originOffset + Vector3D.dotProduct(w, point)) / dot;
-        return new Point3D(1.0, point, k, direction);
+        return new Vector3D(1.0, point, k, direction);
     }
 
     /** Build the line shared by the instance and another plane.
@@ -319,13 +318,12 @@ public class Plane implements Hyperplane
      * @return line at the intersection of the instance and the
      * other plane (really a {@link Line Line} instance)
      */
-    public SubSpace intersection(final Hyperplane other) {
-        final Plane otherP = (Plane) other;
-        final Vector3D direction = Vector3D.crossProduct(w, otherP.w);
+    public Line intersection(final Plane other) {
+        final Vector3D direction = Vector3D.crossProduct(w, other.w);
         if (direction.getNorm() < 1.0e-10) {
             return null;
         }
-        return new Line(intersection(this, otherP, new Plane(direction)),
+        return new Line(intersection(this, other, new Plane(direction)),
                         direction);
     }
 
@@ -374,15 +372,15 @@ public class Plane implements Hyperplane
     /** Build a region covering the whole hyperplane.
      * @return a region covering the whole hyperplane
      */
-    public Region wholeHyperplane() {
-        return new PolygonsSet();
+    public SubPlane wholeHyperplane() {
+        return new SubPlane(this, new PolygonsSet());
     }
 
     /** Build a region covering the whole space.
      * @return a region containing the instance (really a {@link
      * PolyhedronsSet PolyhedronsSet} instance)
      */
-    public Region wholeSpace() {
+    public PolyhedronsSet wholeSpace() {
         return new PolyhedronsSet();
     }
 
@@ -390,7 +388,7 @@ public class Plane implements Hyperplane
      * @param p point to check
      * @return true if p belongs to the plane
      */
-    public boolean contains(final Point3D p) {
+    public boolean contains(final Vector3D p) {
         return FastMath.abs(getOffset(p)) < 1.0e-10;
     }
 
@@ -416,7 +414,7 @@ public class Plane implements Hyperplane
      * @param point point to check
      * @return offset of the point
      */
-    public double getOffset(final Point point) {
+    public double getOffset(final Vector<Euclidean3D> point) {
         return Vector3D.dotProduct((Vector3D) point, w) + originOffset;
     }
 
@@ -425,102 +423,8 @@ public class Plane implements Hyperplane
      * @return true if the instance and the other hyperplane have
      * the same orientation
      */
-    public boolean sameOrientationAs(final Hyperplane other) {
+    public boolean sameOrientationAs(final Hyperplane<Euclidean3D> other) {
         return Vector3D.dotProduct(((Plane) other).w, w) > 0.0;
     }
 
-    /** Compute the relative position of a sub-hyperplane with respect
-     * to the instance.
-     * @param sub sub-hyperplane to check
-     * @return one of {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#PLUS PLUS},
-     * {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#MINUS MINUS},
-     * {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#BOTH BOTH},
-     * {@link org.apache.commons.math.geometry.partitioning.Hyperplane.Side#HYPER HYPER}
-     */
-    public Side side(final SubHyperplane sub) {
-
-        final Plane otherPlane = (Plane) sub.getHyperplane();
-        final Line  inter      = (Line) intersection(otherPlane);
-
-        if (inter == null) {
-            // the hyperplanes are parallel,
-            // any point can be used to check their relative position
-            final double global = getOffset(otherPlane);
-            return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
-        }
-
-        // create a 2D line in the otherPlane canonical 2D frame such that:
-        //   - the line is the crossing line of the two planes in 3D
-        //   - the line splits the otherPlane in two half planes with an
-        //     orientation consistent with the orientation of the instance
-        //     (i.e. the 3D half space on the plus side (resp. minus side)
-        //      of the instance contains the 2D half plane on the plus side
-        //      (resp. minus side) of the 2D line
-        Point2D p = (Point2D) otherPlane.toSubSpace(inter.toSpace(Point1D.ZERO));
-        Point2D q = (Point2D) otherPlane.toSubSpace(inter.toSpace(Point1D.ONE));
-        if (Vector3D.dotProduct(Vector3D.crossProduct(inter.getDirection(),
-                                                      otherPlane.getNormal()),
-                                                      w) < 0) {
-            final Point2D tmp = p;
-            p           = q;
-            q           = tmp;
-        }
-        final Hyperplane line2D = new org.apache.commons.math.geometry.euclidean.twod.Line(p, q);
-
-        // check the side on the 2D plane
-        return sub.getRemainingRegion().side(line2D);
-
-    }
-
-    /** Split a sub-hyperplane in two parts by the instance.
-     * @param sub sub-hyperplane to split
-     * @return an object containing both the part of the sub-hyperplane
-     * on the plus side of the instance and the part of the
-     * sub-hyperplane on the minus side of the instance
-     */
-    public SplitSubHyperplane split(final SubHyperplane sub) {
-
-        final Plane otherPlane = (Plane) sub.getHyperplane();
-        final Line  inter      = (Line) intersection(otherPlane);
-
-        if (inter == null) {
-            // the hyperplanes are parallel
-            final double global = getOffset(otherPlane);
-            return (global < -1.0e-10) ? new SplitSubHyperplane(null, sub) : new SplitSubHyperplane(sub, null);
-        }
-
-        // the hyperplanes do intersect
-        Point2D p = (Point2D) otherPlane.toSubSpace(inter.toSpace(Point1D.ZERO));
-        Point2D q = (Point2D) otherPlane.toSubSpace(inter.toSpace(Point1D.ONE));
-        if (Vector3D.dotProduct(Vector3D.crossProduct(inter.getDirection(),
-                                                      otherPlane.getNormal()),
-                                                      w) < 0) {
-            final Point2D tmp = p;
-            p           = q;
-            q           = tmp;
-        }
-        final SubHyperplane l2DMinus =
-            new SubHyperplane(new org.apache.commons.math.geometry.euclidean.twod.Line(p, q));
-        final SubHyperplane l2DPlus =
-            new SubHyperplane(new org.apache.commons.math.geometry.euclidean.twod.Line(q, p));
-
-        final BSPTree splitTree =
-            sub.getRemainingRegion().getTree(false).split(l2DMinus);
-        final BSPTree plusTree  = Region.isEmpty(splitTree.getPlus()) ?
-                                  new BSPTree(Boolean.FALSE) :
-                                  new BSPTree(l2DPlus, new BSPTree(Boolean.FALSE),
-                                              splitTree.getPlus(), null);
-
-        final BSPTree minusTree = Region.isEmpty(splitTree.getMinus()) ?
-                                  new BSPTree(Boolean.FALSE) :
-                                  new BSPTree(l2DMinus, new BSPTree(Boolean.FALSE),
-                                              splitTree.getMinus(), null);
-
-        return new SplitSubHyperplane(new SubHyperplane(otherPlane.copySelf(),
-                                                        new PolygonsSet(plusTree)),
-                                                        new SubHyperplane(otherPlane.copySelf(),
-                                                                          new PolygonsSet(minusTree)));
-
-    }
-
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSet.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSet.java Fri Jun  3 18:08:12 2011
@@ -17,23 +17,29 @@
 package org.apache.commons.math.geometry.euclidean.threed;
 
 import java.awt.geom.AffineTransform;
-import java.util.Arrays;
 import java.util.Collection;
 
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
+import org.apache.commons.math.geometry.Vector;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.twod.Euclidean2D;
+import org.apache.commons.math.geometry.euclidean.twod.SubLine;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
 import org.apache.commons.math.geometry.partitioning.BSPTree;
 import org.apache.commons.math.geometry.partitioning.BSPTreeVisitor;
+import org.apache.commons.math.geometry.partitioning.BoundaryAttribute;
 import org.apache.commons.math.geometry.partitioning.Hyperplane;
-import org.apache.commons.math.geometry.partitioning.Point;
 import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
 import org.apache.commons.math.geometry.partitioning.Transform;
+import org.apache.commons.math.geometry.partitioning.AbstractRegion;
 import org.apache.commons.math.util.FastMath;
 
 /** This class represents a 3D region: a set of polyhedrons.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class PolyhedronsSet extends Region {
+public class PolyhedronsSet extends AbstractRegion<Euclidean3D, Euclidean2D> {
 
     /** Build a polyhedrons set representing the whole real line.
      */
@@ -50,7 +56,7 @@ public class PolyhedronsSet extends Regi
      * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
      * @param tree inside/outside BSP tree representing the region
      */
-    public PolyhedronsSet(final BSPTree tree) {
+    public PolyhedronsSet(final BSPTree<Euclidean3D> tree) {
         super(tree);
     }
 
@@ -61,19 +67,19 @@ public class PolyhedronsSet extends Regi
      * 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 disjoints polyhedrons considered as a whole). In
+     * 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
+     * calls to the {@link Region#checkPoint(Vector) 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> boundary) {
+    public PolyhedronsSet(final Collection<SubHyperplane<Euclidean3D>> boundary) {
         super(boundary);
     }
 
@@ -85,21 +91,21 @@ public class PolyhedronsSet extends Regi
      * @param zMin low bound along the z direction
      * @param zMax high bound along the z direction
      */
+    @SuppressWarnings("unchecked")
     public PolyhedronsSet(final double xMin, final double xMax,
                           final double yMin, final double yMax,
                           final double zMin, final double zMax) {
-        this(buildConvex(Arrays.asList(new Hyperplane[] {
+        this(new RegionFactory<Euclidean3D>().buildConvex(
             new Plane(new Vector3D(xMin, 0,    0),   Vector3D.MINUS_I),
             new Plane(new Vector3D(xMax, 0,    0),   Vector3D.PLUS_I),
             new Plane(new Vector3D(0,    yMin, 0),   Vector3D.MINUS_J),
             new Plane(new Vector3D(0,    yMax, 0),   Vector3D.PLUS_J),
             new Plane(new Vector3D(0,    0,   zMin), Vector3D.MINUS_K),
-            new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K)
-        })).getTree(false));
+            new Plane(new Vector3D(0,    0,   zMax), Vector3D.PLUS_K)).getTree(false));
     }
 
     /** {@inheritDoc} */
-    public Region buildNew(final BSPTree tree) {
+    public PolyhedronsSet buildNew(final BSPTree<Euclidean3D> tree) {
         return new PolyhedronsSet(tree);
     }
 
@@ -113,32 +119,34 @@ public class PolyhedronsSet extends Regi
             // the polyhedrons set as a finite outside
             // surrounded by an infinite inside
             setSize(Double.POSITIVE_INFINITY);
-            setBarycenter(Point3D.UNDEFINED);
+            setBarycenter(Vector3D.NaN);
         } else {
             // the polyhedrons set is finite, apply the remaining scaling factors
             setSize(getSize() / 3.0);
-            setBarycenter(new Point3D(1.0 / (4 * getSize()), (Vector3D) getBarycenter()));
+            setBarycenter(new Vector3D(1.0 / (4 * getSize()), (Vector3D) getBarycenter()));
         }
 
     }
 
     /** Visitor computing geometrical properties. */
-    private class FacetsContributionVisitor implements BSPTreeVisitor {
+    private class FacetsContributionVisitor implements BSPTreeVisitor<Euclidean3D> {
 
         /** Simple constructor. */
         public FacetsContributionVisitor() {
             setSize(0);
-            setBarycenter(new Point3D(0, 0, 0));
+            setBarycenter(new Vector3D(0, 0, 0));
         }
 
         /** {@inheritDoc} */
-        public Order visitOrder(final BSPTree node) {
+        public Order visitOrder(final BSPTree<Euclidean3D> node) {
             return Order.MINUS_SUB_PLUS;
         }
 
         /** {@inheritDoc} */
-        public void visitInternalNode(final BSPTree node) {
-            final BoundaryAttribute attribute = (BoundaryAttribute) node.getAttribute();
+        public void visitInternalNode(final BSPTree<Euclidean3D> node) {
+            @SuppressWarnings("unchecked")
+            final BoundaryAttribute<Euclidean3D> attribute =
+                (BoundaryAttribute<Euclidean3D>) node.getAttribute();
             if (attribute.getPlusOutside() != null) {
                 addContribution(attribute.getPlusOutside(), false);
             }
@@ -148,32 +156,32 @@ public class PolyhedronsSet extends Regi
         }
 
         /** {@inheritDoc} */
-        public void visitLeafNode(final BSPTree node) {
+        public void visitLeafNode(final BSPTree<Euclidean3D> node) {
         }
 
         /** Add he contribution of a boundary facet.
          * @param facet boundary facet
          * @param reversed if true, the facet has the inside on its plus side
          */
-        private void addContribution(final SubHyperplane facet, final boolean reversed) {
+        private void addContribution(final SubHyperplane<Euclidean3D> facet, final boolean reversed) {
 
-            final Region polygon = facet.getRemainingRegion();
+            final Region<Euclidean2D> polygon = ((SubPlane) facet).getRemainingRegion();
             final double area    = polygon.getSize();
 
             if (Double.isInfinite(area)) {
                 setSize(Double.POSITIVE_INFINITY);
-                setBarycenter(Point3D.UNDEFINED);
+                setBarycenter(Vector3D.NaN);
             } else {
 
                 final Plane    plane  = (Plane) facet.getHyperplane();
-                final Vector3D facetB = (Point3D) plane.toSpace(polygon.getBarycenter());
+                final Vector3D facetB = plane.toSpace(polygon.getBarycenter());
                 double   scaled = area * Vector3D.dotProduct(facetB, plane.getNormal());
                 if (reversed) {
                     scaled = -scaled;
                 }
 
                 setSize(getSize() + scaled);
-                setBarycenter(new Point3D(1.0, (Point3D) getBarycenter(), scaled, facetB));
+                setBarycenter(new Vector3D(1.0, (Vector3D) getBarycenter(), scaled, facetB));
 
             }
 
@@ -188,7 +196,7 @@ public class PolyhedronsSet extends Regi
      * given point, or null if the line does not intersect any
      * sub-hyperplaned
      */
-    public SubHyperplane firstIntersection(final Vector3D point, final Line line) {
+    public SubHyperplane<Euclidean3D> firstIntersection(final Vector3D point, final Line line) {
         return recurseFirstIntersection(getTree(true), point, line);
     }
 
@@ -200,23 +208,23 @@ public class PolyhedronsSet extends Regi
      * given point, or null if the line does not intersect any
      * sub-hyperplaned
      */
-    private SubHyperplane recurseFirstIntersection(final BSPTree node,
-                                                   final Vector3D point,
-                                                   final Line line) {
+    private SubHyperplane<Euclidean3D> recurseFirstIntersection(final BSPTree<Euclidean3D> node,
+                                                                final Vector3D point,
+                                                                final Line line) {
 
-        final SubHyperplane cut = node.getCut();
+        final SubHyperplane<Euclidean3D> cut = node.getCut();
         if (cut == null) {
             return null;
         }
-        final BSPTree minus = node.getMinus();
-        final BSPTree plus  = node.getPlus();
-        final Plane   plane = (Plane) cut.getHyperplane();
+        final BSPTree<Euclidean3D> minus = node.getMinus();
+        final BSPTree<Euclidean3D> plus  = node.getPlus();
+        final Plane               plane = (Plane) cut.getHyperplane();
 
         // establish search order
-        final double offset = plane.getOffset((Point) point);
+        final double offset = plane.getOffset(point);
         final boolean in    = FastMath.abs(offset) < 1.0e-10;
-        final BSPTree near;
-        final BSPTree far;
+        final BSPTree<Euclidean3D> near;
+        final BSPTree<Euclidean3D> far;
         if (offset < 0) {
             near = minus;
             far  = plus;
@@ -227,14 +235,14 @@ public class PolyhedronsSet extends Regi
 
         if (in) {
             // search in the cut hyperplane
-            final SubHyperplane facet = boundaryFacet(point, node);
+            final SubHyperplane<Euclidean3D> facet = boundaryFacet(point, node);
             if (facet != null) {
                 return facet;
             }
         }
 
         // search in the near branch
-        final SubHyperplane crossed = recurseFirstIntersection(near, point, line);
+        final SubHyperplane<Euclidean3D> crossed = recurseFirstIntersection(near, point, line);
         if (crossed != null) {
             return crossed;
         }
@@ -243,7 +251,7 @@ public class PolyhedronsSet extends Regi
             // search in the cut hyperplane
             final Vector3D hit3D = plane.intersection(line);
             if (hit3D != null) {
-                final SubHyperplane facet = boundaryFacet(hit3D, node);
+                final SubHyperplane<Euclidean3D> facet = boundaryFacet(hit3D, node);
                 if (facet != null) {
                     return facet;
                 }
@@ -261,15 +269,18 @@ public class PolyhedronsSet extends Regi
      * @return the boundary facet this points belongs to (or null if it
      * does not belong to any boundary facet)
      */
-    private SubHyperplane boundaryFacet(final Vector3D point, final BSPTree node) {
-        final Point point2D = node.getCut().getHyperplane().toSubSpace((Point) point);
-        final BoundaryAttribute attribute = (BoundaryAttribute) node.getAttribute();
+    private SubHyperplane<Euclidean3D> boundaryFacet(final Vector3D point,
+                                                     final BSPTree<Euclidean3D> node) {
+        final Vector2D point2D = ((Plane) node.getCut().getHyperplane()).toSubSpace(point);
+        @SuppressWarnings("unchecked")
+        final BoundaryAttribute<Euclidean3D> attribute =
+            (BoundaryAttribute<Euclidean3D>) node.getAttribute();
         if ((attribute.getPlusOutside() != null) &&
-            (attribute.getPlusOutside().getRemainingRegion().checkPoint(point2D) == Location.INSIDE)) {
+            (((SubPlane) attribute.getPlusOutside()).getRemainingRegion().checkPoint(point2D) == Location.INSIDE)) {
             return attribute.getPlusOutside();
         }
         if ((attribute.getPlusInside() != null) &&
-            (attribute.getPlusInside().getRemainingRegion().checkPoint(point2D) == Location.INSIDE)) {
+            (((SubPlane) attribute.getPlusInside()).getRemainingRegion().checkPoint(point2D) == Location.INSIDE)) {
             return attribute.getPlusInside();
         }
         return null;
@@ -286,7 +297,7 @@ public class PolyhedronsSet extends Regi
     }
 
     /** 3D rotation as a Transform. */
-    private static class RotationTransform implements Transform {
+    private static class RotationTransform implements Transform<Euclidean3D, Euclidean2D> {
 
         /** Center point of the rotation. */
         private Vector3D   center;
@@ -295,10 +306,10 @@ public class PolyhedronsSet extends Regi
         private Rotation   rotation;
 
         /** Cached original hyperplane. */
-        private Hyperplane cachedOriginal;
+        private Plane cachedOriginal;
 
         /** Cached 2D transform valid inside the cached original hyperplane. */
-        private Transform  cachedTransform;
+        private Transform<Euclidean2D, Euclidean1D>  cachedTransform;
 
         /** Build a rotation transform.
          * @param center center point of the rotation
@@ -310,40 +321,41 @@ public class PolyhedronsSet extends Regi
         }
 
         /** {@inheritDoc} */
-        public Point apply(final Point point) {
+        public Vector3D apply(final Vector<Euclidean3D> point) {
             final Vector3D delta = ((Vector3D) point).subtract(center);
-            return new Point3D(1.0, center, 1.0, rotation.applyTo(delta));
+            return new Vector3D(1.0, center, 1.0, rotation.applyTo(delta));
         }
 
         /** {@inheritDoc} */
-        public Hyperplane apply(final Hyperplane hyperplane) {
+        public Plane apply(final Hyperplane<Euclidean3D> hyperplane) {
             return ((Plane) hyperplane).rotate(center, rotation);
         }
 
         /** {@inheritDoc} */
-        public SubHyperplane apply(final SubHyperplane sub,
-                                   final Hyperplane original, final Hyperplane transformed) {
+        public SubHyperplane<Euclidean2D> apply(final SubHyperplane<Euclidean2D> sub,
+                                                final Hyperplane<Euclidean3D> original,
+                                                final Hyperplane<Euclidean3D> transformed) {
             if (original != cachedOriginal) {
                 // we have changed hyperplane, reset the in-hyperplane transform
 
                 final Plane    oPlane = (Plane) original;
                 final Plane    tPlane = (Plane) transformed;
                 final Vector3D p00    = oPlane.getOrigin();
-                final Vector3D p10    = (Vector3D) oPlane.toSpace(new Point2D(1.0, 0.0));
-                final Vector3D p01    = (Vector3D) oPlane.toSpace(new Point2D(0.0, 1.0));
-                final Point2D  tP00   = (Point2D) tPlane.toSubSpace(apply((Point) p00));
-                final Point2D  tP10   = (Point2D) tPlane.toSubSpace(apply((Point) p10));
-                final Point2D  tP01   = (Point2D) tPlane.toSubSpace(apply((Point) p01));
+                final Vector3D p10    = (Vector3D) oPlane.toSpace(new Vector2D(1.0, 0.0));
+                final Vector3D p01    = (Vector3D) oPlane.toSpace(new Vector2D(0.0, 1.0));
+                final Vector2D  tP00   = (Vector2D) tPlane.toSubSpace(apply(p00));
+                final Vector2D  tP10   = (Vector2D) tPlane.toSubSpace(apply(p10));
+                final Vector2D  tP01   = (Vector2D) tPlane.toSubSpace(apply(p01));
                 final AffineTransform at =
                     new AffineTransform(tP10.getX() - tP00.getX(), tP10.getY() - tP00.getY(),
                                         tP01.getX() - tP00.getX(), tP01.getY() - tP00.getY(),
                                         tP00.getX(), tP00.getY());
 
-                cachedOriginal  = original;
+                cachedOriginal  = (Plane) original;
                 cachedTransform = org.apache.commons.math.geometry.euclidean.twod.Line.getTransform(at);
 
             }
-            return sub.applyTransform(cachedTransform);
+            return ((SubLine) sub).applyTransform(cachedTransform);
         }
 
     }
@@ -358,16 +370,16 @@ public class PolyhedronsSet extends Regi
     }
 
     /** 3D translation as a transform. */
-    private static class TranslationTransform implements Transform {
+    private static class TranslationTransform implements Transform<Euclidean3D, Euclidean2D> {
 
         /** Translation vector. */
         private Vector3D   translation;
 
         /** Cached original hyperplane. */
-        private Hyperplane cachedOriginal;
+        private Plane cachedOriginal;
 
         /** Cached 2D transform valid inside the cached original hyperplane. */
-        private Transform  cachedTransform;
+        private Transform<Euclidean2D, Euclidean1D>  cachedTransform;
 
         /** Build a translation transform.
          * @param translation translation vector
@@ -377,34 +389,35 @@ public class PolyhedronsSet extends Regi
         }
 
         /** {@inheritDoc} */
-        public Point apply(final Point point) {
-            return new Point3D(1.0, (Vector3D) point, 1.0, translation);
+        public Vector3D apply(final Vector<Euclidean3D> point) {
+            return new Vector3D(1.0, (Vector3D) point, 1.0, translation);
         }
 
         /** {@inheritDoc} */
-        public Hyperplane apply(final Hyperplane hyperplane) {
+        public Plane apply(final Hyperplane<Euclidean3D> hyperplane) {
             return ((Plane) hyperplane).translate(translation);
         }
 
         /** {@inheritDoc} */
-        public SubHyperplane apply(final SubHyperplane sub,
-                                   final Hyperplane original, final Hyperplane transformed) {
+        public SubHyperplane<Euclidean2D> apply(final SubHyperplane<Euclidean2D> sub,
+                                                final Hyperplane<Euclidean3D> original,
+                                                final Hyperplane<Euclidean3D> transformed) {
             if (original != cachedOriginal) {
                 // we have changed hyperplane, reset the in-hyperplane transform
 
                 final Plane   oPlane = (Plane) original;
                 final Plane   tPlane = (Plane) transformed;
-                final Point2D shift  = (Point2D) tPlane.toSubSpace(apply((Point) oPlane.getOrigin()));
+                final Vector2D shift  = (Vector2D) tPlane.toSubSpace(apply(oPlane.getOrigin()));
                 final AffineTransform at =
                     AffineTransform.getTranslateInstance(shift.getX(), shift.getY());
 
-                cachedOriginal  = original;
+                cachedOriginal  = (Plane) original;
                 cachedTransform =
                     org.apache.commons.math.geometry.euclidean.twod.Line.getTransform(at);
 
             }
 
-            return sub.applyTransform(cachedTransform);
+            return ((SubLine) sub).applyTransform(cachedTransform);
 
         }
 

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java?rev=1131127&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java Fri Jun  3 18:08:12 2011
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.geometry.euclidean.threed;
+
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+import org.apache.commons.math.geometry.euclidean.twod.Euclidean2D;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
+import org.apache.commons.math.geometry.euclidean.twod.PolygonsSet;
+import org.apache.commons.math.geometry.partitioning.AbstractSubHyperplane;
+import org.apache.commons.math.geometry.partitioning.BSPTree;
+import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.Side;
+import org.apache.commons.math.geometry.partitioning.SubHyperplane;
+
+/** This class represents a sub-hyperplane for {@link Plane}.
+ * @version $Id:$
+ * @since 3.0
+ */
+public class SubPlane extends AbstractSubHyperplane<Euclidean3D, Euclidean2D> {
+
+    /** Simple constructor.
+     * @param hyperplane underlying hyperplane
+     * @param remainingRegion remaining region of the hyperplane
+     */
+    public SubPlane(final Hyperplane<Euclidean3D> hyperplane,
+                    final Region<Euclidean2D> remainingRegion) {
+        super(hyperplane, remainingRegion);
+    }
+
+    /** {@inheritDoc} */
+    protected AbstractSubHyperplane<Euclidean3D, Euclidean2D> buildNew(final Hyperplane<Euclidean3D> hyperplane,
+                                                                       final Region<Euclidean2D> remainingRegion) {
+        return new SubPlane(hyperplane, remainingRegion);
+    }
+
+    /** {@inheritDoc} */
+    public Side side(Hyperplane<Euclidean3D> hyperplane) {
+
+        final Plane otherPlane = (Plane) hyperplane;
+        final Plane thisPlane  = (Plane) getHyperplane();
+        final Line  inter      = (Line) otherPlane.intersection(thisPlane);
+
+        if (inter == null) {
+            // the hyperplanes are parallel,
+            // any point can be used to check their relative position
+            final double global = otherPlane.getOffset(thisPlane);
+            return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
+        }
+
+        // create a 2D line in the otherPlane canonical 2D frame such that:
+        //   - the line is the crossing line of the two planes in 3D
+        //   - the line splits the otherPlane in two half planes with an
+        //     orientation consistent with the orientation of the instance
+        //     (i.e. the 3D half space on the plus side (resp. minus side)
+        //      of the instance contains the 2D half plane on the plus side
+        //      (resp. minus side) of the 2D line
+        Vector2D p = thisPlane.toSubSpace(inter.toSpace(Vector1D.ZERO));
+        Vector2D q = thisPlane.toSubSpace(inter.toSpace(Vector1D.ONE));
+        Vector3D crossP = Vector3D.crossProduct(inter.getDirection(), thisPlane.getNormal());
+        if (Vector3D.dotProduct(crossP, otherPlane.getNormal()) < 0) {
+            final Vector2D tmp = p;
+            p           = q;
+            q           = tmp;
+        }
+        final org.apache.commons.math.geometry.euclidean.twod.Line line2D =
+            new org.apache.commons.math.geometry.euclidean.twod.Line(p, q);
+
+        // check the side on the 2D plane
+        return getRemainingRegion().side(line2D);
+
+    }
+
+    /** Split the instance in two parts by an hyperplane.
+     * @param hyperplane splitting hyperplane
+     * @return an object containing both the part of the instance
+     * on the plus side of the instance and the part of the
+     * instance on the minus side of the instance
+     */
+    public SplitSubHyperplane<Euclidean3D> split(Hyperplane<Euclidean3D> hyperplane) {
+
+        final Plane otherPlane = (Plane) hyperplane;
+        final Plane thisPlane  = (Plane) getHyperplane();
+        final Line  inter      = (Line) otherPlane.intersection(thisPlane);
+
+        if (inter == null) {
+            // the hyperplanes are parallel
+            final double global = otherPlane.getOffset(thisPlane);
+            return (global < -1.0e-10) ?
+                   new SplitSubHyperplane<Euclidean3D>(null, this) :
+                   new SplitSubHyperplane<Euclidean3D>(this, null);
+        }
+
+        // the hyperplanes do intersect
+        Vector2D p = thisPlane.toSubSpace(inter.toSpace(Vector1D.ZERO));
+        Vector2D q = thisPlane.toSubSpace(inter.toSpace(Vector1D.ONE));
+        Vector3D crossP = Vector3D.crossProduct(inter.getDirection(), thisPlane.getNormal());
+        if (Vector3D.dotProduct(crossP, otherPlane.getNormal()) < 0) {
+            final Vector2D tmp = p;
+            p           = q;
+            q           = tmp;
+        }
+        final SubHyperplane<Euclidean2D> l2DMinus =
+            new org.apache.commons.math.geometry.euclidean.twod.Line(p, q).wholeHyperplane();
+        final SubHyperplane<Euclidean2D> l2DPlus =
+            new org.apache.commons.math.geometry.euclidean.twod.Line(q, p).wholeHyperplane();
+
+        final BSPTree<Euclidean2D> splitTree = getRemainingRegion().getTree(false).split(l2DMinus);
+        final BSPTree<Euclidean2D> plusTree  = getRemainingRegion().isEmpty(splitTree.getPlus()) ?
+                                               new BSPTree<Euclidean2D>(Boolean.FALSE) :
+                                               new BSPTree<Euclidean2D>(l2DPlus, new BSPTree<Euclidean2D>(Boolean.FALSE),
+                                                                        splitTree.getPlus(), null);
+
+        final BSPTree<Euclidean2D> minusTree = getRemainingRegion().isEmpty(splitTree.getMinus()) ?
+                                               new BSPTree<Euclidean2D>(Boolean.FALSE) :
+                                                   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)));
+
+    }
+
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/SubPlane.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision