001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.graph.util.delaunay;
017:
018: import java.util.logging.Logger;
019: import org.geotools.graph.structure.Node;
020: import org.geotools.graph.structure.basic.BasicEdge;
021: import org.geotools.graph.structure.line.XYNode;
022:
023: /**
024: *
025: * @author jfc173
026: */
027: public class DelaunayEdge extends BasicEdge {
028:
029: private static final Logger LOGGER = org.geotools.util.logging.Logging
030: .getLogger("org.geotools.graph");
031: Triangle faceA, faceB;
032:
033: /** Creates a new instance of DelaunayEdge */
034: public DelaunayEdge(XYNode nodeA, XYNode nodeB) {
035: super (nodeA, nodeB);
036: }
037:
038: public void disconnect() {
039: this .getNodeA().remove(this );
040: this .getNodeB().remove(this );
041: }
042:
043: public void setFaceA(Triangle t) {
044: if (t.equals(faceB)) {
045: throw new RuntimeException(
046: "Face A must be different from Face B.");
047: }
048: faceA = t;
049: }
050:
051: public void setFaceB(Triangle t) {
052: if (t.equals(faceA)) {
053: throw new RuntimeException(
054: "Face A must be different from Face B.");
055: }
056: faceB = t;
057: }
058:
059: public boolean hasEndPoint(XYNode node) {
060: return ((node.equals(this .getNodeA())) || (node.equals(this
061: .getNodeB())));
062: }
063:
064: public Triangle getOtherFace(Triangle t) {
065: if (faceA.equals(t)) {
066: return faceB;
067: } else if (faceB.equals(t)) {
068: return faceA;
069: } else {
070: LOGGER.warning("Oops. Input face is " + t);
071: LOGGER.warning("Face A is " + faceA);
072: LOGGER.warning("Face B is " + faceB);
073: throw new RuntimeException(
074: "DelaunayEdge.getOtherFace must receive as input one of the faces bordering that edge.");
075: }
076: }
077:
078: public void setOtherFace(Triangle newT, Triangle oldT) {
079: if (faceA.equals(oldT)) {
080: if (newT.equals(faceA)) {
081: LOGGER.warning("Oops. Face A is " + faceA
082: + " and new Triangle is " + newT);
083: throw new RuntimeException(
084: "Face A must be different from Face B.");
085: }
086: this .setFaceB(newT);
087: } else if (faceB.equals(oldT)) {
088: if (newT.equals(faceB)) {
089: LOGGER.warning("Oops. Face B is " + faceB
090: + " and new Triangle is " + newT);
091: throw new RuntimeException(
092: "Face A must be different from Face B.");
093: }
094: this .setFaceA(newT);
095: } else {
096: throw new RuntimeException(
097: "DelaunayEdge.setOtherFace must have either faceA or faceB as the oldT parameter.");
098: }
099: }
100:
101: public double getEuclideanDistance() {
102: return ((XYNode) this .getNodeA()).getCoordinate().distance(
103: ((XYNode) this .getNodeB()).getCoordinate());
104: }
105:
106: public boolean equals(Object o) {
107: return ((o instanceof DelaunayEdge) && ((this .getNodeA()
108: .equals(((DelaunayEdge) o).getNodeA()) && (this
109: .getNodeB().equals(((DelaunayEdge) o).getNodeB()))) || (this
110: .getNodeA().equals(((DelaunayEdge) o).getNodeB()) && (this
111: .getNodeB().equals(((DelaunayEdge) o).getNodeA())))));
112: }
113:
114: public String toString() {
115: return this .getNodeA().toString() + "--"
116: + this.getNodeB().toString();
117: }
118:
119: }
|