using System.IO; using Core.Gis.GeoApi.Geometries; namespace Core.GIS.NetTopologySuite.GeometriesGraph { /// /// /// public class Node : GraphComponent { /// /// Only non-null if this node is precise. /// protected ICoordinate coord = null; /// /// /// protected EdgeEndStar edges = null; /// /// /// /// /// public Node(ICoordinate coord, EdgeEndStar edges) { this.coord = coord; this.edges = edges; label = new Label(0, Locations.Null); } /// /// /// public override ICoordinate Coordinate { get { return coord; } } /// /// /// public override bool IsIsolated { get { return (label.GeometryCount == 1); } } /// /// /// public EdgeEndStar Edges { get { return edges; } } /// /// Add the edge to the list of edges at this node. /// /// public void Add(EdgeEnd e) { // Assert: start pt of e is equal to node point edges.Insert(e); e.Node = this; } /// /// /// /// public void MergeLabel(Node n) { MergeLabel(n.Label); } /// /// To merge labels for two nodes, /// the merged location for each LabelElement is computed. /// The location for the corresponding node LabelElement is set to the result, /// as long as the location is non-null. /// /// public void MergeLabel(Label label2) { for (int i = 0; i < 2; i++) { Locations loc = ComputeMergedLocation(label2, i); Locations thisLoc = label.GetLocation(i); if (thisLoc == Locations.Null) { label.SetLocation(i, loc); } } } /// /// /// /// /// public void SetLabel(int argIndex, Locations onLocation) { if (label == null) { label = new Label(argIndex, onLocation); } else { label.SetLocation(argIndex, onLocation); } } /// /// Updates the label of a node to BOUNDARY, /// obeying the mod-2 boundaryDetermination rule. /// /// public void SetLabelBoundary(int argIndex) { // determine the current location for the point (if any) Locations loc = Locations.Null; if (label != null) { loc = label.GetLocation(argIndex); } // flip the loc Locations newLoc; switch (loc) { case Locations.Boundary: newLoc = Locations.Interior; break; case Locations.Interior: newLoc = Locations.Boundary; break; default: newLoc = Locations.Boundary; break; } label.SetLocation(argIndex, newLoc); } /// /// The location for a given eltIndex for a node will be one /// of { Null, Interior, Boundary }. /// A node may be on both the boundary and the interior of a point; /// in this case, the rule is that the node is considered to be in the boundary. /// The merged location is the maximum of the two input values. /// /// /// public Locations ComputeMergedLocation(Label label2, int eltIndex) { var loc = label.GetLocation(eltIndex); if (!label2.IsNull(eltIndex)) { Locations nLoc = label2.GetLocation(eltIndex); if (loc != Locations.Boundary) { loc = nLoc; } } return loc; } /// /// /// /// public void Write(TextWriter outstream) { outstream.WriteLine("node " + coord + " lbl: " + label); } /// /// Basic nodes do not compute IMs. /// /// public override void ComputeIM(IntersectionMatrix im) {} /// /// /// /// public override string ToString() { return coord + " " + edges; } } }