commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1561506 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/geometry/spherical/twod/ test/java/org/apache/commons/math3/geometry/spherical/twod/
Date Sun, 26 Jan 2014 15:31:18 GMT
Author: luc
Date: Sun Jan 26 15:31:18 2014
New Revision: 1561506

URL: http://svn.apache.org/r1561506
Log:
Extract classes out of SphericalPolygonsSet source file.

None of these classes required private access to the
SphericalPolygonsSet class, so they can be outside, simplifying the
source.

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Edge.java   (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/EdgesBuilder.java   (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/PropertiesComputer.java   (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Vertex.java   (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSetTest.java

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Edge.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Edge.java?rev=1561506&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Edge.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Edge.java Sun Jan 26 15:31:18 2014
@@ -0,0 +1,223 @@
+/*
+ * 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.math3.geometry.spherical.twod;
+
+import java.util.List;
+
+import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.math3.geometry.spherical.oned.Arc;
+import org.apache.commons.math3.util.FastMath;
+import org.apache.commons.math3.util.MathUtils;
+
+/** Spherical polygons boundary edge.
+ * @see SphericalPolygonsSet#getBoundaryLoops()
+ * @see Vertex
+ * @version $Id$
+ * @since 3.3
+ */
+public class Edge {
+
+    /** Start vertex. */
+    private final Vertex start;
+
+    /** End vertex. */
+    private Vertex end;
+
+    /** Length of the arc. */
+    private final double length;
+
+    /** Circle supporting the edge. */
+    private final Circle circle;
+
+    /** Build an edge not contained in any node yet.
+     * @param start start vertex
+     * @param end end vertex
+     * @param length length of the arc (it can be greater than \( \pi \))
+     * @param circle circle supporting the edge
+     */
+    Edge(final Vertex start, final Vertex end, final double length, final Circle circle) {
+
+        this.start  = start;
+        this.end    = end;
+        this.length = length;
+        this.circle = circle;
+
+        // connect the vertices back to the edge
+        start.setOutgoing(this);
+        end.setIncoming(this);
+
+    }
+
+    /** Get start vertex.
+     * @return start vertex
+     */
+    public Vertex getStart() {
+        return start;
+    }
+
+    /** Get end vertex.
+     * @return end vertex
+     */
+    public Vertex getEnd() {
+        return end;
+    }
+
+    /** Get the length of the arc.
+     * @return length of the arc (can be greater than \( \pi \))
+     */
+    public double getLength() {
+        return length;
+    }
+
+    /** Get the circle supporting this edge.
+     * @return circle supporting this edge
+     */
+    public Circle getCircle() {
+        return circle;
+    }
+
+    /** Get an intermediate point.
+     * <p>
+     * The angle along the edge should normally be between 0 and {@link #getLength()}
+     * in order to remain within edge limits. However, there are no checks on the
+     * value of the angle, so user can rebuild the full circle on which an edge is
+     * defined if they want.
+     * </p>
+     * @param alpha angle along the edge, counted from {@link #getStart()}
+     * @return an intermediate point
+     */
+    public Vector3D getPointAt(final double alpha) {
+        return circle.getPointAt(alpha + circle.getPhase(start.getLocation().getVector()));
+    }
+
+    /** Connect the instance with a following edge.
+     * @param next edge following the instance
+     */
+    void setNextEdge(final Edge next) {
+        end = next.getStart();
+        end.setIncoming(this);
+        end.bindWith(getCircle());
+    }
+
+    /** Split the edge.
+     * <p>
+     * Once split, this edge is not referenced anymore by the vertices,
+     * it is replaced by the two or three sub-edges and intermediate splitting
+     * vertices are introduced to connect these sub-edges together.
+     * </p>
+     * @param splitCircle circle splitting the edge in several parts
+     * @param outsideList list where to put parts that are outside of the split circle
+     * @param insideList list where to put parts that are inside the split circle
+     */
+    void split(final Circle splitCircle,
+                       final List<Edge> outsideList, final List<Edge> insideList) {
+
+        // get the inside arc, synchronizing its phase with the edge itself
+        final double edgeStart        = circle.getPhase(start.getLocation().getVector());
+        final Arc    arc              = circle.getInsideArc(splitCircle);
+        final double arcRelativeStart = MathUtils.normalizeAngle(arc.getInf(), edgeStart + FastMath.PI) - edgeStart;
+        final double arcRelativeEnd   = arcRelativeStart + arc.getSize();
+        final double unwrappedEnd     = arcRelativeEnd - MathUtils.TWO_PI;
+
+        // build the sub-edges
+        final double tolerance = circle.getTolerance();
+        Vertex previousVertex = start;
+        if (unwrappedEnd >= length - tolerance) {
+
+            // the edge is entirely contained inside the circle
+            // we don't split anything
+            insideList.add(this);
+
+        } else {
+
+            // there are at least some parts of the edge that should be outside
+            // (even is they are later be filtered out as being too small)
+            double alreadyManagedLength = 0;
+            if (unwrappedEnd >= 0) {
+                // the start of the edge is inside the circle
+                previousVertex = addSubEdge(previousVertex,
+                                            new Vertex(new S2Point(circle.getPointAt(edgeStart + unwrappedEnd))),
+                                            unwrappedEnd, insideList, splitCircle);
+                alreadyManagedLength = unwrappedEnd;
+            }
+
+            if (arcRelativeStart >= length - tolerance) {
+                // the edge ends while still outside of the circle
+                if (unwrappedEnd >= 0) {
+                    previousVertex = addSubEdge(previousVertex, end,
+                                                length - alreadyManagedLength, outsideList, splitCircle);
+                } else {
+                    // the edge is entirely outside of the circle
+                    // we don't split anything
+                    outsideList.add(this);
+                }
+            } else {
+                // the edge is long enough to enter inside the circle
+                previousVertex = addSubEdge(previousVertex,
+                                            new Vertex(new S2Point(circle.getPointAt(edgeStart + arcRelativeStart))),
+                                            arcRelativeStart - alreadyManagedLength, outsideList, splitCircle);
+                alreadyManagedLength = arcRelativeStart;
+
+                if (arcRelativeEnd >= length - tolerance) {
+                    // the edge ends while still inside of the circle
+                    previousVertex = addSubEdge(previousVertex, end,
+                                                length - alreadyManagedLength, insideList, splitCircle);
+                } else {
+                    // the edge is long enough to exit outside of the circle
+                    previousVertex = addSubEdge(previousVertex,
+                                                new Vertex(new S2Point(circle.getPointAt(edgeStart + arcRelativeStart))),
+                                                arcRelativeStart - alreadyManagedLength, insideList, splitCircle);
+                    alreadyManagedLength = arcRelativeStart;
+                    previousVertex = addSubEdge(previousVertex, end,
+                                                length - alreadyManagedLength, outsideList, splitCircle);
+                }
+            }
+
+        }
+
+    }
+
+    /** Add a sub-edge to a list if long enough.
+     * <p>
+     * If the length of the sub-edge to add is smaller than the {@link Circle#getTolerance()}
+     * tolerance of the support circle, it will be ignored.
+     * </p>
+     * @param subStart start of the sub-edge
+     * @param subEnd end of the sub-edge
+     * @param subLength length of the sub-edge
+     * @param splitCircle circle splitting the edge in several parts
+     * @param list list where to put the sub-edge
+     * @return end vertex of the edge ({@code subEnd} if the edge was long enough and really
+     * added, {@code subStart} if the edge was too small and therefore ignored)
+     */
+    private Vertex addSubEdge(final Vertex subStart, final Vertex subEnd, final double subLength,
+                              final List<Edge> list, final Circle splitCircle) {
+
+        if (subLength <= circle.getTolerance()) {
+            // the edge is too short, we ignore it
+            return subStart;
+        }
+
+        // really add the edge
+        subEnd.bindWith(splitCircle);
+        final Edge edge = new Edge(subStart, subEnd, subLength, circle);
+        list.add(edge);
+        return subEnd;
+
+    }
+
+}

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

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Edge.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/EdgesBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/EdgesBuilder.java?rev=1561506&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/EdgesBuilder.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/EdgesBuilder.java Sun Jan 26 15:31:18 2014
@@ -0,0 +1,170 @@
+/*
+ * 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.math3.geometry.spherical.twod;
+
+import java.util.ArrayList;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.math3.exception.MathIllegalStateException;
+import org.apache.commons.math3.exception.util.LocalizedFormats;
+import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.math3.geometry.partitioning.BSPTree;
+import org.apache.commons.math3.geometry.partitioning.BSPTreeVisitor;
+import org.apache.commons.math3.geometry.partitioning.BoundaryAttribute;
+import org.apache.commons.math3.geometry.spherical.oned.Arc;
+import org.apache.commons.math3.geometry.spherical.oned.ArcsSet;
+import org.apache.commons.math3.geometry.spherical.oned.S1Point;
+
+/** Visitor building edges.
+ * @version $Id$
+ * @since 3.3
+ */
+class EdgesBuilder implements BSPTreeVisitor<Sphere2D> {
+
+    /** Root of the tree. */
+    private final BSPTree<Sphere2D> root;
+
+    /** Tolerance below which points are consider to be identical. */
+    private final double tolerance;
+
+    /** Built edges and their associated nodes. */
+    private final Map<Edge, BSPTree<Sphere2D>> edgeToNode;
+
+    /** Reversed map. */
+    private final Map<BSPTree<Sphere2D>, List<Edge>> nodeToEdgesList;
+
+    /** Simple constructor.
+     * @param root tree root
+     * @param tolerance below which points are consider to be identical
+     */
+    public EdgesBuilder(final BSPTree<Sphere2D> root, final double tolerance) {
+        this.root            = root;
+        this.tolerance       = tolerance;
+        this.edgeToNode      = new IdentityHashMap<Edge, BSPTree<Sphere2D>>();
+        this.nodeToEdgesList = new IdentityHashMap<BSPTree<Sphere2D>, List<Edge>>();
+    }
+
+    /** {@inheritDoc} */
+    public Order visitOrder(final BSPTree<Sphere2D> node) {
+        return Order.MINUS_SUB_PLUS;
+    }
+
+    /** {@inheritDoc} */
+    public void visitInternalNode(final BSPTree<Sphere2D> node) {
+        nodeToEdgesList.put(node, new ArrayList<Edge>());
+        @SuppressWarnings("unchecked")
+        final BoundaryAttribute<Sphere2D> attribute = (BoundaryAttribute<Sphere2D>) node.getAttribute();
+        if (attribute.getPlusOutside() != null) {
+            addContribution((SubCircle) attribute.getPlusOutside(), false, node);
+        }
+        if (attribute.getPlusInside() != null) {
+            addContribution((SubCircle) attribute.getPlusInside(), true, node);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void visitLeafNode(final BSPTree<Sphere2D> node) {
+    }
+
+    /** Add the contribution of a boundary edge.
+     * @param sub boundary facet
+     * @param reversed if true, the facet has the inside on its plus side
+     * @param node node to which the edge belongs
+     */
+    private void addContribution(final SubCircle sub, final boolean reversed,
+                                 final BSPTree<Sphere2D> node) {
+        final Circle circle  = (Circle) sub.getHyperplane();
+        final List<Arc> arcs = ((ArcsSet) sub.getRemainingRegion()).asList();
+        for (final Arc a : arcs) {
+            final Vertex start = new Vertex((S2Point) circle.toSpace(new S1Point(a.getInf())));
+            final Vertex end   = new Vertex((S2Point) circle.toSpace(new S1Point(a.getSup())));
+            start.bindWith(circle);
+            end.bindWith(circle);
+            final Edge edge;
+            if (reversed) {
+                edge = new Edge(end, start, a.getSize(), circle.getReverse());
+            } else {
+                edge = new Edge(start, end, a.getSize(), circle);
+            }
+            edgeToNode.put(edge, node);
+            nodeToEdgesList.get(node).add(edge);
+        }
+    }
+
+    /** Get the edge that should naturally follow another one.
+     * @param previous edge to be continued
+     * @return other edge, starting where the previous one ends (they
+     * have not been connected yet)
+     * @exception MathIllegalStateException if there is not a single other edge
+     */
+    private Edge getFollowingEdge(final Edge previous)
+        throws MathIllegalStateException {
+
+        // get the candidate nodes
+        final S2Point point = previous.getEnd().getLocation();
+        final List<BSPTree<Sphere2D>> candidates = root.getCloseCuts(point, tolerance);
+
+        // the following edge we are looking for must start from one of the candidates nodes
+        double closest = tolerance;
+        Edge following = null;
+        for (final BSPTree<Sphere2D> node : candidates) {
+            for (final Edge edge : nodeToEdgesList.get(node)) {
+                if (edge != previous && edge.getStart().getIncoming() == null) {
+                    final Vector3D edgeStart = edge.getStart().getLocation().getVector();
+                    final double gap         = Vector3D.angle(point.getVector(), edgeStart);
+                    if (gap <= closest) {
+                        closest   = gap;
+                        following = edge;
+                    }
+                }
+            }
+        }
+
+        if (following == null) {
+            final Vector3D previousStart = previous.getStart().getLocation().getVector();
+            if (Vector3D.angle(point.getVector(), previousStart) <= tolerance) {
+                // the edge connects back to itself
+                return previous;
+            }
+
+            // this should never happen
+            throw new MathIllegalStateException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
+
+        }
+
+        return following;
+
+    }
+
+    /** Get the boundary edges.
+     * @return boundary edges
+     * @exception MathIllegalStateException if there is not a single other edge
+     */
+    public List<Edge> getEdges() throws MathIllegalStateException {
+
+        // connect the edges
+        for (final Edge previous : edgeToNode.keySet()) {
+            previous.setNextEdge(getFollowingEdge(previous));
+        }
+
+        return new ArrayList<Edge>(edgeToNode.keySet());
+
+    }
+
+}

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

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/EdgesBuilder.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/PropertiesComputer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/PropertiesComputer.java?rev=1561506&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/PropertiesComputer.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/PropertiesComputer.java Sun Jan 26 15:31:18 2014
@@ -0,0 +1,162 @@
+/*
+ * 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.math3.geometry.spherical.twod;
+
+import java.util.List;
+
+import org.apache.commons.math3.exception.MathInternalError;
+import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
+import org.apache.commons.math3.geometry.partitioning.BSPTree;
+import org.apache.commons.math3.geometry.partitioning.BSPTreeVisitor;
+import org.apache.commons.math3.util.FastMath;
+import org.apache.commons.math3.util.MathUtils;
+
+/** Visitor computing geometrical properties.
+ * @version $Id$
+ * @since 3.3
+ */
+class PropertiesComputer implements BSPTreeVisitor<Sphere2D> {
+
+    /** Tolerance below which points are consider to be identical. */
+    private final double tolerance;
+
+    /** Summed area. */
+    private double summedArea;
+
+    /** Summed barycenter. */
+    private Vector3D summedBarycenter;
+
+    /** Simple constructor.
+ * @param tolerance below which points are consider to be identical
+     */
+    public PropertiesComputer(final double tolerance) {
+        this.tolerance        = tolerance;
+        this.summedArea       = 0;
+        this.summedBarycenter = Vector3D.ZERO;
+    }
+
+    /** {@inheritDoc} */
+    public Order visitOrder(final BSPTree<Sphere2D> node) {
+        return Order.MINUS_SUB_PLUS;
+    }
+
+    /** {@inheritDoc} */
+    public void visitInternalNode(final BSPTree<Sphere2D> node) {
+        // nothing to do here
+    }
+
+    /** {@inheritDoc} */
+    public void visitLeafNode(final BSPTree<Sphere2D> node) {
+        if ((Boolean) node.getAttribute()) {
+
+            // transform this inside leaf cell into a simple convex polygon
+            final SphericalPolygonsSet convex =
+                    new SphericalPolygonsSet(node.pruneAroundConvexCell(Boolean.TRUE,
+                                                                        Boolean.FALSE,
+                                                                        null),
+                                             tolerance);
+
+            // extract the start of the single loop boundary of the convex cell
+            final List<Vertex> boundary = convex.getBoundaryLoops();
+            if (boundary.size() != 1) {
+                // this should never happen
+                throw new MathInternalError();
+            }
+
+            // compute the geometrical properties of the convex cell
+            final double area  = convexCellArea(boundary.get(0));
+            final Vector3D barycenter = convexCellBarycenter(boundary.get(0));
+
+            // add the cell contribution to the global properties
+            summedArea      += area;
+            summedBarycenter = new Vector3D(1, summedBarycenter, area, barycenter);
+
+        }
+    }
+
+    /** Compute convex cell area.
+     * @param start start vertex of the convex cell boundary
+     * @return area
+     */
+    private double convexCellArea(final Vertex start) {
+
+        int n = 0;
+        double sum = 0;
+
+        // loop around the cell
+        for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {
+
+            // find path interior angle at vertex
+            final Vector3D previousPole = e.getCircle().getPole();
+            final Vector3D nextPole     = e.getEnd().getOutgoing().getCircle().getPole();
+            final Vector3D point        = e.getEnd().getLocation().getVector();
+            double alpha = FastMath.atan2(Vector3D.dotProduct(nextPole, Vector3D.crossProduct(point, previousPole)),
+                                          -Vector3D.dotProduct(nextPole, previousPole));
+            if (alpha < 0) {
+                alpha += MathUtils.TWO_PI;
+            }
+            sum += alpha;
+            n++;
+        }
+
+        // compute area using extended Girard theorem
+        // see Spherical Trigonometry: For the Use of Colleges and Schools by I. Todhunter
+        // article 99 in chapter VIII Area Of a Spherical Triangle. Spherical Excess.
+        // book available from project Gutenberg at http://www.gutenberg.org/ebooks/19770
+        return sum - (n - 2) * FastMath.PI;
+
+    }
+
+    /** Compute convex cell barycenter.
+     * @param start start vertex of the convex cell boundary
+     * @return barycenter
+     */
+    private Vector3D convexCellBarycenter(final Vertex start) {
+
+        int n = 0;
+        Vector3D sumB = Vector3D.ZERO;
+
+        // loop around the cell
+        for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {
+            final Vector3D middle = e.getPointAt(0.5 * e.getLength());
+            sumB = new Vector3D(1, sumB, e.getLength(), middle);
+            n++;
+        }
+
+        return sumB.normalize();
+
+    }
+
+    /** Get the area.
+     * @return area
+     */
+    public double getArea() {
+        return summedArea;
+    }
+
+    /** Get the barycenter.
+     * @return barycenter
+     */
+    public S2Point getBarycenter() {
+        if (summedBarycenter.getNormSq() == 0) {
+            return S2Point.NaN;
+        } else {
+            return new S2Point(summedBarycenter);
+        }
+    }
+
+}

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

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/PropertiesComputer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java?rev=1561506&r1=1561505&r2=1561506&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSet.java Sun Jan 26 15:31:18 2014
@@ -19,24 +19,15 @@ package org.apache.commons.math3.geometr
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.commons.math3.exception.MathIllegalStateException;
-import org.apache.commons.math3.exception.MathInternalError;
-import org.apache.commons.math3.exception.util.LocalizedFormats;
 import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
 import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.math3.geometry.partitioning.AbstractRegion;
 import org.apache.commons.math3.geometry.partitioning.BSPTree;
-import org.apache.commons.math3.geometry.partitioning.BSPTreeVisitor;
-import org.apache.commons.math3.geometry.partitioning.BoundaryAttribute;
 import org.apache.commons.math3.geometry.partitioning.SubHyperplane;
-import org.apache.commons.math3.geometry.spherical.oned.Arc;
-import org.apache.commons.math3.geometry.spherical.oned.ArcsSet;
-import org.apache.commons.math3.geometry.spherical.oned.S1Point;
 import org.apache.commons.math3.geometry.spherical.oned.Sphere1D;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.util.MathUtils;
@@ -308,304 +299,6 @@ public class SphericalPolygonsSet extend
 
     }
 
-    /** Spherical polygons vertex.
-     * @see Edge
-     */
-    public static class Vertex {
-
-        /** Vertex location. */
-        private final S2Point location;
-
-        /** Incoming edge. */
-        private Edge incoming;
-
-        /** Outgoing edge. */
-        private Edge outgoing;
-
-        /** Circles bound with this vertex. */
-        private final List<Circle> circles;
-
-        /** Build a non-processed vertex not owned by any node yet.
-         * @param location vertex location
-         */
-        private Vertex(final S2Point location) {
-            this.location = location;
-            this.incoming = null;
-            this.outgoing = null;
-            this.circles  = new ArrayList<Circle>();
-        }
-
-        /** Get Vertex location.
-         * @return vertex location
-         */
-        public S2Point getLocation() {
-            return location;
-        }
-
-        /** Bind a circle considered to contain this vertex.
-         * @param circle circle to bind with this vertex
-         */
-        private void bindWith(final Circle circle) {
-            circles.add(circle);
-        }
-
-        /** Get the common circle bound with both the instance and another vertex, if any.
-         * <p>
-         * When two vertices are both bound to the same circle, this means they are
-         * already handled by node associated with this circle, so there is no need
-         * to create a cut hyperplane for them.
-         * </p>
-         * @param vertex other vertex to check instance against
-         * @return circle bound with both the instance and another vertex, or null if the
-         * two vertices do not share a circle yet
-         */
-        private Circle sharedCircleWith(final Vertex vertex) {
-            for (final Circle circle1 : circles) {
-                for (final Circle circle2 : vertex.circles) {
-                    if (circle1 == circle2) {
-                        return circle1;
-                    }
-                }
-            }
-            return null;
-        }
-
-        /** Set incoming edge.
-         * <p>
-         * The circle supporting the incoming edge is automatically bound
-         * with the instance.
-         * </p>
-         * @param incoming incoming edge
-         */
-        private void setIncoming(final Edge incoming) {
-            this.incoming = incoming;
-            bindWith(incoming.getCircle());
-        }
-
-        /** Get incoming edge.
-         * @return incoming edge
-         */
-        public Edge getIncoming() {
-            return incoming;
-        }
-
-        /** Set outgoing edge.
-         * <p>
-         * The circle supporting the outgoing edge is automatically bound
-         * with the instance.
-         * </p>
-         * @param outgoing outgoing edge
-         */
-        private void setOutgoing(final Edge outgoing) {
-            this.outgoing = outgoing;
-            bindWith(outgoing.getCircle());
-        }
-
-        /** Get outgoing edge.
-         * @return outgoing edge
-         */
-        public Edge getOutgoing() {
-            return outgoing;
-        }
-
-    }
-
-    /** Spherical polygons edge.
-     * @see Vertex
-     */
-    public static class Edge {
-
-        /** Start vertex. */
-        private final Vertex start;
-
-        /** End vertex. */
-        private Vertex end;
-
-        /** Length of the arc. */
-        private final double length;
-
-        /** Circle supporting the edge. */
-        private final Circle circle;
-
-        /** Build an edge not contained in any node yet.
-         * @param start start vertex
-         * @param end end vertex
-         * @param length length of the arc (it can be greater than \( \pi \))
-         * @param circle circle supporting the edge
-         */
-        private Edge(final Vertex start, final Vertex end, final double length, final Circle circle) {
-
-            this.start  = start;
-            this.end    = end;
-            this.length = length;
-            this.circle = circle;
-
-            // connect the vertices back to the edge
-            start.setOutgoing(this);
-            end.setIncoming(this);
-
-        }
-
-        /** Get start vertex.
-         * @return start vertex
-         */
-        public Vertex getStart() {
-            return start;
-        }
-
-        /** Get end vertex.
-         * @return end vertex
-         */
-        public Vertex getEnd() {
-            return end;
-        }
-
-        /** Get the length of the arc.
-         * @return length of the arc (can be greater than \( \pi \))
-         */
-        public double getLength() {
-            return length;
-        }
-
-        /** Get the circle supporting this edge.
-         * @return circle supporting this edge
-         */
-        public Circle getCircle() {
-            return circle;
-        }
-
-        /** Get an intermediate point.
-         * <p>
-         * The angle along the edge should normally be between 0 and {@link #getLength()}
-         * in order to remain within edge limits. However, there are no checks on the
-         * value of the angle, so user can rebuild the full circle on which an edge is
-         * defined if they want.
-         * </p>
-         * @param alpha angle along the edge, counted from {@link #getStart()}
-         * @return an intermediate point
-         */
-        public Vector3D getPointAt(final double alpha) {
-            return circle.getPointAt(alpha + circle.getPhase(start.getLocation().getVector()));
-        }
-
-        /** Connect the instance with a following edge.
-         * @param next edge following the instance
-         */
-        private void setNextEdge(final Edge next) {
-            end = next.getStart();
-            end.setIncoming(this);
-            end.bindWith(getCircle());
-        }
-
-        /** Split the edge.
-         * <p>
-         * Once split, this edge is not referenced anymore by the vertices,
-         * it is replaced by the two or three sub-edges and intermediate splitting
-         * vertices are introduced to connect these sub-edges together.
-         * </p>
-         * @param splitCircle circle splitting the edge in several parts
-         * @param outsideList list where to put parts that are outside of the split circle
-         * @param insideList list where to put parts that are inside the split circle
-         */
-        private void split(final Circle splitCircle,
-                           final List<Edge> outsideList, final List<Edge> insideList) {
-
-            // get the inside arc, synchronizing its phase with the edge itself
-            final double edgeStart        = circle.getPhase(start.getLocation().getVector());
-            final Arc    arc              = circle.getInsideArc(splitCircle);
-            final double arcRelativeStart = MathUtils.normalizeAngle(arc.getInf(), edgeStart + FastMath.PI) - edgeStart;
-            final double arcRelativeEnd   = arcRelativeStart + arc.getSize();
-            final double unwrappedEnd     = arcRelativeEnd - MathUtils.TWO_PI;
-
-            // build the sub-edges
-            final double tolerance = circle.getTolerance();
-            Vertex previousVertex = start;
-            if (unwrappedEnd >= length - tolerance) {
-
-                // the edge is entirely contained inside the circle
-                // we don't split anything
-                insideList.add(this);
-
-            } else {
-
-                // there are at least some parts of the edge that should be outside
-                // (even is they are later be filtered out as being too small)
-                double alreadyManagedLength = 0;
-                if (unwrappedEnd >= 0) {
-                    // the start of the edge is inside the circle
-                    previousVertex = addSubEdge(previousVertex,
-                                                new Vertex(new S2Point(circle.getPointAt(edgeStart + unwrappedEnd))),
-                                                unwrappedEnd, insideList, splitCircle);
-                    alreadyManagedLength = unwrappedEnd;
-                }
-
-                if (arcRelativeStart >= length - tolerance) {
-                    // the edge ends while still outside of the circle
-                    if (unwrappedEnd >= 0) {
-                        previousVertex = addSubEdge(previousVertex, end,
-                                                    length - alreadyManagedLength, outsideList, splitCircle);
-                    } else {
-                        // the edge is entirely outside of the circle
-                        // we don't split anything
-                        outsideList.add(this);
-                    }
-                } else {
-                    // the edge is long enough to enter inside the circle
-                    previousVertex = addSubEdge(previousVertex,
-                                                new Vertex(new S2Point(circle.getPointAt(edgeStart + arcRelativeStart))),
-                                                arcRelativeStart - alreadyManagedLength, outsideList, splitCircle);
-                    alreadyManagedLength = arcRelativeStart;
-
-                    if (arcRelativeEnd >= length - tolerance) {
-                        // the edge ends while still inside of the circle
-                        previousVertex = addSubEdge(previousVertex, end,
-                                                    length - alreadyManagedLength, insideList, splitCircle);
-                    } else {
-                        // the edge is long enough to exit outside of the circle
-                        previousVertex = addSubEdge(previousVertex,
-                                                    new Vertex(new S2Point(circle.getPointAt(edgeStart + arcRelativeStart))),
-                                                    arcRelativeStart - alreadyManagedLength, insideList, splitCircle);
-                        alreadyManagedLength = arcRelativeStart;
-                        previousVertex = addSubEdge(previousVertex, end,
-                                                    length - alreadyManagedLength, outsideList, splitCircle);
-                    }
-                }
-
-            }
-
-        }
-
-        /** Add a sub-edge to a list if long enough.
-         * <p>
-         * If the length of the sub-edge to add is smaller than the {@link Circle#getTolerance()}
-         * tolerance of the support circle, it will be ignored.
-         * </p>
-         * @param subStart start of the sub-edge
-         * @param subEnd end of the sub-edge
-         * @param subLength length of the sub-edge
-         * @param splitCircle circle splitting the edge in several parts
-         * @param list list where to put the sub-edge
-         * @return end vertex of the edge ({@code subEnd} if the edge was long enough and really
-         * added, {@code subStart} if the edge was too small and therefore ignored)
-         */
-        private Vertex addSubEdge(final Vertex subStart, final Vertex subEnd, final double subLength,
-                                  final List<Edge> list, final Circle splitCircle) {
-
-            if (subLength <= circle.getTolerance()) {
-                // the edge is too short, we ignore it
-                return subStart;
-            }
-
-            // really add the edge
-            subEnd.bindWith(splitCircle);
-            final Edge edge = new Edge(subStart, subEnd, subLength, circle);
-            list.add(edge);
-            return subEnd;
-
-        }
-
-    }
-
     /** {@inheritDoc} */
     @Override
     public SphericalPolygonsSet buildNew(final BSPTree<Sphere2D> tree) {
@@ -666,6 +359,8 @@ public class SphericalPolygonsSet extend
      * @return boundary of the polygon, organized as an unmodifiable list of loops start vertices.
      * @exception MathIllegalStateException if the tolerance setting does not allow to build
      * a clean non-ambiguous boundary
+     * @see Vertex
+     * @see Edge
      */
     public List<Vertex> getBoundaryLoops() throws MathIllegalStateException {
 
@@ -715,272 +410,4 @@ public class SphericalPolygonsSet extend
 
     }
 
-    /** Visitor building edges. */
-    private static class EdgesBuilder implements BSPTreeVisitor<Sphere2D> {
-
-        /** Root of the tree. */
-        private final BSPTree<Sphere2D> root;
-
-        /** Tolerance below which points are consider to be identical. */
-        private final double tolerance;
-
-        /** Built edges and their associated nodes. */
-        private final Map<Edge, BSPTree<Sphere2D>> edgeToNode;
-
-        /** Reversed map. */
-        private final Map<BSPTree<Sphere2D>, List<Edge>> nodeToEdgesList;
-
-        /** Simple constructor.
-         * @param root tree root
-         * @param tolerance below which points are consider to be identical
-         */
-        public EdgesBuilder(final BSPTree<Sphere2D> root, final double tolerance) {
-            this.root            = root;
-            this.tolerance       = tolerance;
-            this.edgeToNode      = new IdentityHashMap<Edge, BSPTree<Sphere2D>>();
-            this.nodeToEdgesList = new IdentityHashMap<BSPTree<Sphere2D>, List<Edge>>();
-        }
-
-        /** {@inheritDoc} */
-        public Order visitOrder(final BSPTree<Sphere2D> node) {
-            return Order.MINUS_SUB_PLUS;
-        }
-
-        /** {@inheritDoc} */
-        public void visitInternalNode(final BSPTree<Sphere2D> node) {
-            nodeToEdgesList.put(node, new ArrayList<Edge>());
-            @SuppressWarnings("unchecked")
-            final BoundaryAttribute<Sphere2D> attribute = (BoundaryAttribute<Sphere2D>) node.getAttribute();
-            if (attribute.getPlusOutside() != null) {
-                addContribution((SubCircle) attribute.getPlusOutside(), false, node);
-            }
-            if (attribute.getPlusInside() != null) {
-                addContribution((SubCircle) attribute.getPlusInside(), true, node);
-            }
-        }
-
-        /** {@inheritDoc} */
-        public void visitLeafNode(final BSPTree<Sphere2D> node) {
-        }
-
-        /** Add the contribution of a boundary edge.
-         * @param sub boundary facet
-         * @param reversed if true, the facet has the inside on its plus side
-         * @param node node to which the edge belongs
-         */
-        private void addContribution(final SubCircle sub, final boolean reversed,
-                                     final BSPTree<Sphere2D> node) {
-            final Circle circle  = (Circle) sub.getHyperplane();
-            final List<Arc> arcs = ((ArcsSet) sub.getRemainingRegion()).asList();
-            for (final Arc a : arcs) {
-                final Vertex start = new Vertex((S2Point) circle.toSpace(new S1Point(a.getInf())));
-                final Vertex end   = new Vertex((S2Point) circle.toSpace(new S1Point(a.getSup())));
-                start.bindWith(circle);
-                end.bindWith(circle);
-                final Edge edge;
-                if (reversed) {
-                    edge = new Edge(end, start, a.getSize(), circle.getReverse());
-                } else {
-                    edge = new Edge(start, end, a.getSize(), circle);
-                }
-                edgeToNode.put(edge, node);
-                nodeToEdgesList.get(node).add(edge);
-            }
-        }
-
-        /** Get the edge that should naturally follow another one.
-         * @param previous edge to be continued
-         * @return other edge, starting where the previous one ends (they
-         * have not been connected yet)
-         * @exception MathIllegalStateException if there is not a single other edge
-         */
-        private Edge getFollowingEdge(final Edge previous)
-            throws MathIllegalStateException {
-
-            // get the candidate nodes
-            final S2Point point = previous.getEnd().getLocation();
-            final List<BSPTree<Sphere2D>> candidates = root.getCloseCuts(point, tolerance);
-
-            // the following edge we are looking for must start from one of the candidates nodes
-            double closest = tolerance;
-            Edge following = null;
-            for (final BSPTree<Sphere2D> node : candidates) {
-                for (final Edge edge : nodeToEdgesList.get(node)) {
-                    if (edge != previous && edge.getStart().getIncoming() == null) {
-                        final Vector3D edgeStart = edge.getStart().getLocation().getVector();
-                        final double gap         = Vector3D.angle(point.getVector(), edgeStart);
-                        if (gap <= closest) {
-                            closest   = gap;
-                            following = edge;
-                        }
-                    }
-                }
-            }
-
-            if (following == null) {
-                final Vector3D previousStart = previous.getStart().getLocation().getVector();
-                if (Vector3D.angle(point.getVector(), previousStart) <= tolerance) {
-                    // the edge connects back to itself
-                    return previous;
-                }
-
-                // this should never happen
-                throw new MathIllegalStateException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
-
-            }
-
-            return following;
-
-        }
-
-        /** Get the boundary edges.
-         * @return boundary edges
-         * @exception MathIllegalStateException if there is not a single other edge
-         */
-        public List<Edge> getEdges() throws MathIllegalStateException {
-
-            // connect the edges
-            for (final Edge previous : edgeToNode.keySet()) {
-                previous.setNextEdge(getFollowingEdge(previous));
-            }
-
-            return new ArrayList<Edge>(edgeToNode.keySet());
-
-        }
-
-    }
-
-    /** Visitor computing geometrical properties. */
-    private static class PropertiesComputer implements BSPTreeVisitor<Sphere2D> {
-
-        /** Tolerance below which points are consider to be identical. */
-        private final double tolerance;
-
-        /** Summed area. */
-        private double summedArea;
-
-        /** Summed barycenter. */
-        private Vector3D summedBarycenter;
-
-        /** Simple constructor.
-     * @param tolerance below which points are consider to be identical
-         */
-        public PropertiesComputer(final double tolerance) {
-            this.tolerance        = tolerance;
-            this.summedArea       = 0;
-            this.summedBarycenter = Vector3D.ZERO;
-        }
-
-        /** {@inheritDoc} */
-        public Order visitOrder(final BSPTree<Sphere2D> node) {
-            return Order.MINUS_SUB_PLUS;
-        }
-
-        /** {@inheritDoc} */
-        public void visitInternalNode(final BSPTree<Sphere2D> node) {
-            // nothing to do here
-        }
-
-        /** {@inheritDoc} */
-        public void visitLeafNode(final BSPTree<Sphere2D> node) {
-            if ((Boolean) node.getAttribute()) {
-
-                // transform this inside leaf cell into a simple convex polygon
-                final SphericalPolygonsSet convex =
-                        new SphericalPolygonsSet(node.pruneAroundConvexCell(Boolean.TRUE,
-                                                                            Boolean.FALSE,
-                                                                            null),
-                                                 tolerance);
-
-                // extract the start of the single loop boundary of the convex cell
-                final List<Vertex> boundary = convex.getBoundaryLoops();
-                if (boundary.size() != 1) {
-                    // this should never happen
-                    throw new MathInternalError();
-                }
-
-                // compute the geometrical properties of the convex cell
-                final double area  = convexCellArea(boundary.get(0));
-                final Vector3D barycenter = convexCellBarycenter(boundary.get(0));
-
-                // add the cell contribution to the global properties
-                summedArea      += area;
-                summedBarycenter = new Vector3D(1, summedBarycenter, area, barycenter);
-
-            }
-        }
-
-        /** Compute convex cell area.
-         * @param start start vertex of the convex cell boundary
-         * @return area
-         */
-        private double convexCellArea(final Vertex start) {
-
-            int n = 0;
-            double sum = 0;
-
-            // loop around the cell
-            for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {
-
-                // find path interior angle at vertex
-                final Vector3D previousPole = e.getCircle().getPole();
-                final Vector3D nextPole     = e.getEnd().getOutgoing().getCircle().getPole();
-                final Vector3D point        = e.getEnd().getLocation().getVector();
-                double alpha = FastMath.atan2(Vector3D.dotProduct(nextPole, Vector3D.crossProduct(point, previousPole)),
-                                              -Vector3D.dotProduct(nextPole, previousPole));
-                if (alpha < 0) {
-                    alpha += MathUtils.TWO_PI;
-                }
-                sum += alpha;
-                n++;
-            }
-
-            // compute area using extended Girard theorem
-            // see Spherical Trigonometry: For the Use of Colleges and Schools by I. Todhunter
-            // article 99 in chapter VIII Area Of a Spherical Triangle. Spherical Excess.
-            // book available from project Gutenberg at http://www.gutenberg.org/ebooks/19770
-            return sum - (n - 2) * FastMath.PI;
-
-        }
-
-        /** Compute convex cell barycenter.
-         * @param start start vertex of the convex cell boundary
-         * @return barycenter
-         */
-        private Vector3D convexCellBarycenter(final Vertex start) {
-
-            int n = 0;
-            Vector3D sumB = Vector3D.ZERO;
-
-            // loop around the cell
-            for (Edge e = start.getOutgoing(); n == 0 || e.getStart() != start; e = e.getEnd().getOutgoing()) {
-                final Vector3D middle = e.getPointAt(0.5 * e.getLength());
-                sumB = new Vector3D(1, sumB, e.getLength(), middle);
-                n++;
-            }
-
-            return sumB.normalize();
-
-        }
-
-        /** Get the area.
-         * @return area
-         */
-        public double getArea() {
-            return summedArea;
-        }
-
-        /** Get the barycenter.
-         * @return barycenter
-         */
-        public S2Point getBarycenter() {
-            if (summedBarycenter.getNormSq() == 0) {
-                return S2Point.NaN;
-            } else {
-                return new S2Point(summedBarycenter);
-            }
-        }
-
-    }
-
 }

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Vertex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Vertex.java?rev=1561506&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Vertex.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Vertex.java Sun Jan 26 15:31:18 2014
@@ -0,0 +1,125 @@
+/*
+ * 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.math3.geometry.spherical.twod;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Spherical polygons boundary vertex.
+ * @see SphericalPolygonsSet#getBoundaryLoops()
+ * @see Edge
+ * @version $Id$
+ * @since 3.3
+ */
+public class Vertex {
+
+    /** Vertex location. */
+    private final S2Point location;
+
+    /** Incoming edge. */
+    private Edge incoming;
+
+    /** Outgoing edge. */
+    private Edge outgoing;
+
+    /** Circles bound with this vertex. */
+    private final List<Circle> circles;
+
+    /** Build a non-processed vertex not owned by any node yet.
+     * @param location vertex location
+     */
+    Vertex(final S2Point location) {
+        this.location = location;
+        this.incoming = null;
+        this.outgoing = null;
+        this.circles  = new ArrayList<Circle>();
+    }
+
+    /** Get Vertex location.
+     * @return vertex location
+     */
+    public S2Point getLocation() {
+        return location;
+    }
+
+    /** Bind a circle considered to contain this vertex.
+     * @param circle circle to bind with this vertex
+     */
+    void bindWith(final Circle circle) {
+        circles.add(circle);
+    }
+
+    /** Get the common circle bound with both the instance and another vertex, if any.
+     * <p>
+     * When two vertices are both bound to the same circle, this means they are
+     * already handled by node associated with this circle, so there is no need
+     * to create a cut hyperplane for them.
+     * </p>
+     * @param vertex other vertex to check instance against
+     * @return circle bound with both the instance and another vertex, or null if the
+     * two vertices do not share a circle yet
+     */
+    Circle sharedCircleWith(final Vertex vertex) {
+        for (final Circle circle1 : circles) {
+            for (final Circle circle2 : vertex.circles) {
+                if (circle1 == circle2) {
+                    return circle1;
+                }
+            }
+        }
+        return null;
+    }
+
+    /** Set incoming edge.
+     * <p>
+     * The circle supporting the incoming edge is automatically bound
+     * with the instance.
+     * </p>
+     * @param incoming incoming edge
+     */
+    void setIncoming(final Edge incoming) {
+        this.incoming = incoming;
+        bindWith(incoming.getCircle());
+    }
+
+    /** Get incoming edge.
+     * @return incoming edge
+     */
+    public Edge getIncoming() {
+        return incoming;
+    }
+
+    /** Set outgoing edge.
+     * <p>
+     * The circle supporting the outgoing edge is automatically bound
+     * with the instance.
+     * </p>
+     * @param outgoing outgoing edge
+     */
+    void setOutgoing(final Edge outgoing) {
+        this.outgoing = outgoing;
+        bindWith(outgoing.getCircle());
+    }
+
+    /** Get outgoing edge.
+     * @return outgoing edge
+     */
+    public Edge getOutgoing() {
+        return outgoing;
+    }
+
+}

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

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/spherical/twod/Vertex.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSetTest.java?rev=1561506&r1=1561505&r2=1561506&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSetTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/spherical/twod/SphericalPolygonsSetTest.java Sun Jan 26 15:31:18 2014
@@ -92,7 +92,7 @@ public class SphericalPolygonsSetTest {
             }
         }
 
-        List<SphericalPolygonsSet.Vertex> loops = octant.getBoundaryLoops();
+        List<Vertex> loops = octant.getBoundaryLoops();
         Assert.assertEquals(1, loops.size());
         boolean xPFound = false;
         boolean yPFound = false;
@@ -100,11 +100,11 @@ public class SphericalPolygonsSetTest {
         boolean xVFound = false;
         boolean yVFound = false;
         boolean zVFound = false;
-        SphericalPolygonsSet.Vertex first = loops.get(0);
+        Vertex first = loops.get(0);
         int count = 0;
-        for (SphericalPolygonsSet.Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
+        for (Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
             ++count;
-            SphericalPolygonsSet.Edge e = v.getIncoming();
+            Edge e = v.getIncoming();
             Assert.assertTrue(v == e.getStart().getOutgoing().getEnd());
             xPFound = xPFound || e.getCircle().getPole().distance(Vector3D.PLUS_I) < 1.0e-10;
             yPFound = yPFound || e.getCircle().getPole().distance(Vector3D.PLUS_J) < 1.0e-10;
@@ -172,7 +172,7 @@ public class SphericalPolygonsSetTest {
             }
         }
 
-        List<SphericalPolygonsSet.Vertex> loops = threeOctants.getBoundaryLoops();
+        List<Vertex> loops = threeOctants.getBoundaryLoops();
         Assert.assertEquals(1, loops.size());
         boolean xPFound = false;
         boolean yPFound = false;
@@ -180,11 +180,11 @@ public class SphericalPolygonsSetTest {
         boolean xVFound = false;
         boolean yVFound = false;
         boolean zVFound = false;
-        SphericalPolygonsSet.Vertex first = loops.get(0);
+        Vertex first = loops.get(0);
         int count = 0;
-        for (SphericalPolygonsSet.Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
+        for (Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
             ++count;
-            SphericalPolygonsSet.Edge e = v.getIncoming();
+            Edge e = v.getIncoming();
             Assert.assertTrue(v == e.getStart().getOutgoing().getEnd());
             xPFound = xPFound || e.getCircle().getPole().distance(Vector3D.MINUS_I) < 1.0e-10;
             yPFound = yPFound || e.getCircle().getPole().distance(Vector3D.MINUS_J) < 1.0e-10;
@@ -234,7 +234,7 @@ public class SphericalPolygonsSetTest {
         Assert.assertEquals(MathUtils.TWO_PI, polygon.getSize(), 1.0e-10);
         Assert.assertEquals(3 * FastMath.PI, polygon.getBoundarySize(), 1.0e-10);
 
-        List<SphericalPolygonsSet.Vertex> loops = polygon.getBoundaryLoops();
+        List<Vertex> loops = polygon.getBoundaryLoops();
         Assert.assertEquals(1, loops.size());
         boolean pXFound = false;
         boolean mXFound = false;
@@ -242,11 +242,11 @@ public class SphericalPolygonsSetTest {
         boolean mYFound = false;
         boolean pZFound = false;
         boolean mZFound = false;
-        SphericalPolygonsSet.Vertex first = loops.get(0);
+        Vertex first = loops.get(0);
         int count = 0;
-        for (SphericalPolygonsSet.Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
+        for (Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
             ++count;
-            SphericalPolygonsSet.Edge e = v.getIncoming();
+            Edge e = v.getIncoming();
             Assert.assertTrue(v == e.getStart().getOutgoing().getEnd());
             pXFound = pXFound || v.getLocation().getVector().distance(Vector3D.PLUS_I)  < 1.0e-10;
             mXFound = mXFound || v.getLocation().getVector().distance(Vector3D.MINUS_I) < 1.0e-10;



Mime
View raw message