001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2005, 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.referencing.operation.builder;
017:
018: import org.geotools.geometry.DirectPosition2D;
019: import org.opengis.geometry.DirectPosition;
020:
021: /**
022: * Simple Circle focused on Delaunays triangulation.
023: *
024: * @since 2.4
025: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/builder/Circle.java $
026: * @version $Id: Circle.java 28966 2008-01-27 17:36:43Z acuster $
027: * @author Jan Jezek
028: */
029: class Circle {
030: /** Coordinates of center. */
031: private DirectPosition2D center;
032:
033: /** Value of radius */
034: private double radius;
035:
036: /** Tolerance for the cotains method. */
037: private double tolerance = 0.0001;
038:
039: /**
040: * Creates a circle with center [0,0] and radius = 0.
041: *
042: */
043: protected Circle() {
044: this (new DirectPosition2D(0, 0), 0);
045: }
046:
047: /**
048: * Creates a circle using the specified center and radius.
049: * @param center of the circle.
050: * @param radius of the circle.
051: */
052: protected Circle(DirectPosition center, double radius) {
053: this .center = new DirectPosition2D(center);
054: this .radius = radius;
055: }
056:
057: /**
058: * Sets the center.
059: *
060: * @param center coordinates
061: */
062: protected void setCenter(DirectPosition center) {
063: this .center = new DirectPosition2D(center);
064: }
065:
066: /**
067: * Sets the radius.
068: *
069: * @param radius value
070: */
071: protected void setRadius(double radius) {
072: this .radius = radius;
073: }
074:
075: /**
076: * Returns the coordinate of the center.
077: *
078: * @return center coordinates
079: */
080: protected DirectPosition getCenter() {
081: return center;
082: }
083:
084: /**
085: * Returns the radius.
086: *
087: * @return radius value.
088: */
089: protected double getRadius() {
090: return radius;
091: }
092:
093: /**
094: * Sets the tolerance for the contains method.
095: *
096: * @param tolerance value
097: */
098: protected void setTolerance(double tolerance) {
099: this .tolerance = tolerance;
100: }
101:
102: /**
103: * Raturns the tolerance
104: *
105: * @return tolerance value
106: */
107: protected double getTolerance() {
108: return tolerance;
109: }
110:
111: /**
112: * The contains test whether the coordinate p is within the circle.
113: * Triangle contains coordinate if the distance between center and p is
114: * smaller then the radius that is reduced by tolerance. This is used for
115: * triangulation when there are four points on one circle to avoid
116: * neverending loop.
117: *
118: * @param p - the point to be tested
119: *
120: * @return True if the circle contais p, False if not.
121: */
122: protected boolean contains(DirectPosition p) {
123: if (center.distance(new DirectPosition2D(p)) < (this .radius - tolerance)) {
124: return true;
125: } else {
126: return false;
127: }
128: }
129: }
|