1 /* 2 * Licensed to the Apache Software Foundation (ASF) 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 ASF 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 * http://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.apache.commons.math3.geometry.spherical.twod; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 /** Spherical polygons boundary vertex. 23 * @see SphericalPolygonsSet#getBoundaryLoops() 24 * @see Edge 25 * @since 3.3 26 */ 27 public class Vertex { 28 29 /** Vertex location. */ 30 private final S2Point location; 31 32 /** Incoming edge. */ 33 private Edge incoming; 34 35 /** Outgoing edge. */ 36 private Edge outgoing; 37 38 /** Circles bound with this vertex. */ 39 private final List<Circle> circles; 40 41 /** Build a non-processed vertex not owned by any node yet. 42 * @param location vertex location 43 */ Vertex(final S2Point location)44 Vertex(final S2Point location) { 45 this.location = location; 46 this.incoming = null; 47 this.outgoing = null; 48 this.circles = new ArrayList<Circle>(); 49 } 50 51 /** Get Vertex location. 52 * @return vertex location 53 */ getLocation()54 public S2Point getLocation() { 55 return location; 56 } 57 58 /** Bind a circle considered to contain this vertex. 59 * @param circle circle to bind with this vertex 60 */ bindWith(final Circle circle)61 void bindWith(final Circle circle) { 62 circles.add(circle); 63 } 64 65 /** Get the common circle bound with both the instance and another vertex, if any. 66 * <p> 67 * When two vertices are both bound to the same circle, this means they are 68 * already handled by node associated with this circle, so there is no need 69 * to create a cut hyperplane for them. 70 * </p> 71 * @param vertex other vertex to check instance against 72 * @return circle bound with both the instance and another vertex, or null if the 73 * two vertices do not share a circle yet 74 */ sharedCircleWith(final Vertex vertex)75 Circle sharedCircleWith(final Vertex vertex) { 76 for (final Circle circle1 : circles) { 77 for (final Circle circle2 : vertex.circles) { 78 if (circle1 == circle2) { 79 return circle1; 80 } 81 } 82 } 83 return null; 84 } 85 86 /** Set incoming edge. 87 * <p> 88 * The circle supporting the incoming edge is automatically bound 89 * with the instance. 90 * </p> 91 * @param incoming incoming edge 92 */ setIncoming(final Edge incoming)93 void setIncoming(final Edge incoming) { 94 this.incoming = incoming; 95 bindWith(incoming.getCircle()); 96 } 97 98 /** Get incoming edge. 99 * @return incoming edge 100 */ getIncoming()101 public Edge getIncoming() { 102 return incoming; 103 } 104 105 /** Set outgoing edge. 106 * <p> 107 * The circle supporting the outgoing edge is automatically bound 108 * with the instance. 109 * </p> 110 * @param outgoing outgoing edge 111 */ setOutgoing(final Edge outgoing)112 void setOutgoing(final Edge outgoing) { 113 this.outgoing = outgoing; 114 bindWith(outgoing.getCircle()); 115 } 116 117 /** Get outgoing edge. 118 * @return outgoing edge 119 */ getOutgoing()120 public Edge getOutgoing() { 121 return outgoing; 122 } 123 124 } 125