public bool Equals(Edge <T> other) { return(other != null && StartVertex.Equals(other.StartVertex) && EndVertex.Equals(other.EndVertex) && Weight.Equals(other.Weight)); }
public bool ConnectsTo(Vertex <TV, TE, TF> vertex) { if (vertex == null) { return(false); } return(EndVertex.Equals(vertex) || StartVertex.Equals(vertex)); }
//---------------------------------PRIVATES-------------------------------------// /** * Sets an end as vertex (starting point if none end were defined, ending point otherwise) * * @param vertex the vertex that is an segment end * @return false if all the ends were already defined, true otherwise */ private bool SetVertex(Vertex vertex) { //none end were defined - define starting point as VERTEX if (NumEndsSet == 0) { StartVertex = vertex; StartType = VERTEX; StartDistance = line.ComputePointToPointDistance(vertex.Position); StartPosition = StartVertex.Position; NumEndsSet++; return(true); } //starting point were defined - define ending point as VERTEX if (NumEndsSet == 1) { EndVertex = vertex; EndType = VERTEX; EndDistance = line.ComputePointToPointDistance(vertex.Position); EndPosition = EndVertex.Position; NumEndsSet++; //defining middle based on the starting point //VERTEX-VERTEX-VERTEX if (StartVertex.Equals(EndVertex)) { IntermediateType = VERTEX; } //VERTEX-EDGE-VERTEX else if (StartType == VERTEX) { IntermediateType = EDGE; } //the ending point distance should be smaller than starting point distance if (StartDistance > EndDistance) { SwapEnds(); } return(true); } else { return(false); } }
//public Line AsLine() //{ // return Line.ByStartPointEndPoint(StartVertex.AsPoint(), EndVertex.AsPoint()); //} #region override methods //TODO: Improve overriding equality methods as per http://www.loganfranken.com/blog/687/overriding-equals-in-c-part-1/ /// <summary> /// Override of Equal Method /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } gEdge e = (gEdge)obj; if (StartVertex.Equals(e.StartVertex) && EndVertex.Equals(e.EndVertex)) { return(true); } if (StartVertex.Equals(e.EndVertex) && EndVertex.Equals(e.StartVertex)) { return(true); } return(false); }
/// <summary> /// Method to return the other end vertex of the gEdge /// </summary> /// <param name="vertex"></param> /// <returns></returns> public gVertex GetVertexPair(gVertex vertex) { return((StartVertex.Equals(vertex)) ? EndVertex : StartVertex); }
/// <summary> /// gEdge constructor by line /// </summary> /// <param name="line">line</param> /// <returns name="edge">edge</returns> //public static gEdge ByLine(Line line) //{ // gVertex start = gVertex.ByCoordinates(line.StartPoint.X, line.StartPoint.Y, line.StartPoint.Z); // gVertex end = gVertex.ByCoordinates(line.EndPoint.X, line.EndPoint.Y, line.EndPoint.Z); // return new gEdge(start, end); //} #endregion /// <summary> /// Method to check if vertex belongs to edge /// </summary> /// <param name="vertex"></param> /// <returns></returns> public bool Contains(gVertex vertex) { return(StartVertex.Equals(vertex) || EndVertex.Equals(vertex)); }
public bool Connects(Vertex <TV, TE, TF> start, Vertex <TV, TE, TF> end) { return(EndVertex.Equals(end) && StartVertex.Equals(start)); }