View Javadoc
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  
18  package org.hipparchus.geometry.spherical.twod;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.geometry.partitioning.BSPTree;
22  
23  /** Specialized version of {@link Edge} with tree node information.
24   * <p>
25   * The tree nodes information is used to set up connection between
26   * edges (i.e. combine the end vertex of an edge and the start vertex
27   * of the next edge) using topological information, thus avoiding
28   * inaccuracies due to angular distance only checks.
29   * </p>
30   * @since 1.4
31   */
32  class EdgeWithNodeInfo extends Edge {
33  
34      /** Node containing edge. */
35      private final BSPTree<Sphere2D> node;
36  
37      /** Node whose intersection with current node defines start point. */
38      private final BSPTree<Sphere2D> startNode;
39  
40      /** Node whose intersection with current node defines end point. */
41      private final BSPTree<Sphere2D> endNode;
42  
43      /** Indicator for completely processed edge. */
44      private boolean processed;
45  
46      /** Build an edge.
47       * @param start start point
48       * @param end end point
49       * @param length length of the arc (it can be greater than π)
50       * @param circle circle supporting the edge
51       * @param node node containing the edge
52       * @param startNode node whose intersection with current node defines start point
53       * @param endNode node whose intersection with current node defines end point
54       */
55      EdgeWithNodeInfo(final Vertex start, final Vertex end,
56                       final double length, final Circle circle,
57                       final BSPTree<Sphere2D> node,
58                       final BSPTree<Sphere2D> startNode,
59                       final BSPTree<Sphere2D> endNode) {
60          super(start, end, length, circle);
61          this.node      = node;
62          this.startNode = startNode;
63          this.endNode   = endNode;
64          this.processed = false;
65      }
66  
67      /** Check if two edges follow each other naturally.
68       * @param previous candidate previous edge
69       * @param next candidate next edge
70       * @return true if {@code edge} is a natural follower for instance
71       */
72      public static boolean areNaturalFollowers(final EdgeWithNodeInfo previous, final EdgeWithNodeInfo next) {
73          return next.getStart().getIncoming() == null &&
74                 previous.endNode              == next.node &&
75                 previous.node                 == next.startNode &&
76                 Vector3D.dotProduct(previous.getEnd().getLocation().getVector(),
77                                     next.getStart().getLocation().getVector()) > 0.0;
78      }
79  
80      /** Check if two edges result from a single edged having split by a circle.
81       * @param previous candidate previous edge
82       * @param next candidate next edge
83       * @return true if {@code edge} is a natural follower for instance
84       */
85      public static boolean resultFromASplit(final EdgeWithNodeInfo previous, final EdgeWithNodeInfo next) {
86          return next.getStart().getIncoming()          == null &&
87                 previous.node.getCut().getHyperplane() == next.node.getCut().getHyperplane() &&
88                 previous.endNode                       == next.startNode &&
89                 Vector3D.dotProduct(previous.getEnd().getLocation().getVector(),
90                                     next.getStart().getLocation().getVector()) > 0.0;
91      }
92  
93      /** Set the processed flag.
94       * @param processed processed flag to set
95       */
96      public void setProcessed(final boolean processed) {
97          this.processed = processed;
98      }
99  
100     /** Check if the edge has been processed.
101      * @return true if the edge has been processed
102      */
103     public boolean isProcessed() {
104         return processed;
105     }
106 
107 }