1 /* 2 * Copyright (c) 2016 Vivid Solutions. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. 7 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html 8 * and the Eclipse Distribution License is available at 9 * 10 * http://www.eclipse.org/org/documents/edl-v10.php. 11 */ 12 package org.locationtech.jts.triangulate; 13 14 15 import org.locationtech.jts.geom.Coordinate; 16 import org.locationtech.jts.triangulate.quadedge.Vertex; 17 18 /** 19 * A vertex in a Constrained Delaunay Triangulation. 20 * The vertex may or may not lie on a constraint. 21 * If it does it may carry extra information about the original constraint. 22 * 23 * @author Martin Davis 24 */ 25 public class ConstraintVertex extends Vertex { 26 private boolean isOnConstraint; 27 private Object constraint = null; 28 29 /** 30 * Creates a new constraint vertex 31 * 32 * @param p the location of the vertex 33 */ ConstraintVertex(Coordinate p)34 public ConstraintVertex(Coordinate p) { 35 super(p); 36 } 37 38 /** 39 * Sets whether this vertex lies on a constraint. 40 * 41 * @param isOnConstraint true if this vertex lies on a constraint 42 */ setOnConstraint(boolean isOnConstraint)43 public void setOnConstraint(boolean isOnConstraint) { 44 this.isOnConstraint = isOnConstraint; 45 } 46 47 /** 48 * Tests whether this vertex lies on a constraint. 49 * 50 * @return true if the vertex lies on a constraint 51 */ isOnConstraint()52 public boolean isOnConstraint() { 53 return isOnConstraint; 54 } 55 56 /** 57 * Sets the external constraint information 58 * 59 * @param constraint an object which carries information about the constraint this vertex lies on 60 */ setConstraint(Object constraint)61 public void setConstraint(Object constraint) { 62 isOnConstraint = true; 63 this.constraint = constraint; 64 } 65 66 /** 67 * Gets the external constraint object 68 * 69 * @return the external constraint object 70 */ getConstraint()71 public Object getConstraint() { 72 return constraint; 73 } 74 75 /** 76 * Merges the constraint data in the vertex <tt>other</tt> into this vertex. 77 * This method is called when an inserted vertex is 78 * very close to an existing vertex in the triangulation. 79 * 80 * @param other the constraint vertex to merge 81 */ merge(ConstraintVertex other)82 protected void merge(ConstraintVertex other) { 83 if (other.isOnConstraint) { 84 isOnConstraint = true; 85 constraint = other.constraint; 86 } 87 } 88 } 89