[geos-commits] r2426 - in trunk/source: algorithm headers/geos/algorithm

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Apr 30 05:26:28 EDT 2009


Author: strk
Date: 2009-04-30 05:26:28 -0400 (Thu, 30 Apr 2009)
New Revision: 2426

Added:
   trunk/source/algorithm/BoundaryNodeRule.cpp
   trunk/source/headers/geos/algorithm/BoundaryNodeRule.h
Modified:
   trunk/source/algorithm/Makefile.am
   trunk/source/headers/geos/algorithm/Makefile.am
Log:
Port algorithm::BoundaryNodeRule from JTS-1.10 (needed for IsSimpleOp sync)


Added: trunk/source/algorithm/BoundaryNodeRule.cpp
===================================================================
--- trunk/source/algorithm/BoundaryNodeRule.cpp	                        (rev 0)
+++ trunk/source/algorithm/BoundaryNodeRule.cpp	2009-04-30 09:26:28 UTC (rev 2426)
@@ -0,0 +1,143 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009      Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: algorithm/BoundaryNodeRule.java rev 1.4 (JTS-1.10)
+ *
+ **********************************************************************/
+
+#include <geos/algorithm/BoundaryNodeRule.h>
+
+namespace geos {
+namespace algorithm { // geos.algorithm
+
+// These classes are public in JTS, and under the BoundaryNodeRule
+// namespace. In GEOS they are hidden and only accessible as singleton
+// from BoundaryNodeRule static const references
+//
+namespace { 
+
+/**
+ * A {@link BoundaryNodeRule} specifies that points are in the
+ * boundary of a lineal geometry iff
+ * the point lies on the boundary of an odd number
+ * of components.
+ * Under this rule {@link LinearRing}s and closed
+ * {@link LineString}s have an empty boundary.
+ * <p>
+ * This is the rule specified by the <i>OGC SFS</i>,
+ * and is the default rule used in JTS.
+ *
+ * @author Martin Davis
+ * @version 1.7
+ */
+class Mod2BoundaryNodeRule : public BoundaryNodeRule
+{
+public:
+	bool isInBoundary(int boundaryCount) const
+	{
+		// the "Mod-2 Rule"
+		return boundaryCount % 2 == 1;
+	}
+};
+
+
+/**
+ * A {@link BoundaryNodeRule} which specifies that any points
+ * which are endpoints
+ * of lineal components are in the boundary of the
+ * parent geometry.
+ * This corresponds to the "intuitive" topological definition
+ * of boundary.
+ * Under this rule {@link LinearRing}s have a non-empty boundary
+ * (the common endpoint of the underlying LineString).
+ * <p>
+ * This rule is useful when dealing with linear networks.
+ * For example, it can be used to check
+ * whether linear networks are correctly noded.
+ * The usual network topology constraint is that linear segments may
+ * touch only at endpoints.
+ * In the case of a segment touching a closed segment (ring) at one
+ * point,
+ * the Mod2 rule cannot distinguish between the permitted case of
+ * touching at the
+ * node point and the invalid case of touching at some other interior
+ * (non-node) point.
+ * The EndPoint rule does distinguish between these cases,
+ * so is more appropriate for use.
+ *
+ * @author Martin Davis
+ * @version 1.7
+ */
+class EndPointBoundaryNodeRule : public BoundaryNodeRule
+{
+	bool isInBoundary(int boundaryCount) const
+	{
+		return boundaryCount > 0;
+	}
+};
+
+/**
+ * A {@link BoundaryNodeRule} which determines that only
+ * endpoints with valency greater than 1 are on the boundary.
+ * This corresponds to the boundary of a {@link MultiLineString}
+ * being all the "attached" endpoints, but not
+ * the "unattached" ones.
+ *
+ * @author Martin Davis
+ * @version 1.7
+ */
+class MultiValentEndPointBoundaryNodeRule : public BoundaryNodeRule
+{
+	bool isInBoundary(int boundaryCount) const
+	{
+		return boundaryCount > 1;
+	}
+};
+
+/**
+ * A {@link BoundaryNodeRule} which determines that only
+ * endpoints with valency of exactly 1 are on the boundary.
+ * This corresponds to the boundary of a {@link MultiLineString}
+ * being all the "unattached" endpoints.
+ *
+ * @author Martin Davis
+ * @version 1.7
+ */
+class MonoValentEndPointBoundaryNodeRule : public BoundaryNodeRule
+{
+	bool isInBoundary(int boundaryCount) const
+	{
+		return boundaryCount == 1;
+	}
+};
+
+
+} // anonymous namespace
+
+static Mod2BoundaryNodeRule mod2Rule;
+static EndPointBoundaryNodeRule endPointRule;
+static MultiValentEndPointBoundaryNodeRule multiValentRule;
+static MonoValentEndPointBoundaryNodeRule monoValentRule;
+
+const BoundaryNodeRule& BoundaryNodeRule::MOD2_BOUNDARY_RULE = mod2Rule;
+const BoundaryNodeRule& BoundaryNodeRule::ENDPOINT_BOUNDARY_RULE = endPointRule;
+const BoundaryNodeRule& BoundaryNodeRule::MULTIVALENT_ENDPOINT_BOUNDARY_RULE = multiValentRule;
+const BoundaryNodeRule& BoundaryNodeRule::MONOVALENT_ENDPOINT_BOUNDARY_RULE = monoValentRule;
+const BoundaryNodeRule& BoundaryNodeRule::OGC_SFS_BOUNDARY_RULE = BoundaryNodeRule::MOD2_BOUNDARY_RULE;
+
+
+} // namespace geos.algorithm
+} // namespace geos
+

Modified: trunk/source/algorithm/Makefile.am
===================================================================
--- trunk/source/algorithm/Makefile.am	2009-04-30 08:33:46 UTC (rev 2425)
+++ trunk/source/algorithm/Makefile.am	2009-04-30 09:26:28 UTC (rev 2426)
@@ -8,6 +8,7 @@
 
 libalgorithm_la_SOURCES = \
 	Angle.cpp \
+	BoundaryNodeRule.cpp \
 	CentroidArea.cpp \
 	CentroidLine.cpp \
 	CentroidPoint.cpp \

Added: trunk/source/headers/geos/algorithm/BoundaryNodeRule.h
===================================================================
--- trunk/source/headers/geos/algorithm/BoundaryNodeRule.h	                        (rev 0)
+++ trunk/source/headers/geos/algorithm/BoundaryNodeRule.h	2009-04-30 09:26:28 UTC (rev 2426)
@@ -0,0 +1,108 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009      Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: algorithm/BoundaryNodeRule.java rev 1.4 (JTS-1.10)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_ALGORITHM_BOUNDARYNODERULE_H
+#define GEOS_ALGORITHM_BOUNDARYNODERULE_H
+
+// Forward declarations
+// ...
+
+namespace geos {
+namespace algorithm { // geos::algorithm
+
+
+/**
+ * An interface for rules which determine whether node points
+ * which are in boundaries of {@link Lineal} geometry components
+ * are in the boundary of the parent geometry collection.
+ * The SFS specifies a single kind of boundary node rule,
+ * the {@link Mod2BoundaryNodeRule} rule.
+ * However, other kinds of Boundary Node Rules are appropriate
+ * in specific situations (for instance, linear network topology
+ * usually follows the {@link EndPointBoundaryNodeRule}.)
+ * Some JTS operations allow the BoundaryNodeRule to be specified,
+ * and respect this rule when computing the results of the operation.
+ *
+ * @author Martin Davis
+ * @version 1.7
+ *
+ * @see operation::relate::RelateOp
+ * @see operation::IsSimpleOp
+ * @see algorithm::PointLocator
+ */
+class BoundaryNodeRule {
+
+public:
+
+        /**
+         * Tests whether a point that lies in <tt>boundaryCount</tt>
+         * geometry component boundaries is considered to form part of
+	 * the boundary of the parent geometry.
+         *
+         * @param boundaryCount the number of component boundaries that
+	 *                      this point occurs in
+         * @return true if points in this number of boundaries lie in
+	 *              the parent boundary
+         */
+	virtual bool isInBoundary(int boundaryCount) const=0;
+
+	/** \brief
+	 * The Mod-2 Boundary Node Rule (which is the rule specified
+	 * in the OGC SFS).
+	 *
+	 * @see Mod2BoundaryNodeRule
+	 */
+	static const BoundaryNodeRule& MOD2_BOUNDARY_RULE;
+
+	/** \brief
+	 * The Endpoint Boundary Node Rule.
+	 *
+	 * @see EndPointBoundaryNodeRule
+	 */
+	static const BoundaryNodeRule& ENDPOINT_BOUNDARY_RULE;
+
+	/** \brief
+	 * The MultiValent Endpoint Boundary Node Rule.
+	 *
+	 * @see MultiValentEndPointBoundaryNodeRule
+	 */
+	static const BoundaryNodeRule& MULTIVALENT_ENDPOINT_BOUNDARY_RULE;
+
+	/** \brief
+	 * The Monovalent Endpoint Boundary Node Rule.
+	 *
+	 * @see MonoValentEndPointBoundaryNodeRule
+	 */
+	static const BoundaryNodeRule& MONOVALENT_ENDPOINT_BOUNDARY_RULE;
+
+	/** \brief
+	 * The Boundary Node Rule specified by the OGC Simple Features
+	 * Specification, which is the same as the Mod-2 rule.
+	 *
+	 * @see Mod2BoundaryNodeRule
+	 */
+	static const BoundaryNodeRule& OGC_SFS_BOUNDARY_RULE;
+
+};
+
+} // namespace geos::algorithm
+} // namespace geos
+
+#endif // GEOS_ALGORITHM_BOUNDARYNODERULE_H
+

Modified: trunk/source/headers/geos/algorithm/Makefile.am
===================================================================
--- trunk/source/headers/geos/algorithm/Makefile.am	2009-04-30 08:33:46 UTC (rev 2425)
+++ trunk/source/headers/geos/algorithm/Makefile.am	2009-04-30 09:26:28 UTC (rev 2426)
@@ -21,6 +21,7 @@
 
 noinst_HEADERS = 			\
 	Angle.h				\
+	BoundaryNodeRule.h		\
 	CGAlgorithms.h			\
 	CentralEndpointIntersector.h	\
 	CentroidArea.h			\



More information about the geos-commits mailing list