001: /*
002: * The JTS Topology Suite is a collection of Java classes that
003: * implement the fundamental operations required to validate a given
004: * geo-spatial data set to a known topological specification.
005: *
006: * Copyright (C) 2001 Vivid Solutions
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: *
022: * For more information, contact:
023: *
024: * Vivid Solutions
025: * Suite #1A
026: * 2328 Government Street
027: * Victoria BC V8T 5G5
028: * Canada
029: *
030: * (250)385-6040
031: * www.vividsolutions.com
032: */
033: package com.vividsolutions.jts.algorithm;
034:
035: /**
036: * An interface for rules which determine whether node points
037: * which are in boundaries of lineal geometry components
038: * are in the boundary of the parent geometry collection.
039: * The SFS specifies a single kind of boundary node rule,
040: * the {@link Mod2BoundaryNodeRule} rule.
041: * However, other kinds of Boundary Node Rules are appropriate
042: * in specific situations (for instance, linear network topology
043: * usually follows the {@link EndPointBoundaryNodeRule}.)
044: * Some JTS operations allow the BoundaryNodeRule to be specified,
045: * and respect this rule when computing the results of the operation.
046: *
047: * @author Martin Davis
048: * @version 1.7
049: *
050: * @see RelateOp
051: * @see IsSimpleOp
052: */
053: public interface BoundaryNodeRule {
054:
055: boolean isInBoundary(int boundaryCount);
056:
057: /**
058: * The Mod-2 Boundary Node Rule (as used in the OGC SFS).
059: */
060: public static final BoundaryNodeRule MOD2_BOUNDARY_RULE = new Mod2BoundaryNodeRule();
061:
062: /**
063: * The Endpoint Boundary Node Rule.
064: */
065: public static final BoundaryNodeRule ENDPOINT_BOUNDARY_RULE = new EndPointBoundaryNodeRule();
066:
067: /**
068: * The MultiValent Endpoint Boundary Node Rule.
069: */
070: public static final BoundaryNodeRule MULTIVALENT_ENDPOINT_BOUNDARY_RULE = new MultiValentEndPointBoundaryNodeRule();
071:
072: /**
073: * The Monovalent Endpoint Boundary Node Rule.
074: */
075: public static final BoundaryNodeRule MONOVALENT_ENDPOINT_BOUNDARY_RULE = new MonoValentEndPointBoundaryNodeRule();
076:
077: /**
078: * The Boundary Node Rule specified by the OGC Simple Features Specification,
079: * equal to the Mod-2 rule.
080: */
081: public static final BoundaryNodeRule OGC_SFS_BOUNDARY_RULE = MOD2_BOUNDARY_RULE;
082:
083: /**
084: * A {@link BoundaryNodeRule} specifies that points are in the
085: * boundary of a lineal geometry iff
086: * the point lies on the boundary of an odd number
087: * of components.
088: * Under this rule {@link LinearRing}s and closed
089: * {@link LineString}s have an empty boundary.
090: * <p>
091: * This is the rule specified by the <i>OGC SFS</i>,
092: * and is the default rule used in JTS.
093: *
094: * @author Martin Davis
095: * @version 1.7
096: */
097: public static class Mod2BoundaryNodeRule implements
098: BoundaryNodeRule {
099: public boolean isInBoundary(int boundaryCount) {
100: // the "Mod-2 Rule"
101: return boundaryCount % 2 == 1;
102: }
103: }
104:
105: /**
106: * A {@link BoundaryNodeRule} which specifies that any points which are endpoints
107: * of lineal components are in the boundary of the
108: * parent geometry.
109: * This corresponds to the "intuitive" topological definition
110: * of boundary.
111: * Under this rule {@link LinearRing}s have a non-empty boundary
112: * (the common endpoint of the underlying LineString).
113: * <p>
114: * This rule is useful when dealing with linear networks.
115: * For example, it can be used to check
116: * whether linear networks are correctly noded.
117: * The usual network topology constraint is that linear segments may touch only at endpoints.
118: * In the case of a segment touching a closed segment (ring) at one point,
119: * the Mod2 rule cannot distinguish between the permitted case of touching at the
120: * node point and the invalid case of touching at some other interior (non-node) point.
121: * The EndPoint rule does distinguish between these cases,
122: * so is more appropriate for use.
123: *
124: * @author Martin Davis
125: * @version 1.7
126: */
127: public static class EndPointBoundaryNodeRule implements
128: BoundaryNodeRule {
129: public boolean isInBoundary(int boundaryCount) {
130: return boundaryCount > 0;
131: }
132: }
133:
134: /**
135: * A {@link BoundaryNodeRule} which determines that only
136: * endpoints with valency greater than 1 are on the boundary.
137: * This corresponds to the boundary of a {@link MultiLineString}
138: * being all the "attached" endpoints, but not
139: * the "unattached" ones.
140: *
141: * @author Martin Davis
142: * @version 1.7
143: */
144: public static class MultiValentEndPointBoundaryNodeRule implements
145: BoundaryNodeRule {
146: public boolean isInBoundary(int boundaryCount) {
147: return boundaryCount > 1;
148: }
149: }
150:
151: /**
152: * A {@link BoundaryNodeRule} which determines that only
153: * endpoints with valency of exactly 1 are on the boundary.
154: * This corresponds to the boundary of a {@link MultiLineString}
155: * being all the "unattached" endpoints.
156: *
157: * @author Martin Davis
158: * @version 1.7
159: */
160: public static class MonoValentEndPointBoundaryNodeRule implements
161: BoundaryNodeRule {
162: public boolean isInBoundary(int boundaryCount) {
163: return boundaryCount == 1;
164: }
165: }
166:
167: }
|