EdgeWithNodeInfo.java

  1. /*
  2.  * Licensed to the Hipparchus project under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.hipparchus.geometry.spherical.twod;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.geometry.partitioning.BSPTree;

  20. /** Specialized version of {@link Edge} with tree node information.
  21.  * <p>
  22.  * The tree nodes information is used to set up connection between
  23.  * edges (i.e. combine the end vertex of an edge and the start vertex
  24.  * of the next edge) using topological information, thus avoiding
  25.  * inaccuracies due to angular distance only checks.
  26.  * </p>
  27.  * @since 1.4
  28.  */
  29. class EdgeWithNodeInfo extends Edge {

  30.     /** Node containing edge. */
  31.     private final BSPTree<Sphere2D, S2Point, Circle, SubCircle> node;

  32.     /** Node whose intersection with current node defines start point. */
  33.     private final BSPTree<Sphere2D, S2Point, Circle, SubCircle> startNode;

  34.     /** Node whose intersection with current node defines end point. */
  35.     private final BSPTree<Sphere2D, S2Point, Circle, SubCircle> endNode;

  36.     /** Indicator for completely processed edge. */
  37.     private boolean processed;

  38.     /** Build an edge.
  39.      * @param start start point
  40.      * @param end end point
  41.      * @param length length of the arc (it can be greater than π)
  42.      * @param circle circle supporting the edge
  43.      * @param node node containing the edge
  44.      * @param startNode node whose intersection with current node defines start point
  45.      * @param endNode node whose intersection with current node defines end point
  46.      */
  47.     EdgeWithNodeInfo(final Vertex start, final Vertex end,
  48.                      final double length, final Circle circle,
  49.                      final BSPTree<Sphere2D, S2Point, Circle, SubCircle> node,
  50.                      final BSPTree<Sphere2D, S2Point, Circle, SubCircle> startNode,
  51.                      final BSPTree<Sphere2D, S2Point, Circle, SubCircle> endNode) {
  52.         super(start, end, length, circle);
  53.         this.node      = node;
  54.         this.startNode = startNode;
  55.         this.endNode   = endNode;
  56.         this.processed = false;
  57.     }

  58.     /** Check if two edges follow each other naturally.
  59.      * @param previous candidate previous edge
  60.      * @param next candidate next edge
  61.      * @return true if {@code edge} is a natural follower for instance
  62.      */
  63.     public static boolean areNaturalFollowers(final EdgeWithNodeInfo previous, final EdgeWithNodeInfo next) {
  64.         return next.getStart().getIncoming() == null &&
  65.                previous.endNode              == next.node &&
  66.                previous.node                 == next.startNode &&
  67.                Vector3D.dotProduct(previous.getEnd().getLocation().getVector(),
  68.                                    next.getStart().getLocation().getVector()) > 0.0;
  69.     }

  70.     /** Check if two edges result from a single edged having been split by a circle.
  71.      * @param previous candidate previous edge
  72.      * @param next candidate next edge
  73.      * @return true if {@code edge} is a natural follower for instance
  74.      */
  75.     public static boolean resultFromASplit(final EdgeWithNodeInfo previous, final EdgeWithNodeInfo next) {
  76.         return next.getStart().getIncoming()          == null &&
  77.                previous.node.getCut().getHyperplane() == next.node.getCut().getHyperplane() &&
  78.                previous.endNode                       == next.startNode &&
  79.                Vector3D.dotProduct(previous.getEnd().getLocation().getVector(),
  80.                                    next.getStart().getLocation().getVector()) > 0.0;
  81.     }

  82.     /** Set the processed flag.
  83.      * @param processed processed flag to set
  84.      */
  85.     public void setProcessed(final boolean processed) {
  86.         this.processed = processed;
  87.     }

  88.     /** Check if the edge has been processed.
  89.      * @return true if the edge has been processed
  90.      */
  91.     public boolean isProcessed() {
  92.         return processed;
  93.     }

  94. }