Class EdgeNodingValidator

 1  
 2 /*
 3  * Copyright (c) 2016 Vivid Solutions.
 4  *
 5  * All rights reserved. This program and the accompanying materials
 6  * are made available under the terms of the Eclipse Public License 2.0
 7  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
 8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
 9  * and the Eclipse Distribution License is available at
10  *
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  */
13 package org.locationtech.jts.geomgraph;
14  
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.Iterator;
18  
19 import org.locationtech.jts.geom.TopologyException;
20 import org.locationtech.jts.noding.BasicSegmentString;
21 import org.locationtech.jts.noding.FastNodingValidator;
22  
23 /**
24  * Validates that a collection of {@link Edge}s is correctly noded.
25  * Throws an appropriate exception if an noding error is found.
26  * Uses {@link FastNodingValidator} to perform the validation.
27  * 
28  * @version 1.7
29  * 
30  * @see FastNodingValidator
31  */
32 public class EdgeNodingValidator 
33 {  
34     /**
35    * Checks whether the supplied {@link Edge}s
36    * are correctly noded.  
37    * Throws a  {@link TopologyException} if they are not.
38    * 
39    * @param edges a collection of Edges.
40    * @throws TopologyException if the SegmentStrings are not correctly noded
41    *
42    */
43     public static void checkValid(Collection edges)
44     {
45         EdgeNodingValidator validator = new EdgeNodingValidator(edges);
46         validator.checkValid();
47     }
48     
49   public static Collection toSegmentStrings(Collection edges)
50   {
51     // convert Edges to SegmentStrings
52     Collection segStrings = new ArrayList();
53     for (Iterator i = edges.iterator(); i.hasNext(); ) {
54       Edge e = (Edge) i.next();
55       segStrings.add(new BasicSegmentString(e.getCoordinates(), e));
56     }
57     return segStrings;
58   }
59  
60   private FastNodingValidator nv;
61  
62   /**
63    * Creates a new validator for the given collection of {@link Edge}s.
64    * 
65    * @param edges a collection of Edges.
66    */
67   public EdgeNodingValidator(Collection edges)
68   {
69     nv = new FastNodingValidator(toSegmentStrings(edges));
70   }
71  
72   /**
73    * Checks whether the supplied edges
74    * are correctly noded.  Throws an exception if they are not.
75    * 
76    * @throws TopologyException if the SegmentStrings are not correctly noded
77    *
78    */
79   public void checkValid()
80   {
81     nv.checkValid();
82   }
83  
84 }
85