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 [2/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...

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Line.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Line.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Line.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Line.java Fri Jun  3 18:08:12 2011
@@ -20,15 +20,14 @@ import java.awt.geom.AffineTransform;
 
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.geometry.Vector;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
 import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
 import org.apache.commons.math.geometry.euclidean.oned.OrientedPoint;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
-import org.apache.commons.math.geometry.partitioning.BSPTree;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+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.geometry.partitioning.Transform;
 import org.apache.commons.math.util.FastMath;
 import org.apache.commons.math.util.MathUtils;
@@ -57,9 +56,10 @@ import org.apache.commons.math.util.Math
  * left half plane is the set of points with negative offsets and the
  * right half plane is the set of points with positive offsets.</p>
 
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class Line implements Hyperplane {
+public class Line implements Hyperplane<Euclidean2D>, Embedding<Euclidean2D, Euclidean1D> {
 
     /** Angle with respect to the abscissa axis. */
     private double angle;
@@ -78,7 +78,7 @@ public class Line implements Hyperplane 
      * @param p1 first point
      * @param p2 second point
      */
-    public Line(final Point2D p1, final Point2D p2) {
+    public Line(final Vector2D p1, final Vector2D p2) {
         reset(p1, p2);
     }
 
@@ -86,7 +86,7 @@ public class Line implements Hyperplane 
      * @param p point belonging to the line
      * @param angle angle of the line with respect to abscissa axis
      */
-    public Line(final Point2D p, final double angle) {
+    public Line(final Vector2D p, final double angle) {
         reset(p, angle);
     }
 
@@ -116,7 +116,7 @@ public class Line implements Hyperplane 
     }
 
     /** {@inheritDoc} */
-    public Hyperplane copySelf() {
+    public Line copySelf() {
         return new Line(this);
     }
 
@@ -125,20 +125,20 @@ public class Line implements Hyperplane 
      * @param p1 first point
      * @param p2 second point
      */
-    public void reset(final Point2D p1, final Point2D p2) {
-        final double dx = p2.x - p1.x;
-        final double dy = p2.y - p1.y;
+    public void reset(final Vector2D p1, final Vector2D p2) {
+        final double dx = p2.getX() - p1.getX();
+        final double dy = p2.getY() - p1.getY();
         final double d = FastMath.hypot(dx, dy);
         if (d == 0.0) {
             angle        = 0.0;
             cos          = 1.0;
             sin          = 0.0;
-            originOffset = p1.y;
+            originOffset = p1.getY();
         } else {
             angle        = FastMath.PI + FastMath.atan2(-dy, -dx);
             cos          = FastMath.cos(angle);
             sin          = FastMath.sin(angle);
-            originOffset = (p2.x * p1.y - p1.x * p2.y) / d;
+            originOffset = (p2.getX() * p1.getY() - p1.getX() * p2.getY()) / d;
         }
     }
 
@@ -146,11 +146,11 @@ public class Line implements Hyperplane 
      * @param p point belonging to the line
      * @param alpha angle of the line with respect to abscissa axis
      */
-    public void reset(final Point2D p, final double alpha) {
+    public void reset(final Vector2D p, final double alpha) {
         this.angle   = MathUtils.normalizeAngle(alpha, FastMath.PI);
         cos          = FastMath.cos(this.angle);
         sin          = FastMath.sin(this.angle);
-        originOffset = cos * p.y - sin * p.x;
+        originOffset = cos * p.getY() - sin * p.getX();
     }
 
     /** Revert the instance.
@@ -176,57 +176,44 @@ public class Line implements Hyperplane 
                         -cos, -sin, -originOffset);
     }
 
-    /** Transform a 2D space point into a line point.
-     * @param point 2D point (must be a {@link Point2D Point2D}
-     * instance)
-     * @return line point corresponding to the 2D point (really a {@link
-     * org.apache.commons.math.geometry.euclidean.oned.Point1D Point1D} instance)
-     * @see #toSpace
-     */
-    public Point toSubSpace(final Point point) {
-        final Point2D p2D = (Point2D) point;
-        return new Point1D(cos * p2D.x + sin * p2D.y);
-    }
-
-    /** Get one point from the line.
-     * @param point desired abscissa for the point (must be a {@link
-     * org.apache.commons.math.geometry.euclidean.oned.Point1D Point1D} instance)
-     * @return line point at specified abscissa (really a {@link Point2D
-     * Point2D} instance)
-     */
-    public Point toSpace(final Point point) {
-        final double abscissa = ((Point1D) point).getAbscissa();
-        return new Point2D(abscissa * cos - originOffset * sin,
+    /** {@inheritDoc} */
+    public Vector1D toSubSpace(final Vector<Euclidean2D> point) {
+        Vector2D p2 = (Vector2D) point;
+        return new Vector1D(cos * p2.getX() + sin * p2.getY());
+    }
+
+    /** {@inheritDoc} */
+    public Vector2D toSpace(final Vector<Euclidean1D> point) {
+        final double abscissa = ((Vector1D) point).getX();
+        return new Vector2D(abscissa * cos - originOffset * sin,
                            abscissa * sin + originOffset * cos);
     }
 
     /** Get the intersection point of the instance and another line.
      * @param other other line
      * @return intersection point of the instance and the other line
-     * (really a {@link Point2D Point2D} instance)
+     * (really a {@link Vector2D Vector2D} instance)
      */
-    public SubSpace intersection(final Hyperplane other) {
+    public Vector2D intersection(final Hyperplane<Euclidean2D> other) {
         final Line otherL = (Line) other;
         final double d = sin * otherL.cos - otherL.sin * cos;
         if (FastMath.abs(d) < 1.0e-10) {
             return null;
         }
-        return new Point2D((cos * otherL.originOffset - otherL.cos * originOffset) / d,
+        return new Vector2D((cos * otherL.originOffset - otherL.cos * originOffset) / d,
                            (sin * otherL.originOffset - otherL.sin * originOffset) / d);
     }
 
-    /** Build a region covering the whole hyperplane.
-     * @return a region covering the whole hyperplane
-     */
-    public Region wholeHyperplane() {
-        return new IntervalsSet();
+    /** {@inheritDoc} */
+    public SubLine wholeHyperplane() {
+        return new SubLine(this, new IntervalsSet());
     }
 
     /** Build a region covering the whole space.
      * @return a region containing the instance (really a {@link
      * PolygonsSet PolygonsSet} instance)
      */
-    public Region wholeSpace() {
+    public PolygonsSet wholeSpace() {
         return new PolygonsSet();
     }
 
@@ -240,7 +227,8 @@ public class Line implements Hyperplane 
      * @param line line to check
      * @return offset of the line
      */
-    public double getOffset(final Line line) {
+    public double getOffset(final Hyperplane<Euclidean2D> hyperplane) {
+        Line line = (Line) hyperplane;
         return originOffset +
                ((cos * line.cos + sin * line.sin > 0) ? -line.originOffset : line.originOffset);
     }
@@ -250,12 +238,12 @@ public class Line implements Hyperplane 
      * positive if the point is on the right side of the line and
      * negative if it is on the left side, according to its natural
      * orientation.</p>
-     * @param point point to check (must be a {@link Point2D Point2D} instance)
+     * @param point point to check (must be a {@link Vector2D Vector2D} instance)
      * @return offset of the point
      */
-    public double getOffset(final Point point) {
-        final Point2D p2D = (Point2D) point;
-        return sin * p2D.x - cos * p2D.y + originOffset;
+    public double getOffset(final Vector<Euclidean2D> point) {
+        Vector2D p2 = (Vector2D) point;
+        return sin * p2.getX() - cos * p2.getY() + originOffset;
     }
 
     /** Check if the instance has the same orientation as another hyperplane.
@@ -271,7 +259,7 @@ public class Line 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<Euclidean2D> other) {
         final Line otherL = (Line) other;
         return (sin * otherL.sin + cos * otherL.cos) >= 0.0;
     }
@@ -282,17 +270,17 @@ public class Line implements Hyperplane 
      * @return one point in the plane, with given abscissa and offset
      * relative to the line
      */
-    public Point2D getPointAt(final Point1D abscissa, final double offset) {
-        final double x       = abscissa.getAbscissa();
+    public Vector2D getPointAt(final Vector1D abscissa, final double offset) {
+        final double x       = abscissa.getX();
         final double dOffset = offset - originOffset;
-        return new Point2D(x * cos + dOffset * sin, x * sin - dOffset * cos);
+        return new Vector2D(x * cos + dOffset * sin, x * sin - dOffset * cos);
     }
 
     /** Check if the line contains a point.
      * @param p point to check
      * @return true if p belongs to the line
      */
-    public boolean contains(final Point2D p) {
+    public boolean contains(final Vector2D p) {
         return FastMath.abs(getOffset(p)) < 1.0e-10;
     }
 
@@ -308,8 +296,8 @@ public class Line implements Hyperplane 
     /** Translate the line to force it passing by a point.
      * @param p point by which the line should pass
      */
-    public void translateToPoint(final Point2D p) {
-        originOffset = cos * p.y - sin * p.x;
+    public void translateToPoint(final Vector2D p) {
+        originOffset = cos * p.getY() - sin * p.getX();
     }
 
     /** Get the angle of the line.
@@ -342,75 +330,6 @@ public class Line implements Hyperplane 
         originOffset = offset;
     }
 
-    /** 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 Hyperplane otherHyp = sub.getHyperplane();
-        final Point2D    crossing = (Point2D) intersection(otherHyp);
-
-        if (crossing == null) {
-            // the lines are parallel,
-            final double global = getOffset((Line) otherHyp);
-            return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
-        }
-
-        // the lines do intersect
-        final boolean direct = FastMath.sin(((Line) otherHyp).angle - angle) < 0;
-        final Point1D x = (Point1D) otherHyp.toSubSpace(crossing);
-        return sub.getRemainingRegion().side(new OrientedPoint(x, direct));
-
-    }
-
-    /** 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 Line    otherLine = (Line) sub.getHyperplane();
-        final Point2D crossing  = (Point2D) intersection(otherLine);
-
-        if (crossing == null) {
-            // the lines are parallel
-            final double global = getOffset(otherLine);
-            return (global < -1.0e-10) ?
-                   new SplitSubHyperplane(null, sub) :
-                   new SplitSubHyperplane(sub, null);
-        }
-
-        // the lines do intersect
-        final boolean direct = FastMath.sin(otherLine.angle - angle) < 0;
-        final Point1D x      = (Point1D) otherLine.toSubSpace(crossing);
-        final SubHyperplane subPlus  = new SubHyperplane(new OrientedPoint(x, !direct));
-        final SubHyperplane subMinus = new SubHyperplane(new OrientedPoint(x, direct));
-
-        final BSPTree splitTree =
-            sub.getRemainingRegion().getTree(false).split(subMinus);
-        final BSPTree plusTree  = Region.isEmpty(splitTree.getPlus()) ?
-                                  new BSPTree(Boolean.FALSE) :
-                                  new BSPTree(subPlus, new BSPTree(Boolean.FALSE),
-                                              splitTree.getPlus(), null);
-        final BSPTree minusTree = Region.isEmpty(splitTree.getMinus()) ?
-                                  new BSPTree(Boolean.FALSE) :
-                                  new BSPTree(subMinus, new BSPTree(Boolean.FALSE),
-                                              splitTree.getMinus(), null);
-
-        return new SplitSubHyperplane(new SubHyperplane(otherLine.copySelf(),
-                                                        new IntervalsSet(plusTree)),
-                                                        new SubHyperplane(otherLine.copySelf(),
-                                                                          new IntervalsSet(minusTree)));
-
-    }
-
     /** Get a {@link org.apache.commons.math.geometry.partitioning.Transform
      * Transform} embedding an affine transform.
      * @param transform affine transform to embed (must be inversible
@@ -419,12 +338,13 @@ public class Line implements Hyperplane 
      * apply(Hyperplane)} method would work only for some lines, and
      * fail for other ones)
      * @return a new transform that can be applied to either {@link
-     * Point2D Point2D}, {@link Line Line} or {@link
+     * Vector2D Vector2D}, {@link Line Line} or {@link
      * org.apache.commons.math.geometry.partitioning.SubHyperplane
      * SubHyperplane} instances
      * @exception MathIllegalArgumentException if the transform is non invertible
      */
-    public static Transform getTransform(final AffineTransform transform) throws MathIllegalArgumentException {
+    public static Transform<Euclidean2D, Euclidean1D> getTransform(final AffineTransform transform)
+        throws MathIllegalArgumentException {
         return new LineTransform(transform);
     }
 
@@ -435,7 +355,7 @@ public class Line implements Hyperplane 
      * applied to a large number of lines (for example to a large
      * polygon)./<p>
      */
-    private static class LineTransform implements Transform {
+    private static class LineTransform implements Transform<Euclidean2D, Euclidean1D> {
 
         // CHECKSTYLE: stop JavadocVariable check
         private double cXX;
@@ -478,16 +398,16 @@ public class Line implements Hyperplane 
         }
 
         /** {@inheritDoc} */
-        public Point apply(final Point point) {
-            final Point2D p2D = (Point2D) point;
+        public Vector2D apply(final Vector<Euclidean2D> point) {
+            final Vector2D p2D = (Vector2D) point;
             final double  x   = p2D.getX();
             final double  y   = p2D.getY();
-            return new Point2D(cXX * x + cXY * y + cX1,
+            return new Vector2D(cXX * x + cXY * y + cX1,
                                cYX * x + cYY * y + cY1);
         }
 
         /** {@inheritDoc} */
-        public Hyperplane apply(final Hyperplane hyperplane) {
+        public Line apply(final Hyperplane<Euclidean2D> hyperplane) {
             final Line   line    = (Line) hyperplane;
             final double rOffset = c1X * line.cos + c1Y * line.sin + c11 * line.originOffset;
             final double rCos    = cXX * line.cos + cXY * line.sin;
@@ -499,12 +419,15 @@ public class Line implements Hyperplane 
         }
 
         /** {@inheritDoc} */
-        public SubHyperplane apply(final SubHyperplane sub,
-                                   final Hyperplane original, final Hyperplane transformed) {
-            final OrientedPoint op = (OrientedPoint) sub.getHyperplane();
-            final Point1D newLoc =
-                (Point1D) transformed.toSubSpace(apply(original.toSpace(op.getLocation())));
-            return new SubHyperplane(new OrientedPoint(newLoc, op.isDirect()));
+        public SubHyperplane<Euclidean1D> apply(final SubHyperplane<Euclidean1D> sub,
+                                                final Hyperplane<Euclidean2D> original,
+                                                final Hyperplane<Euclidean2D> transformed) {
+            final OrientedPoint op     = (OrientedPoint) sub.getHyperplane();
+            final Line originalLine    = (Line) original;
+            final Line transformedLine = (Line) transformed;
+            final Vector1D newLoc =
+                transformedLine.toSubSpace(apply(originalLine.toSpace(op.getLocation())));
+            return new OrientedPoint(newLoc, op.isDirect()).wholeHyperplane();
         }
 
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/NestedLoops.java Fri Jun  3 18:08:12 2011
@@ -17,44 +17,43 @@
 package org.apache.commons.math.geometry.euclidean.twod;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
-import org.apache.commons.math.geometry.euclidean.oned.OrientedPoint;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
-import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
 import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
 
 /** This class represent a tree of nested 2D boundary loops.
 
- * <p>This class is used during Piece instances construction.
- * Beams are built using the outline edges as
- * representative of facets, the orientation of these facets are
+ * <p>This class is used for piecewise polygons construction.
+ * Polygons are built using the outline edges as
+ * representative of boundaries, the orientation of these lines are
  * meaningful. However, we want to allow the user to specify its
  * outline loops without having to take care of this orientation. This
  * class is devoted to correct mis-oriented loops.<p>
 
- * <p>Orientation is computed assuming the piece is finite, i.e. the
- * outermost loops have their exterior side facing points at infinity,
- * and hence are oriented counter-clockwise. The orientation of
+ * <p>Orientation is computed assuming the piecewise polygon is finite,
+ * i.e. the outermost loops have their exterior side facing points at
+ * infinity, and hence are oriented counter-clockwise. The orientation of
  * internal loops is computed as the reverse of the orientation of
  * their immediate surrounding loop.</p>
 
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
 class NestedLoops {
 
     /** Boundary loop. */
-    private Point2D[] loop;
+    private Vector2D[] loop;
 
     /** Surrounded loops. */
     private ArrayList<NestedLoops> surrounded;
 
     /** Polygon enclosing a finite region. */
-    private Region polygon;
+    private Region<Euclidean2D> polygon;
 
     /** Indicator for original loop orientation. */
     private boolean originalIsClockwise;
@@ -74,7 +73,7 @@ class NestedLoops {
      * @param loop boundary loop (will be reversed in place if needed)
      * @exception MathIllegalArgumentException if an outline has an open boundary loop
      */
-    private NestedLoops(final Point2D[] loop) throws MathIllegalArgumentException {
+    private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {
 
         if (loop[0] == null) {
             throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
@@ -84,23 +83,21 @@ class NestedLoops {
         surrounded = new ArrayList<NestedLoops>();
 
         // build the polygon defined by the loop
-        final ArrayList<SubHyperplane> edges = new ArrayList<SubHyperplane>();
-        Point2D current = loop[loop.length - 1];
+        final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
+        Vector2D current = loop[loop.length - 1];
         for (int i = 0; i < loop.length; ++i) {
-            final Point2D previous = current;
+            final Vector2D previous = current;
             current = loop[i];
             final Line   line   = new Line(previous, current);
-            final Region region =  Region.buildConvex(Arrays.asList(new Hyperplane[] {
-                new OrientedPoint((Point1D) line.toSubSpace(previous), false),
-                new OrientedPoint((Point1D) line.toSubSpace(current),  true)
-            }));
-            edges.add(new SubHyperplane(line, region));
+            final IntervalsSet region = 
+                new IntervalsSet(line.toSubSpace(previous).getX(), line.toSubSpace(current).getX());
+            edges.add(new SubLine(line, region));
         }
         polygon = new PolygonsSet(edges);
 
         // ensure the polygon encloses a finite region of the plane
         if (Double.isInfinite(polygon.getSize())) {
-            polygon = polygon.getComplement();
+            polygon = new RegionFactory<Euclidean2D>().getComplement(polygon);
             originalIsClockwise = false;
         } else {
             originalIsClockwise = true;
@@ -113,7 +110,7 @@ class NestedLoops {
      * @exception MathIllegalArgumentException if an outline has crossing
      * boundary loops or open boundary loops
      */
-    public void add(final Point2D[] bLoop) throws MathIllegalArgumentException {
+    public void add(final Vector2D[] bLoop) throws MathIllegalArgumentException {
         add(new NestedLoops(bLoop));
     }
 
@@ -142,8 +139,9 @@ class NestedLoops {
         }
 
         // we should be separate from the remaining children
+        RegionFactory<Euclidean2D> factory = new RegionFactory<Euclidean2D>();
         for (final NestedLoops child : surrounded) {
-            if (!Region.intersection(node.polygon, child.polygon).isEmpty()) {
+            if (!factory.intersection(node.polygon, child.polygon).isEmpty()) {
                 throw new MathIllegalArgumentException(LocalizedFormats.CROSSING_BOUNDARY_LOOPS);
             }
         }
@@ -154,7 +152,7 @@ class NestedLoops {
 
     /** Correct the orientation of the loops contained in the tree.
      * <p>This is this method that really inverts the loops that where
-     * provided through the {@link #add(Point2D[]) add} method if
+     * provided through the {@link #add(Vector2D[]) add} method if
      * they are mis-oriented</p>
      */
     public void correctOrientation() {
@@ -174,7 +172,7 @@ class NestedLoops {
             int min = -1;
             int max = loop.length;
             while (++min < --max) {
-                final Point2D tmp = loop[min];
+                final Vector2D tmp = loop[min];
                 loop[min] = loop[max];
                 loop[max] = tmp;
             }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/PolygonsSet.java Fri Jun  3 18:08:12 2011
@@ -17,25 +17,27 @@
 package org.apache.commons.math.geometry.euclidean.twod;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.exception.MathInternalError;
+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.BSPTree;
-import org.apache.commons.math.geometry.partitioning.Hyperplane;
 import org.apache.commons.math.geometry.partitioning.Region;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
+import org.apache.commons.math.geometry.partitioning.AbstractRegion;
 import org.apache.commons.math.geometry.partitioning.utilities.AVLTree;
 import org.apache.commons.math.util.FastMath;
 
 /** This class represents a 2D region: a set of polygons.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-public class PolygonsSet extends Region {
+public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
 
     /** Vertices organized as boundary loops. */
-    private Point2D[][] vertices;
+    private Vector2D[][] vertices;
 
     /** Build a polygons set representing the whole real line.
      */
@@ -52,7 +54,7 @@ public class PolygonsSet extends Region 
      * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p>
      * @param tree inside/outside BSP tree representing the region
      */
-    public PolygonsSet(final BSPTree tree) {
+    public PolygonsSet(final BSPTree<Euclidean2D> tree) {
         super(tree);
     }
 
@@ -63,7 +65,7 @@ public class PolygonsSet extends Region 
      * 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
+     * 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
@@ -76,7 +78,7 @@ public class PolygonsSet extends Region 
      * @param boundary collection of boundary elements, as a
      * collection of {@link SubHyperplane SubHyperplane} objects
      */
-    public PolygonsSet(final Collection<SubHyperplane> boundary) {
+    public PolygonsSet(final Collection<SubHyperplane<Euclidean2D>> boundary) {
         super(boundary);
     }
 
@@ -88,7 +90,7 @@ public class PolygonsSet extends Region 
      */
     public PolygonsSet(final double xMin, final double xMax,
                        final double yMin, final double yMax) {
-        this(buildConvex(boxBoundary(xMin, xMax, yMin, yMax)).getTree(false));
+        super(boxBoundary(xMin, xMax, yMin, yMax));
     }
 
     /** Create a list of hyperplanes representing the boundary of a box.
@@ -98,42 +100,42 @@ public class PolygonsSet extends Region 
      * @param yMax high bound along the y direction
      * @return boundary of the box
      */
-    private static List<Hyperplane> boxBoundary(final double xMin, final double xMax,
-                                                final double yMin, final double yMax) {
-        final Point2D minMin = new Point2D(xMin, yMin);
-        final Point2D minMax = new Point2D(xMin, yMax);
-        final Point2D maxMin = new Point2D(xMax, yMin);
-        final Point2D maxMax = new Point2D(xMax, yMax);
-        return Arrays.asList(new Hyperplane[] {
+    private static Line[] boxBoundary(final double xMin, final double xMax,
+                                      final double yMin, final double yMax) {
+        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)
-        });
+        };
     }
 
     /** {@inheritDoc} */
-    public Region buildNew(final BSPTree tree) {
+    public PolygonsSet buildNew(final BSPTree<Euclidean2D> tree) {
         return new PolygonsSet(tree);
     }
 
     /** {@inheritDoc} */
     protected void computeGeometricalProperties() {
 
-        final Point2D[][] v = getVertices();
+        final Vector2D[][] v = getVertices();
 
         if (v.length == 0) {
             if ((Boolean) getTree(false).getAttribute()) {
                 setSize(Double.POSITIVE_INFINITY);
-                setBarycenter(Point2D.UNDEFINED);
+                setBarycenter(Vector2D.NaN);
             } else {
                 setSize(0);
-                setBarycenter(new Point2D(0, 0));
+                setBarycenter(new Vector2D(0, 0));
             }
         } else if (v[0][0] == null) {
             // there is at least one open-loop: the polygon is infinite
             setSize(Double.POSITIVE_INFINITY);
-            setBarycenter(Point2D.UNDEFINED);
+            setBarycenter(Vector2D.NaN);
         } else {
             // all loops are closed, we compute some integrals around the shape
 
@@ -141,14 +143,14 @@ public class PolygonsSet extends Region 
             double sumX = 0;
             double sumY = 0;
 
-            for (Point2D[] loop : v) {
-                double x1 = loop[loop.length - 1].x;
-                double y1 = loop[loop.length - 1].y;
-                for (final Point2D point : loop) {
+            for (Vector2D[] loop : v) {
+                double x1 = loop[loop.length - 1].getX();
+                double y1 = loop[loop.length - 1].getY();
+                for (final Vector2D point : loop) {
                     final double x0 = x1;
                     final double y0 = y1;
-                    x1 = point.x;
-                    y1 = point.y;
+                    x1 = point.getX();
+                    y1 = point.getY();
                     final double factor = x0 * y1 - y0 * x1;
                     sum  += factor;
                     sumX += factor * (x0 + x1);
@@ -159,10 +161,10 @@ public class PolygonsSet extends Region 
             if (sum < 0) {
                 // the polygon as a finite outside surrounded by an infinite inside
                 setSize(Double.POSITIVE_INFINITY);
-                setBarycenter(Point2D.UNDEFINED);
+                setBarycenter(Vector2D.NaN);
             } else {
                 setSize(sum / 2);
-                setBarycenter(new Point2D(sumX / (3 * sum), sumY / (3 * sum)));
+                setBarycenter(new Vector2D(sumX / (3 * sum), sumY / (3 * sum)));
             }
 
         }
@@ -192,19 +194,19 @@ public class PolygonsSet extends Region 
      * loops with the open loops first (the returned value is guaranteed
      * to be non-null)
      */
-    public Point2D[][] getVertices() {
+    public Vector2D[][] getVertices() {
         if (vertices == null) {
             if (getTree(false).getCut() == null) {
-                vertices = new Point2D[0][];
+                vertices = new Vector2D[0][];
             } else {
 
-                // sort the segmfinal ents according to their start point
+                // sort the segments according to their start point
                 final SegmentsBuilder visitor = new SegmentsBuilder();
                 getTree(true).visit(visitor);
                 final AVLTree<Segment> sorted = visitor.getSorted();
 
                 // identify the loops, starting from the open ones
-                // (their start segments final are naturally at the sorted set beginning)
+                // (their start segments are naturally at the sorted set beginning)
                 final ArrayList<List<Segment>> loops = new ArrayList<List<Segment>>();
                 while (!sorted.isEmpty()) {
                     final AVLTree<Segment>.Node node = sorted.getSmallest();
@@ -215,31 +217,30 @@ public class PolygonsSet extends Region 
                 }
 
                 // tranform the loops in an array of arrays of points
-                vertices = new Point2D[loops.size()][];
+                vertices = new Vector2D[loops.size()][];
                 int i = 0;
 
                 for (final List<Segment> loop : loops) {
                     if (loop.size() < 2) {
-                        // sifinal ngle infinite line
-                        final Line line = ((Segment) loop.get(0)).getLine();
-                        vertices[i++] = new Point2D[] {
+                        // single infinite line
+                        final Line line = loop.get(0).getLine();
+                        vertices[i++] = new Vector2D[] {
                             null,
-                            (Point2D) line.toSpace(new Point1D(-Float.MAX_VALUE)),
-                            (Point2D) line.toSpace(new Point1D(+Float.MAX_VALUE))
+                            line.toSpace(new Vector1D(-Float.MAX_VALUE)),
+                            line.toSpace(new Vector1D(+Float.MAX_VALUE))
                         };
-                    } else if (((Segment) loop.get(0)).getStart() == null) {
-                        // open lofinal op with at least one real point
-                        final Point2D[] array = new Point2D[loop.size() + 2];
+                    } else if (loop.get(0).getStart() == null) {
+                        // open loop with at least one real point
+                        final Vector2D[] array = new Vector2D[loop.size() + 2];
                         int j = 0;
                         for (Segment segment : loop) {
 
                             if (j == 0) {
                                 // null point and first dummy point
-                                double x =
-                                    ((Point1D) segment.getLine().toSubSpace(segment.getEnd())).getAbscissa();
+                                double x = segment.getLine().toSubSpace(segment.getEnd()).getX();
                                 x -= FastMath.max(1.0, FastMath.abs(x / 2));
                                 array[j++] = null;
-                                array[j++] = (Point2D) segment.getLine().toSpace(new Point1D(x));
+                                array[j++] = segment.getLine().toSpace(new Vector1D(x));
                             }
 
                             if (j < (array.length - 1)) {
@@ -249,16 +250,15 @@ public class PolygonsSet extends Region 
 
                             if (j == (array.length - 1)) {
                                 // last dummy point
-                                double x =
-                                    ((Point1D) segment.getLine().toSubSpace(segment.getStart())).getAbscissa();
+                                double x = segment.getLine().toSubSpace(segment.getStart()).getX();
                                 x += FastMath.max(1.0, FastMath.abs(x / 2));
-                                array[j++] = (Point2D) segment.getLine().toSpace(new Point1D(x));
+                                array[j++] = segment.getLine().toSpace(new Vector1D(x));
                             }
 
                         }
                         vertices[i++] = array;
                     } else {
-                        final Point2D[] array = new Point2D[loop.size()];
+                        final Vector2D[] array = new Vector2D[loop.size()];
                         int j = 0;
                         for (Segment segment : loop) {
                             array[j++] = segment.getStart();
@@ -285,10 +285,10 @@ public class PolygonsSet extends Region 
                                      final AVLTree<Segment> sorted) {
 
         final ArrayList<Segment> loop = new ArrayList<Segment>();
-        Segment segment = (Segment) node.getElement();
+        Segment segment = node.getElement();
         loop.add(segment);
-        final Point2D globalStart = segment.getStart();
-        Point2D end = segment.getEnd();
+        final Vector2D globalStart = segment.getStart();
+        Vector2D end = segment.getEnd();
         node.delete();
 
         // is this an open or a closed loop ?
@@ -333,7 +333,7 @@ public class PolygonsSet extends Region 
         }
 
         if ((end == null) && !open) {
-            throw new RuntimeException("internal error");
+            throw new MathInternalError();
         }
 
         return loop;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Segment.java Fri Jun  3 18:08:12 2011
@@ -19,15 +19,16 @@ package org.apache.commons.math.geometry
 import org.apache.commons.math.geometry.partitioning.utilities.OrderedTuple;
 
 /** This class holds segments information before they are connected.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
 class Segment implements Comparable<Segment> {
 
     /** Start point of the segment. */
-    private final Point2D      start;
+    private final Vector2D      start;
 
     /** End point of the segments. */
-    private final Point2D      end;
+    private final Vector2D      end;
 
     /** Line containing the segment. */
     private final Line         line;
@@ -40,13 +41,13 @@ class Segment implements Comparable<Segm
      * @param end end point of the segment
      * @param line line containing the segment
      */
-    public Segment(final Point2D start, final Point2D end, final Line line) {
+    public Segment(final Vector2D start, final Vector2D end, final Line line) {
         this.start  = start;
         this.end    = end;
         this.line   = line;
         sortingKey = (start == null) ?
                      new OrderedTuple(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY) :
-                     new OrderedTuple(start.x, start.y);
+                     new OrderedTuple(start.getX(), start.getY());
     }
 
     /** Build a dummy segment.
@@ -58,24 +59,24 @@ class Segment implements Comparable<Segm
      * @param dx abscissa offset from the start point
      * @param dy ordinate offset from the start point
      */
-    public Segment(final Point2D start, final double dx, final double dy) {
+    public Segment(final Vector2D start, final double dx, final double dy) {
         this.start = null;
         this.end   = null;
         this.line  = null;
-        sortingKey = new OrderedTuple(start.x + dx, start.y + dy);
+        sortingKey = new OrderedTuple(start.getX() + dx, start.getY() + dy);
     }
 
     /** Get the start point of the segment.
      * @return start point of the segment
      */
-    public Point2D getStart() {
+    public Vector2D getStart() {
         return start;
     }
 
     /** Get the end point of the segment.
      * @return end point of the segment
      */
-    public Point2D getEnd() {
+    public Vector2D getEnd() {
         return end;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SegmentBuilder.java Fri Jun  3 18:08:12 2011
@@ -18,19 +18,22 @@ package org.apache.commons.math.geometry
 
 import java.util.List;
 
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
 import org.apache.commons.math.geometry.euclidean.oned.Interval;
 import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+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.BoundaryAttribute;
+import org.apache.commons.math.geometry.partitioning.BoundaryAttribute;
 import org.apache.commons.math.geometry.partitioning.SubHyperplane;
 import org.apache.commons.math.geometry.partitioning.utilities.AVLTree;
 
 /** Visitor building segments.
- * @version $Revision$ $Date$
+ * @version $Id:$
+ * @since 3.0
  */
-class SegmentsBuilder implements BSPTreeVisitor {
+class SegmentsBuilder implements BSPTreeVisitor<Euclidean2D> {
 
     /** Sorted segments. */
     private AVLTree<Segment> sorted;
@@ -41,13 +44,14 @@ class SegmentsBuilder implements BSPTree
     }
 
     /** {@inheritDoc} */
-    public Order visitOrder(final BSPTree node) {
+    public Order visitOrder(final BSPTree<Euclidean2D> node) {
         return Order.MINUS_SUB_PLUS;
     }
 
     /** {@inheritDoc} */
-    public void visitInternalNode(final BSPTree node) {
-        final BoundaryAttribute attribute = (BoundaryAttribute) node.getAttribute();
+    public void visitInternalNode(final BSPTree<Euclidean2D> node) {
+        @SuppressWarnings("unchecked")
+        final BoundaryAttribute<Euclidean2D> attribute = (BoundaryAttribute<Euclidean2D>) node.getAttribute();
         if (attribute.getPlusOutside() != null) {
             addContribution(attribute.getPlusOutside(), false);
         }
@@ -57,21 +61,24 @@ class SegmentsBuilder implements BSPTree
     }
 
     /** {@inheritDoc} */
-    public void visitLeafNode(final BSPTree node) {
+    public void visitLeafNode(final BSPTree<Euclidean2D> node) {
     }
 
     /** Add he contribution of a boundary facet.
      * @param sub boundary facet
      * @param reversed if true, the facet has the inside on its plus side
      */
-    private void addContribution(final SubHyperplane sub, final boolean reversed) {
+    private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
+        @SuppressWarnings("unchecked")
+        final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
+            (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
         final Line line      = (Line) sub.getHyperplane();
-        final List<Interval> intervals = ((IntervalsSet) sub.getRemainingRegion()).asList();
+        final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
         for (final Interval i : intervals) {
-            final Point2D start = Double.isInfinite(i.getLower()) ?
-                                  null : (Point2D) line.toSpace(new Point1D(i.getLower()));
-            final Point2D end   = Double.isInfinite(i.getUpper()) ?
-                                  null : (Point2D) line.toSpace(new Point1D(i.getUpper()));
+            final Vector2D start = Double.isInfinite(i.getLower()) ?
+                                  null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
+            final Vector2D end   = Double.isInfinite(i.getUpper()) ?
+                                  null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
             if (reversed) {
                 sorted.insert(new Segment(end, start, line.getReverse()));
             } else {

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java?rev=1131127&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/SubLine.java Fri Jun  3 18:08:12 2011
@@ -0,0 +1,108 @@
+/*
+ * 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.twod;
+
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
+import org.apache.commons.math.geometry.euclidean.oned.OrientedPoint;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
+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;
+import org.apache.commons.math.util.FastMath;
+
+/** This class represents a sub-hyperplane for {@link Line}.
+ * @version $Id:$
+ * @since 3.0
+ */
+public class SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> {
+
+    /** Simple constructor.
+     * @param hyperplane underlying hyperplane
+     * @param remainingRegion remaining region of the hyperplane
+     */
+    public SubLine(final Hyperplane<Euclidean2D> hyperplane,
+                   final Region<Euclidean1D> remainingRegion) {
+        super(hyperplane, remainingRegion);
+    }
+
+    /** {@inheritDoc} */
+    protected AbstractSubHyperplane<Euclidean2D, Euclidean1D> buildNew(final Hyperplane<Euclidean2D> hyperplane,
+                                                                       final Region<Euclidean1D> remainingRegion) {
+        return new SubLine(hyperplane, remainingRegion);
+    }
+
+    /** {@inheritDoc} */
+    public Side side(final Hyperplane<Euclidean2D> hyperplane) {
+
+        final Line    thisLine  = (Line) getHyperplane();
+        final Line    otherLine = (Line) hyperplane;
+        final Vector2D crossing  = thisLine.intersection(otherLine);
+
+        if (crossing == null) {
+            // the lines are parallel,
+            final double global = otherLine.getOffset(thisLine);
+            return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
+        }
+
+        // the lines do intersect
+        final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
+        final Vector1D x = (Vector1D) thisLine.toSubSpace(crossing);
+        return getRemainingRegion().side(new OrientedPoint(x, direct));
+
+    }
+
+    /** {@inheritDoc} */
+    public SplitSubHyperplane<Euclidean2D> split(final Hyperplane<Euclidean2D> hyperplane) {
+
+        final Line    thisLine  = (Line) getHyperplane();
+        final Line    otherLine = (Line) hyperplane;
+        final Vector2D crossing  = thisLine.intersection(otherLine);
+
+        if (crossing == null) {
+            // the lines are parallel
+            final double global = otherLine.getOffset(thisLine);
+            return (global < -1.0e-10) ?
+                   new SplitSubHyperplane<Euclidean2D>(null, this) :
+                   new SplitSubHyperplane<Euclidean2D>(this, null);
+        }
+
+        // the lines do intersect
+        final boolean direct = FastMath.sin(thisLine.getAngle() - otherLine.getAngle()) < 0;
+        final Vector1D x      = (Vector1D) thisLine.toSubSpace(crossing);
+        final SubHyperplane<Euclidean1D> subPlus  = new OrientedPoint(x, !direct).wholeHyperplane();
+        final SubHyperplane<Euclidean1D> subMinus = new OrientedPoint(x,  direct).wholeHyperplane();
+
+        final BSPTree<Euclidean1D> splitTree = getRemainingRegion().getTree(false).split(subMinus);
+        final BSPTree<Euclidean1D> plusTree  = getRemainingRegion().isEmpty(splitTree.getPlus()) ?
+                                               new BSPTree<Euclidean1D>(Boolean.FALSE) :
+                                               new BSPTree<Euclidean1D>(subPlus, new BSPTree<Euclidean1D>(Boolean.FALSE),
+                                                                        splitTree.getPlus(), null);
+        final BSPTree<Euclidean1D> minusTree = getRemainingRegion().isEmpty(splitTree.getMinus()) ?
+                                               new BSPTree<Euclidean1D>(Boolean.FALSE) :
+                                               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)));
+
+    }
+
+}

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

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

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/oned/IntervalsSetTest.java Fri Jun  3 18:08:12 2011
@@ -20,8 +20,9 @@ import java.util.List;
 
 import org.apache.commons.math.geometry.euclidean.oned.Interval;
 import org.apache.commons.math.geometry.euclidean.oned.IntervalsSet;
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
 import org.apache.commons.math.geometry.partitioning.Region;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -32,12 +33,12 @@ public class IntervalsSetTest {
     public void testInterval() {
         IntervalsSet set = new IntervalsSet(2.3, 5.7);
         Assert.assertEquals(3.4, set.getSize(), 1.0e-10);
-        Assert.assertEquals(4.0, ((Point1D) set.getBarycenter()).getAbscissa(), 1.0e-10);
-        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(2.3)));
-        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(5.7)));
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(1.2)));
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(8.7)));
-        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Point1D(3.0)));
+        Assert.assertEquals(4.0, ((Vector1D) set.getBarycenter()).getX(), 1.0e-10);
+        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(2.3)));
+        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(5.7)));
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(1.2)));
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.7)));
+        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(3.0)));
         Assert.assertEquals(2.3, set.getInf(), 1.0e-10);
         Assert.assertEquals(5.7, set.getSup(), 1.0e-10);
     }
@@ -45,17 +46,17 @@ public class IntervalsSetTest {
     @Test
     public void testInfinite() {
         IntervalsSet set = new IntervalsSet(9.0, Double.POSITIVE_INFINITY);
-        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(9.0)));
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(8.4)));
+        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(9.0)));
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.4)));
         for (double e = 1.0; e <= 6.0; e += 1.0) {
             Assert.assertEquals(Region.Location.INSIDE,
-                                set.checkPoint(new Point1D(FastMath.pow(10.0, e))));
+                                set.checkPoint(new Vector1D(FastMath.pow(10.0, e))));
         }
         Assert.assertTrue(Double.isInfinite(set.getSize()));
         Assert.assertEquals(9.0, set.getInf(), 1.0e-10);
         Assert.assertTrue(Double.isInfinite(set.getSup()));
 
-        set = (IntervalsSet) set.getComplement();
+        set = (IntervalsSet) new RegionFactory<Euclidean1D>().getComplement(set);
         Assert.assertEquals(9.0, set.getSup(), 1.0e-10);
         Assert.assertTrue(Double.isInfinite(set.getInf()));
 
@@ -63,22 +64,23 @@ public class IntervalsSetTest {
 
     @Test
     public void testMultiple() {
+        RegionFactory<Euclidean1D> factory = new RegionFactory<Euclidean1D>();
         IntervalsSet set = (IntervalsSet)
-        Region.intersection(Region.union(Region.difference(new IntervalsSet(1.0, 6.0),
-                                                           new IntervalsSet(3.0, 5.0)),
-                                                           new IntervalsSet(9.0, Double.POSITIVE_INFINITY)),
-                                                           new IntervalsSet(Double.NEGATIVE_INFINITY, 11.0));
+        factory.intersection(factory.union(factory.difference(new IntervalsSet(1.0, 6.0),
+                                                              new IntervalsSet(3.0, 5.0)),
+                                                              new IntervalsSet(9.0, Double.POSITIVE_INFINITY)),
+                                                              new IntervalsSet(Double.NEGATIVE_INFINITY, 11.0));
         Assert.assertEquals(5.0, set.getSize(), 1.0e-10);
-        Assert.assertEquals(5.9, ((Point1D) set.getBarycenter()).getAbscissa(), 1.0e-10);
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(0.0)));
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(4.0)));
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(8.0)));
-        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Point1D(12.0)));
-        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Point1D(1.2)));
-        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Point1D(5.9)));
-        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Point1D(9.01)));
-        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(5.0)));
-        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Point1D(11.0)));
+        Assert.assertEquals(5.9, ((Vector1D) set.getBarycenter()).getX(), 1.0e-10);
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(0.0)));
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(4.0)));
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.0)));
+        Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(12.0)));
+        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(1.2)));
+        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(5.9)));
+        Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(9.01)));
+        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(5.0)));
+        Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(11.0)));
         Assert.assertEquals( 1.0, set.getInf(), 1.0e-10);
         Assert.assertEquals(11.0, set.getSup(), 1.0e-10);
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PlaneTest.java Fri Jun  3 18:08:12 2011
@@ -18,7 +18,6 @@ package org.apache.commons.math.geometry
 
 import org.apache.commons.math.geometry.euclidean.threed.Line;
 import org.apache.commons.math.geometry.euclidean.threed.Plane;
-import org.apache.commons.math.geometry.euclidean.threed.Point3D;
 import org.apache.commons.math.geometry.euclidean.threed.Rotation;
 import org.apache.commons.math.geometry.euclidean.threed.Vector3D;
 import org.junit.Assert;
@@ -29,22 +28,22 @@ public class PlaneTest {
     @Test
     public void testContains() {
         Plane p = new Plane(new Vector3D(0, 0, 1), new Vector3D(0, 0, 1));
-        Assert.assertTrue(p.contains(new Point3D(0, 0, 1)));
-        Assert.assertTrue(p.contains(new Point3D(17, -32, 1)));
-        Assert.assertTrue(! p.contains(new Point3D(17, -32, 1.001)));
+        Assert.assertTrue(p.contains(new Vector3D(0, 0, 1)));
+        Assert.assertTrue(p.contains(new Vector3D(17, -32, 1)));
+        Assert.assertTrue(! p.contains(new Vector3D(17, -32, 1.001)));
     }
 
     @Test
     public void testOffset() {
         Vector3D p1 = new Vector3D(1, 1, 1);
         Plane p = new Plane(p1, new Vector3D(0.2, 0, 0));
-        Assert.assertEquals(-5.0, p.getOffset(new Point3D(-4, 0, 0)), 1.0e-10);
-        Assert.assertEquals(+5.0, p.getOffset(new Point3D(6, 10, -12)), 1.0e-10);
+        Assert.assertEquals(-5.0, p.getOffset(new Vector3D(-4, 0, 0)), 1.0e-10);
+        Assert.assertEquals(+5.0, p.getOffset(new Vector3D(6, 10, -12)), 1.0e-10);
         Assert.assertEquals(0.3,
-                            p.getOffset(new Point3D(1.0, p1, 0.3, p.getNormal())),
+                            p.getOffset(new Vector3D(1.0, p1, 0.3, p.getNormal())),
                             1.0e-10);
         Assert.assertEquals(-0.3,
-                            p.getOffset(new Point3D(1.0, p1, -0.3, p.getNormal())),
+                            p.getOffset(new Vector3D(1.0, p1, -0.3, p.getNormal())),
                             1.0e-10);
     }
 
@@ -56,9 +55,9 @@ public class PlaneTest {
 
     @Test
     public void testThreePoints() {
-        Point3D p1 = new Point3D(1.2, 3.4, -5.8);
-        Point3D p2 = new Point3D(3.4, -5.8, 1.2);
-        Point3D p3 = new Point3D(-2.0, 4.3, 0.7);
+        Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
+        Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
+        Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
         Plane    p  = new Plane(p1, p2, p3);
         Assert.assertTrue(p.contains(p1));
         Assert.assertTrue(p.contains(p2));
@@ -67,9 +66,9 @@ public class PlaneTest {
 
     @Test
     public void testRotate() {
-        Point3D p1 = new Point3D(1.2, 3.4, -5.8);
-        Point3D p2 = new Point3D(3.4, -5.8, 1.2);
-        Point3D p3 = new Point3D(-2.0, 4.3, 0.7);
+        Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
+        Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
+        Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
         Plane    p  = new Plane(p1, p2, p3);
         Vector3D oldNormal = p.getNormal();
 
@@ -92,9 +91,9 @@ public class PlaneTest {
 
     @Test
     public void testTranslate() {
-        Point3D p1 = new Point3D(1.2, 3.4, -5.8);
-        Point3D p2 = new Point3D(3.4, -5.8, 1.2);
-        Point3D p3 = new Point3D(-2.0, 4.3, 0.7);
+        Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
+        Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
+        Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
         Plane    p  = new Plane(p1, p2, p3);
 
         p = p.translate(new Vector3D(2.0, p.getU(), -1.5, p.getV()));
@@ -118,7 +117,7 @@ public class PlaneTest {
     public void testIntersection() {
         Plane p = new Plane(new Vector3D(1, 2, 3), new Vector3D(-4, 1, -5));
         Line  l = new Line(new Vector3D(0.2, -3.5, 0.7), new Vector3D(1, 1, -1));
-        Point3D point = p.intersection(l);
+        Vector3D point = p.intersection(l);
         Assert.assertTrue(p.contains(point));
         Assert.assertTrue(l.contains(point));
         Assert.assertNull(p.intersection(new Line(new Vector3D(10, 10, 10),

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/PolyhedronsSetTest.java Fri Jun  3 18:08:12 2011
@@ -16,20 +16,13 @@
  */
 package org.apache.commons.math.geometry.euclidean.threed;
 
-import java.util.Arrays;
-
-import org.apache.commons.math.geometry.euclidean.threed.Plane;
-import org.apache.commons.math.geometry.euclidean.threed.Point3D;
-import org.apache.commons.math.geometry.euclidean.threed.PolyhedronsSet;
-import org.apache.commons.math.geometry.euclidean.threed.Rotation;
-import org.apache.commons.math.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
 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.BSPTree;
 import org.apache.commons.math.geometry.partitioning.BSPTreeVisitor;
-import org.apache.commons.math.geometry.partitioning.Hyperplane;
+import org.apache.commons.math.geometry.partitioning.BoundaryAttribute;
 import org.apache.commons.math.geometry.partitioning.Region;
-import org.apache.commons.math.geometry.partitioning.SubHyperplane;
+import org.apache.commons.math.geometry.partitioning.RegionFactory;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -53,41 +46,41 @@ public class PolyhedronsSetTest {
                     boolean zOK = (z >= 0.0) && (z <= 1.0);
                     Region.Location expected =
                         (xOK && yOK && zOK) ? Region.Location.INSIDE : Region.Location.OUTSIDE;
-                    Assert.assertEquals(expected, tree.checkPoint(new Point3D(x, y, z)));
+                    Assert.assertEquals(expected, tree.checkPoint(new Vector3D(x, y, z)));
                 }
             }
         }
-        checkPoints(Region.Location.BOUNDARY, tree, new Point3D[] {
-            new Point3D(0.0, 0.5, 0.5),
-            new Point3D(1.0, 0.5, 0.5),
-            new Point3D(0.5, 0.0, 0.5),
-            new Point3D(0.5, 1.0, 0.5),
-            new Point3D(0.5, 0.5, 0.0),
-            new Point3D(0.5, 0.5, 1.0)
+        checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
+            new Vector3D(0.0, 0.5, 0.5),
+            new Vector3D(1.0, 0.5, 0.5),
+            new Vector3D(0.5, 0.0, 0.5),
+            new Vector3D(0.5, 1.0, 0.5),
+            new Vector3D(0.5, 0.5, 0.0),
+            new Vector3D(0.5, 0.5, 1.0)
         });
-        checkPoints(Region.Location.OUTSIDE, tree, new Point3D[] {
-            new Point3D(0.0, 1.2, 1.2),
-            new Point3D(1.0, 1.2, 1.2),
-            new Point3D(1.2, 0.0, 1.2),
-            new Point3D(1.2, 1.0, 1.2),
-            new Point3D(1.2, 1.2, 0.0),
-            new Point3D(1.2, 1.2, 1.0)
+        checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
+            new Vector3D(0.0, 1.2, 1.2),
+            new Vector3D(1.0, 1.2, 1.2),
+            new Vector3D(1.2, 0.0, 1.2),
+            new Vector3D(1.2, 1.0, 1.2),
+            new Vector3D(1.2, 1.2, 0.0),
+            new Vector3D(1.2, 1.2, 1.0)
         });
     }
 
     @Test
     public void testTetrahedron() {
-        Point3D vertex1 = new Point3D(1, 2, 3);
-        Point3D vertex2 = new Point3D(2, 2, 4);
-        Point3D vertex3 = new Point3D(2, 3, 3);
-        Point3D vertex4 = new Point3D(1, 3, 4);
+        Vector3D vertex1 = new Vector3D(1, 2, 3);
+        Vector3D vertex2 = new Vector3D(2, 2, 4);
+        Vector3D vertex3 = new Vector3D(2, 3, 3);
+        Vector3D vertex4 = new Vector3D(1, 3, 4);
+        @SuppressWarnings("unchecked")
         PolyhedronsSet tree =
-            (PolyhedronsSet) Region.buildConvex(Arrays.asList(new Hyperplane[] {
+            (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex(
                 new Plane(vertex3, vertex2, vertex1),
                 new Plane(vertex2, vertex3, vertex4),
                 new Plane(vertex4, vertex3, vertex1),
-                new Plane(vertex1, vertex2, vertex4)
-            }));
+                new Plane(vertex1, vertex2, vertex4));
         Assert.assertEquals(1.0 / 3.0, tree.getSize(), 1.0e-10);
         Assert.assertEquals(2.0 * FastMath.sqrt(3.0), tree.getBoundarySize(), 1.0e-10);
         Vector3D barycenter = (Vector3D) tree.getBarycenter();
@@ -95,18 +88,18 @@ public class PolyhedronsSetTest {
         Assert.assertEquals(2.5, barycenter.getY(), 1.0e-10);
         Assert.assertEquals(3.5, barycenter.getZ(), 1.0e-10);
         double third = 1.0 / 3.0;
-        checkPoints(Region.Location.BOUNDARY, tree, new Point3D[] {
+        checkPoints(Region.Location.BOUNDARY, tree, new Vector3D[] {
             vertex1, vertex2, vertex3, vertex4,
-            new Point3D(third, vertex1, third, vertex2, third, vertex3),
-            new Point3D(third, vertex2, third, vertex3, third, vertex4),
-            new Point3D(third, vertex3, third, vertex4, third, vertex1),
-            new Point3D(third, vertex4, third, vertex1, third, vertex2)
+            new Vector3D(third, vertex1, third, vertex2, third, vertex3),
+            new Vector3D(third, vertex2, third, vertex3, third, vertex4),
+            new Vector3D(third, vertex3, third, vertex4, third, vertex1),
+            new Vector3D(third, vertex4, third, vertex1, third, vertex2)
         });
-        checkPoints(Region.Location.OUTSIDE, tree, new Point3D[] {
-            new Point3D(1, 2, 4),
-            new Point3D(2, 2, 3),
-            new Point3D(2, 3, 4),
-            new Point3D(1, 3, 3)
+        checkPoints(Region.Location.OUTSIDE, tree, new Vector3D[] {
+            new Vector3D(1, 2, 4),
+            new Vector3D(2, 2, 3),
+            new Vector3D(2, 3, 4),
+            new Vector3D(1, 3, 3)
         });
     }
 
@@ -116,13 +109,13 @@ public class PolyhedronsSetTest {
         Vector3D vertex2 = new Vector3D(2.0, 2.4, 4.2);
         Vector3D vertex3 = new Vector3D(2.8, 3.3, 3.7);
         Vector3D vertex4 = new Vector3D(1.0, 3.6, 4.5);
+        @SuppressWarnings("unchecked")
         PolyhedronsSet tree =
-            (PolyhedronsSet) Region.buildConvex(Arrays.asList(new Hyperplane[] {
+            (PolyhedronsSet) new RegionFactory<Euclidean3D>().buildConvex(
                 new Plane(vertex3, vertex2, vertex1),
                 new Plane(vertex2, vertex3, vertex4),
                 new Plane(vertex4, vertex3, vertex1),
-                new Plane(vertex1, vertex2, vertex4)
-            }));
+                new Plane(vertex1, vertex2, vertex4));
         Vector3D barycenter = (Vector3D) tree.getBarycenter();
         Vector3D s = new Vector3D(10.2, 4.3, -6.7);
         Vector3D c = new Vector3D(-0.2, 2.1, -3.2);
@@ -152,29 +145,30 @@ public class PolyhedronsSetTest {
                                                                 1.0, c,
                                                                 1.0, r.applyTo(vertex4.subtract(c)))
         };
-        tree.getTree(true).visit(new BSPTreeVisitor() {
+        tree.getTree(true).visit(new BSPTreeVisitor<Euclidean3D>() {
 
-            public Order visitOrder(BSPTree node) {
+            public Order visitOrder(BSPTree<Euclidean3D> node) {
                 return Order.MINUS_SUB_PLUS;
             }
 
-            public void visitInternalNode(BSPTree node) {
-                Region.BoundaryAttribute attribute =
-                    (Region.BoundaryAttribute) node.getAttribute();
+            public void visitInternalNode(BSPTree<Euclidean3D> node) {
+                @SuppressWarnings("unchecked")
+                BoundaryAttribute<Euclidean3D> attribute =
+                    (BoundaryAttribute<Euclidean3D>) node.getAttribute();
                 if (attribute.getPlusOutside() != null) {
-                    checkFacet(attribute.getPlusOutside());
+                    checkFacet((SubPlane) attribute.getPlusOutside());
                 }
                 if (attribute.getPlusInside() != null) {
-                    checkFacet(attribute.getPlusInside());
+                    checkFacet((SubPlane) attribute.getPlusInside());
                 }
             }
 
-            public void visitLeafNode(BSPTree node) {
+            public void visitLeafNode(BSPTree<Euclidean3D> node) {
             }
 
-            private void checkFacet(SubHyperplane facet) {
+            private void checkFacet(SubPlane facet) {
                 Plane plane = (Plane) facet.getHyperplane();
-                Point2D[][] vertices =
+                Vector2D[][] vertices =
                     ((PolygonsSet) facet.getRemainingRegion()).getVertices();
                 Assert.assertEquals(1, vertices.length);
                 for (int i = 0; i < vertices[0].length; ++i) {
@@ -222,8 +216,8 @@ public class PolyhedronsSetTest {
             new PolyhedronsSet(x - w, x + w, y - l, y + l, z - w, z + w);
         PolyhedronsSet zBeam =
             new PolyhedronsSet(x - w, x + w, y - w, y + w, z - l, z + l);
-        PolyhedronsSet tree =
-            (PolyhedronsSet) Region.union(xBeam, Region.union(yBeam, zBeam));
+        RegionFactory<Euclidean3D> factory = new RegionFactory<Euclidean3D>();
+        PolyhedronsSet tree = (PolyhedronsSet) factory.union(xBeam, factory.union(yBeam, zBeam));
         Vector3D barycenter = (Vector3D) tree.getBarycenter();
 
         Assert.assertEquals(x, barycenter.getX(), 1.0e-10);
@@ -234,7 +228,7 @@ public class PolyhedronsSetTest {
 
     }
 
-    private void checkPoints(Region.Location expected, PolyhedronsSet tree, Point3D[] points) {
+    private void checkPoints(Region.Location expected, PolyhedronsSet tree, Vector3D[] points) {
         for (int i = 0; i < points.length; ++i) {
             Assert.assertEquals(expected, tree.checkPoint(points[i]));
         }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java?rev=1131127&r1=1131126&r2=1131127&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/twod/LineTest.java Fri Jun  3 18:08:12 2011
@@ -16,9 +16,10 @@
  */
 package org.apache.commons.math.geometry.euclidean.twod;
 
-import org.apache.commons.math.geometry.euclidean.oned.Point1D;
+import org.apache.commons.math.geometry.euclidean.oned.Euclidean1D;
+import org.apache.commons.math.geometry.euclidean.oned.Vector1D;
 import org.apache.commons.math.geometry.euclidean.twod.Line;
-import org.apache.commons.math.geometry.euclidean.twod.Point2D;
+import org.apache.commons.math.geometry.euclidean.twod.Vector2D;
 import org.apache.commons.math.geometry.partitioning.Transform;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
@@ -30,48 +31,48 @@ public class LineTest {
 
     @Test
     public void testContains() {
-        Line l = new Line(new Point2D(0, 1), new Point2D(1, 2));
-        Assert.assertTrue(l.contains(new Point2D(0, 1)));
-        Assert.assertTrue(l.contains(new Point2D(1, 2)));
-        Assert.assertTrue(l.contains(new Point2D(7, 8)));
-        Assert.assertTrue(! l.contains(new Point2D(8, 7)));
+        Line l = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
+        Assert.assertTrue(l.contains(new Vector2D(0, 1)));
+        Assert.assertTrue(l.contains(new Vector2D(1, 2)));
+        Assert.assertTrue(l.contains(new Vector2D(7, 8)));
+        Assert.assertTrue(! l.contains(new Vector2D(8, 7)));
     }
 
     @Test
     public void testAbscissa() {
-        Line l = new Line(new Point2D(2, 1), new Point2D(-2, -2));
+        Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
         Assert.assertEquals(0.0,
-                            ((Point1D) l.toSubSpace(new Point2D(-3,  4))).getAbscissa(),
+                            ((Vector1D) l.toSubSpace(new Vector2D(-3,  4))).getX(),
                             1.0e-10);
         Assert.assertEquals(0.0,
-                            ((Point1D) l.toSubSpace(new Point2D( 3, -4))).getAbscissa(),
+                            ((Vector1D) l.toSubSpace(new Vector2D( 3, -4))).getX(),
                             1.0e-10);
         Assert.assertEquals(-5.0,
-                            ((Point1D) l.toSubSpace(new Point2D( 7, -1))).getAbscissa(),
+                            ((Vector1D) l.toSubSpace(new Vector2D( 7, -1))).getX(),
                             1.0e-10);
         Assert.assertEquals( 5.0,
-                             ((Point1D) l.toSubSpace(new Point2D(-1, -7))).getAbscissa(),
+                             ((Vector1D) l.toSubSpace(new Vector2D(-1, -7))).getX(),
                              1.0e-10);
     }
 
     @Test
     public void testOffset() {
-        Line l = new Line(new Point2D(2, 1), new Point2D(-2, -2));
-        Assert.assertEquals(-5.0, l.getOffset(new Point2D(5, -3)), 1.0e-10);
-        Assert.assertEquals(+5.0, l.getOffset(new Point2D(-5, 2)), 1.0e-10);
+        Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
+        Assert.assertEquals(-5.0, l.getOffset(new Vector2D(5, -3)), 1.0e-10);
+        Assert.assertEquals(+5.0, l.getOffset(new Vector2D(-5, 2)), 1.0e-10);
     }
 
     @Test
     public void testPointAt() {
-        Line l = new Line(new Point2D(2, 1), new Point2D(-2, -2));
+        Line l = new Line(new Vector2D(2, 1), new Vector2D(-2, -2));
         for (double a = -2.0; a < 2.0; a += 0.2) {
-            Point1D pA = new Point1D(a);
-            Point2D point = (Point2D) l.toSpace(pA);
-            Assert.assertEquals(a, ((Point1D) l.toSubSpace(point)).getAbscissa(), 1.0e-10);
+            Vector1D pA = new Vector1D(a);
+            Vector2D point = (Vector2D) l.toSpace(pA);
+            Assert.assertEquals(a, ((Vector1D) l.toSubSpace(point)).getX(), 1.0e-10);
             Assert.assertEquals(0.0, l.getOffset(point),   1.0e-10);
             for (double o = -2.0; o < 2.0; o += 0.2) {
                 point = l.getPointAt(pA, o);
-                Assert.assertEquals(a, ((Point1D) l.toSubSpace(point)).getAbscissa(), 1.0e-10);
+                Assert.assertEquals(a, ((Vector1D) l.toSubSpace(point)).getX(), 1.0e-10);
                 Assert.assertEquals(o, l.getOffset(point),   1.0e-10);
             }
         }
@@ -79,38 +80,36 @@ public class LineTest {
 
     @Test
     public void testOriginOffset() {
-        Line l1 = new Line(new Point2D(0, 1), new Point2D(1, 2));
+        Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
         Assert.assertEquals(FastMath.sqrt(0.5), l1.getOriginOffset(), 1.0e-10);
-        Line l2 = new Line(new Point2D(1, 2), new Point2D(0, 1));
+        Line l2 = new Line(new Vector2D(1, 2), new Vector2D(0, 1));
         Assert.assertEquals(-FastMath.sqrt(0.5), l2.getOriginOffset(), 1.0e-10);
     }
 
     @Test
     public void testParallel() {
-        Line l1 = new Line(new Point2D(0, 1), new Point2D(1, 2));
-        Line l2 = new Line(new Point2D(2, 2), new Point2D(3, 3));
+        Line l1 = new Line(new Vector2D(0, 1), new Vector2D(1, 2));
+        Line l2 = new Line(new Vector2D(2, 2), new Vector2D(3, 3));
         Assert.assertTrue(l1.isParallelTo(l2));
-        Line l3 = new Line(new Point2D(1, 0), new Point2D(0.5, -0.5));
+        Line l3 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.5));
         Assert.assertTrue(l1.isParallelTo(l3));
-        Line l4 = new Line(new Point2D(1, 0), new Point2D(0.5, -0.51));
+        Line l4 = new Line(new Vector2D(1, 0), new Vector2D(0.5, -0.51));
         Assert.assertTrue(! l1.isParallelTo(l4));
     }
 
     @Test
     public void testTransform() {
 
-        Line l1 = new Line(new Point2D(1.0 ,1.0), new Point2D(4.0 ,1.0));
-        Transform t1 = Line.getTransform(new AffineTransform(0.0, 0.5,
-                                                             -1.0, 0.0,
-                                                             1.0, 1.5));
+        Line l1 = new Line(new Vector2D(1.0 ,1.0), new Vector2D(4.0 ,1.0));
+        Transform<Euclidean2D, Euclidean1D> t1 =
+            Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
         Assert.assertEquals(0.5 * FastMath.PI,
                             ((Line) t1.apply(l1)).getAngle(),
                             1.0e-10);
 
-        Line l2 = new Line(new Point2D(0.0, 0.0), new Point2D(1.0, 1.0));
-        Transform t2 = Line.getTransform(new AffineTransform(0.0, 0.5,
-                                                             -1.0, 0.0,
-                                                             1.0, 1.5));
+        Line l2 = new Line(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0));
+        Transform<Euclidean2D, Euclidean1D> t2 =
+            Line.getTransform(new AffineTransform(0.0, 0.5, -1.0, 0.0, 1.0, 1.5));
         Assert.assertEquals(FastMath.atan2(1.0, -2.0),
                             ((Line) t2.apply(l2)).getAngle(),
                             1.0e-10);
@@ -119,11 +118,11 @@ public class LineTest {
 
     @Test
     public void testIntersection() {
-        Line    l1 = new Line(new Point2D( 0, 1), new Point2D(1, 2));
-        Line    l2 = new Line(new Point2D(-1, 2), new Point2D(2, 1));
-        Point2D p  = (Point2D) l1.intersection(l2);
-        Assert.assertEquals(0.5, p.x, 1.0e-10);
-        Assert.assertEquals(1.5, p.y, 1.0e-10);
+        Line    l1 = new Line(new Vector2D( 0, 1), new Vector2D(1, 2));
+        Line    l2 = new Line(new Vector2D(-1, 2), new Vector2D(2, 1));
+        Vector2D p  = (Vector2D) l1.intersection(l2);
+        Assert.assertEquals(0.5, p.getX(), 1.0e-10);
+        Assert.assertEquals(1.5, p.getY(), 1.0e-10);
     }
 
 }