Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#OUTLINE_BOUNDARY_LOOP_OPEN

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#OUTLINE_BOUNDARY_LOOP_OPEN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EdgesBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** 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;

}
 
Example 2
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @param tolerance tolerance below which points are considered identical
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 * @since 3.3
 */
private NestedLoops(final Vector2D[] loop, final double tolerance)
    throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop       = loop;
    this.surrounded = new ArrayList<NestedLoops>();
    this.tolerance  = tolerance;

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current, tolerance);
        final IntervalsSet region =
            new IntervalsSet(line.toSubSpace((Point<Euclidean2D>) previous).getX(),
                             line.toSubSpace((Point<Euclidean2D>) current).getX(),
                             tolerance);
        edges.add(new SubLine(line, region));
    }
    polygon = new PolygonsSet(edges, tolerance);

    // ensure the polygon encloses a finite region of the plane
    if (Double.isInfinite(polygon.getSize())) {
        polygon = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 3
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 */
private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop = loop;
    surrounded = new ArrayList<NestedLoops>();

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current);
        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 = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 4
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 */
private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop = loop;
    surrounded = new ArrayList<NestedLoops>();

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current);
        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 = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 5
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 */
private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop = loop;
    surrounded = new ArrayList<NestedLoops>();

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current);
        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 = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 6
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 */
private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop = loop;
    surrounded = new ArrayList<NestedLoops>();

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current);
        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 = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 7
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 */
private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop = loop;
    surrounded = new ArrayList<NestedLoops>();

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current);
        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 = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 8
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 */
private NestedLoops(final Vector2D[] loop) throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop = loop;
    surrounded = new ArrayList<NestedLoops>();

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current);
        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 = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}
 
Example 9
Source File: EdgesBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** 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;

}
 
Example 10
Source File: NestedLoops.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Constructor.
 * <p>Build a tree node with neither parent nor children</p>
 * @param loop boundary loop (will be reversed in place if needed)
 * @param tolerance tolerance below which points are considered identical
 * @exception MathIllegalArgumentException if an outline has an open boundary loop
 * @since 3.3
 */
private NestedLoops(final Vector2D[] loop, final double tolerance)
    throws MathIllegalArgumentException {

    if (loop[0] == null) {
        throw new MathIllegalArgumentException(LocalizedFormats.OUTLINE_BOUNDARY_LOOP_OPEN);
    }

    this.loop       = loop;
    this.surrounded = new ArrayList<NestedLoops>();
    this.tolerance  = tolerance;

    // build the polygon defined by the loop
    final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
    Vector2D current = loop[loop.length - 1];
    for (int i = 0; i < loop.length; ++i) {
        final Vector2D previous = current;
        current = loop[i];
        final Line   line   = new Line(previous, current, tolerance);
        final IntervalsSet region =
            new IntervalsSet(line.toSubSpace((Point<Euclidean2D>) previous).getX(),
                             line.toSubSpace((Point<Euclidean2D>) current).getX(),
                             tolerance);
        edges.add(new SubLine(line, region));
    }
    polygon = new PolygonsSet(edges, tolerance);

    // ensure the polygon encloses a finite region of the plane
    if (Double.isInfinite(polygon.getSize())) {
        polygon = new RegionFactory<Euclidean2D>().getComplement(polygon);
        originalIsClockwise = false;
    } else {
        originalIsClockwise = true;
    }

}