Class GraphComponent

 1  
 2  
 3  
 4 /*
 5  * Copyright (c) 2016 Vivid Solutions.
 6  *
 7  * All rights reserved. This program and the accompanying materials
 8  * are made available under the terms of the Eclipse Public License 2.0
 9  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
10  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
11  * and the Eclipse Distribution License is available at
12  *
13  * http://www.eclipse.org/org/documents/edl-v10.php.
14  */
15 package org.locationtech.jts.geomgraph;
16  
17 import org.locationtech.jts.geom.Coordinate;
18 import org.locationtech.jts.geom.IntersectionMatrix;
19 import org.locationtech.jts.util.Assert;
20  
21 /**
22  * A GraphComponent is the parent class for the objects'
23  * that form a graph.  Each GraphComponent can carry a
24  * Label.
25  * @version 1.7
26  */
27 abstract public class GraphComponent {
28  
29   protected Label label;
30   /**
31    * isInResult indicates if this component has already been included in the result
32    */
33   private boolean isInResult = false;
34   private boolean isCovered = false;
35   private boolean isCoveredSet = false;
36   private boolean isVisited = false;
37  
38   public GraphComponent() {
39   }
40  
41   public GraphComponent(Label label) {
42     this.label = label;
43   }
44  
45   public Label getLabel() { return label; }
46   public void setLabel(Label label) { this.label = label; }
47   public void setInResult(boolean isInResult) { this.isInResult = isInResult; }
48   public boolean isInResult() { return isInResult; }
49   public void setCovered(boolean isCovered)
50   {
51     this.isCovered = isCovered;
52     this.isCoveredSet = true;
53   }
54   public boolean isCovered()    { return isCovered; }
55   public boolean isCoveredSet() { return isCoveredSet; }
56   public boolean isVisited() { return isVisited; }
57   public void setVisited(boolean isVisited) { this.isVisited = isVisited; }
58   /**
59    * @return a coordinate in this component (or null, if there are none)
60    */
61   abstract public Coordinate getCoordinate();
62   /**
63    * compute the contribution to an IM for this component
64    */
65   abstract protected void computeIM(IntersectionMatrix im);
66   /**
67    * An isolated component is one that does not intersect or touch any other
68    * component.  This is the case if the label has valid locations for
69    * only a single Geometry.
70    *
71    * @return true if this component is isolated
72    */
73   abstract public boolean isIsolated();
74   /**
75    * Update the IM with the contribution for this component.
76    * A component only contributes if it has a labelling for both parent geometries
77    */
78   public void updateIM(IntersectionMatrix im)
79   {
80     Assert.isTrue(label.getGeometryCount() >= 2"found partial label");
81     computeIM(im);
82   }
83  
84 }
85