private List <Point> GetAllPointsInWindingOrder() { //return Edges.SelectMany(e => e.Points).Distinct().ToList(); List <Point> points = new List <Point>(); // The edges were added in order, but we don't know if the points within the edges are in order. // Therefore we look at the previous edge to figoure out which point has allready been visited Edge previous = Edges.First(); foreach (Edge current in Edges.Skip(1).Take(Edges.Count - 2)) { if (points.Count == 0) { Point firstPoint = previous.PointOnlyInThis(current); points.Add(firstPoint); Point secondPoint = previous.PointInBoth(current); points.Add(secondPoint); } Point nextPoint = current.PointOnlyInThis(previous); points.Add(nextPoint); previous = current; } return(points); }
/// <summary> /// Removes all edges between vertices. /// Vertices still remains in graph but any of them are connected. /// </summary> public void ClearEdges() { while (Edges.Any()) { RemoveEdge(Edges.First()); } }
public Edge GetRightEdgeBy(Edge edge) { if (edge == null) { return(Edges.First()); } if (Edges.FirstOrDefault(item => item == edge) == null) { throw new System.Exception("Ребро должно принадлежать этому узлу!"); } if (edge == South) { return(East ?? Edges.FirstOrDefault(item => item != edge)); } if (edge == East) { return(South ?? Edges.FirstOrDefault(item => item != edge)); } if (edge == Nord) { return(West ?? Edges.FirstOrDefault(item => item != edge)); } if (edge == West) { return(Nord ?? Edges.FirstOrDefault(item => item != edge)); } throw new System.Exception("Ну такого просто не может быть!"); }
public bool HasNegativeCycles() { var originalNode = Edges.First().Key; var costs = NodeValues .Where(e => !e.Equals(originalNode)) .ToDictionary(e => e, e => new InfinityInt(true)); Dictionary <V, V> predecessors = NodeValues .Where(e => !e.Equals(originalNode)) .ToDictionary(e => e, e => default(V)); costs.Add(originalNode, new InfinityInt(0)); for (int i = 1; i <= NodeValues.Count + 1; i++) { foreach (KeyValuePair <V, List <Edge> > edges in Edges) { foreach (Edge e in edges.Value) { if (!costs[e.From.Value].IsInfinity && (costs[e.To.Value].IsInfinity || costs[e.From.Value].Value + e.Distance < costs[e.To.Value].Value)) { if (i == NodeValues.Count) { return(true); } costs[e.To.Value] = new InfinityInt(costs[e.From.Value].Value + e.Distance); predecessors[e.To.Value] = e.From.Value; } } } } return(false); }
/// <summary> /// Others the edge. /// </summary> /// <param name="thisVertex">The this vertex.</param> /// <param name="willAcceptNullAnswer">if set to <c>true</c> [will accept null answer].</param> /// <returns>Edge.</returns> public Edge OtherEdge(Vertex thisVertex, bool willAcceptNullAnswer = false) { if (willAcceptNullAnswer) { return(Edges.FirstOrDefault(e => e != null && e.To != thisVertex && e.From != thisVertex)); } return(Edges.First(e => e != null && e.To != thisVertex && e.From != thisVertex)); }
public int DistanceToAdjacent(GraphNode <TVal> other) { if (!IsAdjacent(other)) { throw new ArgumentException("this node is not adjacent"); } return(Edges.First(x => x.GetOther(this) == other).Weight); }
public string GetWeight(string vertexToName) { if (Name == vertexToName && Edges.All(e => e.VertexTo.Name != vertexToName)) { return(string.Empty); } return(Edges.First(e => e.VertexTo.Name == vertexToName).GetWeightString()); }
/// <summary> /// Enumerates all the interior angles of the polygon. /// </summary> public IEnumerable <Angle> Angles() { for (int i = 1; i < Edges.Count; i++) { var previous = Edges[i - 1]; var next = Edges[i]; yield return(next.AngleBetween(previous).Supplement()); } yield return(Edges.First().AngleBetween(Edges.Last()).Supplement()); }
private Line _getNormalLine() { IVector vector1 = (Edges.OrderBy(s => s.EndPoint.X).ThenBy(s => s.EndPoint.Y).ThenByUnit(s => s.EndPoint.Z) .First()); IVector vector2 = Edges.First(s => s.BasePoint == vector1.EndPoint); var normal = vector1.Direction.CrossProduct(vector2.Direction); return(new Line(vector1.BasePoint, normal)); }
private void changeColor(List <Pair <int, int> > target, Color color) { changeAllColor(Colors.Black); foreach (var result in target) { var edge = Edges.First(i => (i.Pos.First.Key == result.First && i.Pos.Second.Key == result.Second) || (i.Pos.Second.Key == result.First && i.Pos.First.Key == result.Second)); edge.Color = new SolidColorBrush(color); } }
public void SetupParallelEdges(int edge1Id, int edge2Id, bool parallel) { var edge1 = Edges.First(e => e.Id == edge1Id); var edge2 = Edges.First(e => e.Id == edge2Id); var vertex11 = Vertices.First(v => v.Id == edge1.Vertices[0].Id); var vertex12 = Vertices.First(v => v.Id == edge1.Vertices[1].Id); var vertex21 = Vertices.First(v => v.Id == edge2.Vertices[0].Id); var vertex22 = Vertices.First(v => v.Id == edge2.Vertices[1].Id); var intEdges = new List <int> { edge1Id, edge2Id }; var intVertices = new List <int>(); if (vertex11.Point.X < vertex12.Point.X) { intVertices.Add(vertex11.Id); intVertices.Add(vertex12.Id); } else { intVertices.Add(vertex12.Id); intVertices.Add(vertex11.Id); } if (vertex21.Point.X < vertex22.Point.X) { intVertices.Add(vertex21.Id); intVertices.Add(vertex22.Id); } else { intVertices.Add(vertex22.Id); intVertices.Add(vertex21.Id); } var parallelEdges = new ParallelEdges { Parallel = parallel, Edges = intEdges, Vertices = intVertices }; ParallelPairs.Add(parallelEdges); }
/// <summary> /// Removes an edge between two vertices, if such edge exists. /// </summary> public void RemoveEdge(IVertex <T> startVertex, IVertex <T> endVertex) { if (!ContainsVertex(startVertex) || !ContainsVertex(endVertex)) { throw new InvalidOperationException("One or more vertex does not belong to graph."); } if (!AreAdjacent(startVertex, endVertex)) { throw new InvalidOperationException("There is no such edge in the graph."); } var edge = Edges.First(x => x.StartVertex.Equals(startVertex) && x.EndVertex.Equals(endVertex)); Edges.Remove(edge); edge.CurrentGraph = null; }
private async Task show(List <Pair <int, int> > target, Color color) { await exactStop(); Logs.Add(new LogViewModel("start shower")); _cts = new CancellationTokenSource(); try { changeAllColor(Colors.Black); await Task.Delay(500, _cts.Token); while (true) { foreach (var result in target) { var edge = Edges.First(i => (i.Pos.First.Key == result.First && i.Pos.Second.Key == result.Second) || (i.Pos.Second.Key == result.First && i.Pos.First.Key == result.Second)); edge.Color = new SolidColorBrush(color); await Task.Delay(1000, _cts.Token); } changeAllColor(Colors.Black); await Task.Delay(1000, _cts.Token); } } catch (OperationCanceledException) { changeAllColor(Colors.Black); _cts = null; Logs.Add(new LogViewModel("stop shower")); } }
public IEdge GetEdge(object from, object to) { if (!(from is double) || !(to is double)) { throw new ArgumentException("Only double accepted"); } if (!Nodes.ContainsKey(from) || !Nodes.ContainsKey(to)) { throw new ArgumentException("Node not find"); } IEdge ed; try { ed = Edges.First((IEdge e) => (double)e.From == (double)from && (double)e.To == (double)to || (double)e.From == (double)to && (double)e.To == (double)from); } catch (Exception ex) { return(null); } return(ed); }
public void Redraw(bool clear = false) { if (clear) { foreach (var vertex in Vertices) { _window.DrawDot(vertex.Point, Color.White); } } else { foreach (var vertex in Vertices) { _window.DrawDot(vertex.Point, Color.Crimson); } } var parallels = new List <int>(); var perpendiculars = new List <int>(); foreach (var parallelPair in ParallelPairs) { if (parallelPair.Parallel) { parallels.Add(parallelPair.Edges[0]); parallels.Add(parallelPair.Edges[1]); } else { perpendiculars.Add(parallelPair.Edges[0]); perpendiculars.Add(parallelPair.Edges[1]); } } foreach (var dot in DotsToClear) { _window.DrawDot(dot, Color.White); } DotsToClear = new List <Point>(); int i = 0; if (!clear) { foreach (var parallelPair in ParallelPairs) { foreach (var edgeInt in parallelPair.Edges) { var edge = Edges.First(e => e.Id == edgeInt); var start = edge.Points.First(); var end = edge.Points.Last(); var midPoint = new Point((start.X + end.X) / 2, (start.Y + end.Y) / 2); _window.DrawDot(midPoint, _dotColors[i]); DotsToClear.Add(midPoint); } i = (i + 1) % _dotColors.Length; } } foreach (var edge in Edges) { if (clear) { _window.DrawPoints(edge.Points, Color.White); } else { _window.DrawPoints(edge.Points, _color); } } }
public Edge GetEdgeByPredicate(object value) { return(Edges.First(e => e.Predicate.Value == value)); }
/// <summary> /// Get edge which is connection between two nodes. /// </summary> /// <param name="node1">One of all available nodes from List of Nodes. /// <seealso cref="AISDEProject.Node"/> /// </param> /// <param name="node2">Second remaining node from List of Nodes. /// <seealso cref="AISDEProject.Node"/> /// </param> /// <returns>Method returns Edge with these two nodes.<seealso cref="AISDEProject.Edge"/></returns> Edge GetEdge(Node node1, Node node2) => Edges. First(e => (e.Begin.Equals(node1) && e.End.Equals(node2)) || (e.Begin.Equals(node2) && e.End.Equals(node1)));
public GroundEdge GetEdge(GroundPoint pointA, GroundPoint pointB) { return(Edges.First(edge => (edge.PointA == pointA && edge.PointB == pointB) || (edge.PointA == pointB && edge.PointB == pointA))); }
public Edge GetEdge(Vertex other) { return(Edges.First((e) => e.Contains(other))); }