protected void GetNextDirection(ref EdgeDirection dir1, ref EdgeDirection dir2) { Tuple <EdgeDirection, EdgeDirection> res = null; bool nextIsRes = false; foreach (var d1 in GetPossibleDirections(Node1)) { foreach (var d2 in GetPossibleDirections(Node2)) { if (res == null) { res = new Tuple <EdgeDirection, EdgeDirection>(d1, d2); } if (nextIsRes) { res = new Tuple <EdgeDirection, EdgeDirection>(d1, d2); goto next; } if (d1 == dir1 && d2 == dir2) { nextIsRes = true; } } } next: if (res == null) { res = new Tuple <EdgeDirection, EdgeDirection>(EdgeDirection.None, EdgeDirection.None); } dir1 = res.Item1; dir2 = res.Item2; }
public IEdge ConnectTo(INode otherNode, EdgeDirection direction) { Objects.RequireNonNull(otherNode); var edge = factory.CreateEdge(this, otherNode, direction); return(this.ConnectTo(otherNode, edge)); }
public Edge() { _source = -1; _destination = -1; _weight = -1; _direction = EdgeDirection.Bidirectional; }
public override IEdge CreateEdge(INode nodeA, INode nodeB, EdgeDirection direction) { var edge = new PartitionEdge(nodeA, nodeB, direction, this.baseEntityFactory); logger.Trace("Created new edge: {0}", edge); return(edge); }
public Edge(INode nodeA, INode nodeB, EdgeDirection direction, IEntityFactory factory) : base(factory) { this.endA = nodeA; this.endB = nodeB; this.direction = direction; }
private void CheckDegree(LayoutVertexBase vertex, EdgeDirection direction) { if (vertex.IsDummy && this.Degree(vertex, direction) > 1) { throw new InvalidOperationException($"Dummy vertex {vertex} cannot have more than 1 {direction}-edges."); } }
public static Rectangle ShiftRectangleEdge(Rectangle rect, EdgeDirection edgeToMove, int distTomove) { // Find edge to move switch (edgeToMove) { case EdgeDirection.Left: rect.X -= distTomove; rect.Width += distTomove; break; case EdgeDirection.Right: rect.Width += distTomove; break; case EdgeDirection.Top: rect.Y -= distTomove; rect.Height += distTomove; break; case EdgeDirection.Bottom: rect.Height += distTomove; break; } return(rect); }
static bool CheckEdgeAndAdd(List <Vector2> result, EdgeDirection direction, int x, int y, int tileSize, Color[] pixels) { while (x >= 0 && y >= 0 && x < tileSize && y < tileSize) { if (pixels[y * tileSize + x].a > 0.5f) { // int xMod = Snap( x, tileSize ); // int yMod = Snap( y, tileSize ); // Vector2 thisPoint = new Vector2( (float)(xMod) / (float)(tileSize), (float)(yMod) / (float)(tileSize) ); AddToList(result, Snap(x, tileSize), Snap(y, tileSize), tileSize); return(true); } switch (direction) { case EdgeDirection.Down: y--; break; case EdgeDirection.Up: default: y++; break; case EdgeDirection.Left: x--; break; case EdgeDirection.Right: x++; break; } } return(false); }
private void AddEdge(Task task, Object resource, EdgeDirection direction) { if (!taskToInt.ContainsKey(task)) { adjacencyList.Add(counterForMapping, new List <int>()); taskToInt.Add(task, counterForMapping++); } if (!resourceToInt.ContainsKey(resource)) { adjacencyList.Add(counterForMapping, new List <int>()); resourceToInt.Add(resource, counterForMapping++); } if (direction == EdgeDirection.Normal) { if (SimpleTaskScheduler.IsVerbose) { Console.WriteLine("Added edge task " + task.GetHashCode() + " to resource " + resource.GetHashCode()); } AddEdge(taskToInt[task], resourceToInt[resource]); } else if (direction == EdgeDirection.Inverted) { if (SimpleTaskScheduler.IsVerbose) { Console.WriteLine("Added edge resource " + resource.GetHashCode() + " to task " + task.GetHashCode()); } AddEdge(resourceToInt[resource], taskToInt[task]); } }
private static int[,] EdgeHelperv2(double scale, int[,] im, double threshold, double[,] filter, double[,] filterT, double fdiv, EdgeDirection direction) { int[,] result = new int[im.GetLength(0), im.GetLength(1)]; double[,] b = new double[im.GetLength(0), im.GetLength(1)]; double cutoff = 0; double tresh = 0; //Sobel approximation to derivative var bx = ImageFilter.Filter_double(im, filterT, fdiv); var by = ImageFilter.Filter_double(im, filter, fdiv); //compute the magnitude if (direction == EdgeDirection.horizontal) { b = by.PowArrayElements(2); } else if (direction == EdgeDirection.vertical) { b = bx.PowArrayElements(2); } else if (direction == EdgeDirection.both || direction == EdgeDirection.def) { b = bx.PowArrayElements(2).SumArrays(by.PowArrayElements(2)); } else { Console.WriteLine("Wrong direction"); } if (threshold == 0) { cutoff = scale * b.Cast <double>().ToArray().Average(); tresh = Math.Sqrt(cutoff); } else { cutoff = Math.Pow(threshold, 2); } for (int i = 0; i < im.GetLength(0); i++) { for (int j = 0; j < im.GetLength(1); j++) { if (b[i, j] > cutoff) { result[i, j] = 255; } else { result[i, j] = 0; } } } return(result); }
public Edge(int source, int destination, int weight = 0, EdgeDirection direction = EdgeDirection.Bidirectional) { _source = source; _destination = destination; _weight = weight; _direction = direction; }
public static IEnumerable <TEdge> GetEdges <TVertex, TEdge>( this IBidirectionalGraph <TVertex, TEdge> graph, TVertex vertex, EdgeDirection edgeDirection) where TEdge : IEdge <TVertex> { return(edgeDirection == EdgeDirection.In ? graph.InEdges(vertex) : graph.OutEdges(vertex)); }
public static IEnumerable <TVertex> GetNeighbours <TVertex, TEdge>( this IBidirectionalGraph <TVertex, TEdge> graph, TVertex vertex, EdgeDirection edgeDirection) where TEdge : IEdge <TVertex> { return(edgeDirection == EdgeDirection.In ? graph.GetInNeighbours(vertex) : graph.GetOutNeighbours(vertex)); }
public Edge(int id, Node left, Node right, EdgeDirection direction = EdgeDirection.None, int weight = 1) { Id = id; Left = left; Right = right; Direction = direction; Weight = weight; }
private List <EdgeNodeDto> GetOfficer(List <EdgeDto> edges, EdgeDirection dir) { if (dir == EdgeDirection.FromCaller) { var query = from E in edges join off in _database.GetCollection <OfficerDto>("officer").AsQueryable() on E.To equals off.NodeId select new { OfficerId = off.NodeId, OfficerName = off.Name, EdgeFrom = E.From, EdgeTo = E.To, EdgeType = E.Type, EdgeLink = E.Link }; var results = query.ToList(); return(results.Select(q => new EdgeNodeDto() { Edge = new EdgeDto() { From = q.EdgeFrom, To = q.EdgeTo, Link = q.EdgeLink }, Node = new NodeDto() { Id = q.OfficerId, Label = q.OfficerName, NodeType = NodeType.Officer } }).ToList()); } else { var query = from E in edges join off in _database.GetCollection <OfficerDto>("officer").AsQueryable() on E.From equals off.NodeId select new { OfficerId = off.NodeId, OfficerName = off.Name, EdgeFrom = E.From, EdgeTo = E.To, EdgeType = E.Type, EdgeLink = E.Link }; var results = query.ToList(); return(results.Select(q => new EdgeNodeDto() { Edge = new EdgeDto() { From = q.EdgeFrom, To = q.EdgeTo, Link = q.EdgeLink }, Node = new NodeDto() { Id = q.OfficerId, Label = q.OfficerName, NodeType = NodeType.Officer } }).ToList()); } }
} // TODO: calculate in graph layout pass public EdgeConfig(int source, EdgeDirection sourcePosition, int destination, string archetypeName, int weight = 1, int length = 1) { Source = source; SourcePosition = sourcePosition; Destination = destination; Weight = weight; Length = length; Archetype = archetypeName; }
public static void ExecuteOnEdgesRecursive <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph, TEdge edge, EdgeDirection edgeDirection, Action <TEdge> actionOnEdge) where TEdge : IEdge <TVertex> { actionOnEdge(edge); foreach (var nextEdge in graph.GetEdges(edge.GetEndVertex(edgeDirection), edgeDirection)) { graph.ExecuteOnEdgesRecursive(nextEdge, edgeDirection, actionOnEdge); } }
private void RemoveEdge(Task task, Object resource, EdgeDirection direction) { if (direction == EdgeDirection.Normal) { RemoveEdge(taskToInt[task], resourceToInt[resource]); } else if (direction == EdgeDirection.Inverted) { RemoveEdge(resourceToInt[resource], taskToInt[task]); } }
public static EdgeAttribute Direction(EdgeDirection direction) { if (!direction.IsValid()) { throw new ArgumentException($"The { nameof(EdgeDirection) } provided must be a valid enum.", nameof(direction)); } var directionStr = direction.AsString().ToLowerInvariant(); return(new EdgeAttribute("dir", directionStr)); }
public Edge(Vertex Vertex1, Vertex Vertex2, string Type, string Relationship, string Comment, int Weight) { this.Vertex1 = Vertex1; this.Vertex2 = Vertex2; this.Type = Type; this.Relationship = Relationship; this.Comment = Comment; this.Weight = Weight; this.FeedOfOrigin = ""; this.Direction = EdgeDirection.Undirected; }
public static IShortestPathQueryable <ShortestPathData <TVertex, TEdge> > Edge <TVertex, TEdge>( this IShortestPathQueryable <ShortestPathData <TVertex, TEdge> > source, string collectionName, EdgeDirection direction) { return(source.Provider.CreateQuery <ShortestPathData <TVertex, TEdge> >( Expression.Call( ArangoQueryableExtensions.FindExtention("ShortestPath_Edge_Direction", typeof(TVertex), typeof(TEdge)), source.Expression, Expression.Constant(collectionName), Expression.Constant(direction) )) as IShortestPathQueryable <ShortestPathData <TVertex, TEdge> >); }
/// <summary> Get direction vector along some edge </summary> protected PointF GetDir(Node node, EdgeDirection dir) { var e = node.GetEdge(dir); if (e == null || e == Edge) { return(PointF.Empty); } var node2 = e.GetOtherNode(node); var res = node2.LocationF.Sub(node.LocationF).Normalized(); return(res); }
public static Pix SobelEdgeFilter(Pix pix, EdgeDirection orientflag = EdgeDirection.All) { if (pix.Depth != 8) { pix = Convert.ConvertTo8(pix); } IntPtr p = LeptonicaNativeApi.Native.pixSobelEdgeFilter(pix.Reference, orientflag); if (p == IntPtr.Zero) { throw new NullReferenceException("failed to edge."); } return(Pix.Create(p)); }
public IEnumerable <TVertex> GetAdjacentVertices(TVertexId vertexId, EdgeDirection direction, EdgePredicate <TVertex, TEdge> edgePredicate = null, bool recursive = false) { if (!ContainsVertex(vertexId)) { return(Enumerable.Empty <TVertex>()); } var vertexIds = _graph.GetAdjacentVertices(vertexId, direction, edge => edgePredicate == null || edgePredicate(GetEdge(edge.Id)), recursive); return(vertexIds.Select(GetVertex)); }
public void GoNextDirection() { //find parallel connected edges foreach (var d in GetPossibleDirections(Node1, EdgeDirection)) { var e1 = Node1.GetEdge(d); var e2 = Node2.GetEdge(d); if (e1 != null && e1 != Edge && e2 != null && e2 != Edge) { EdgeDirection = d; break; } } }
//List<RaycastHit> GetEdgeLoop(float p_height) void GetEdgeLoop(float p_height) { //Finds an edge loop at height p_height RaycastHit hitDetails; Vector3 referenceRay = new Vector3(); List <RaycastHit> edgeLoop = new List <RaycastHit>(); Vector3 centre = new Vector3(); Vector3 pointOnCircumference = new Vector3(); //First ray will be cast to this point Vector3 startPoint = new Vector3(); Vector3 endPoint = new Vector3(); EdgeDirection firstPointSpot = (EdgeDirection)Random.Range(0, System.Enum.GetValues(typeof(EdgeDirection)).Length); centre = climbingSurfaceBounds.center; centre.y = p_height; pointOnCircumference = frontLeft + frontLeftMultiplier; pointOnCircumference.y = p_height; Quaternion q; Vector3 d; referenceRay = pointOnCircumference - centre; float i = 0.0f; Debug.DrawRay(centre, referenceRay, Color.black, 3.0f); while (i <= 360.0f) { //Find the Quaternion corresponding to rotating anything i degree around Y-Axis q = Quaternion.AngleAxis(i, Vector3.up); //Apply the rotation to the scanner Ray d = q * referenceRay; i += 0.01f; startPoint = centre + d; endPoint = centre; hitDetails = new RaycastHit(); //Perform a raycast to find a point and it's normal if (Physics.Raycast(startPoint, (endPoint - startPoint), out hitDetails, d.magnitude, climbingSurfaceLayer)) { edgeLoop.Add(hitDetails); } } allEdgeLoops.Add(edgeLoop); }
protected IEnumerable <EdgeDirection> GetPossibleDirections(Node node, EdgeDirection after) { for (int add = 1; add <= 4; add++) { var d = (EdgeDirection)(((int)after + add) % 5); if (d != after) { var e = node.GetEdge(d); if (e != null && e != Edge) { yield return(d); } } } }
public Edge(Vertex Vertex1, Vertex Vertex2, string Type, string Relationship, string Comment, int Weight, int Timestamp, string FeedOfOrigin, EdgeDirection eDirection) { this.Vertex1 = Vertex1; this.Vertex2 = Vertex2; this.Type = Type; this.Relationship = Relationship; this.Comment = Comment; this.Weight = Weight; this.FeedOfOrigin = FeedOfOrigin; if (Timestamp > 0) this.Timestamp = DateUtil.ConvertToDateTime(Timestamp); this.Direction = eDirection; }
//查找类型为指定Type的连边: 字面量 public IEnumerable <Edge> GetEdgesByType(string attribute, EdgeDirection direction) { if (attribute == null) { return(new List <Edge>()); } if (direction == EdgeDirection.In) { return(InBound.Where(x => x.Attribute == attribute)); } if (direction == EdgeDirection.Out) { return(OutBound.Where(x => x.Attribute == attribute)); } return(new List <Edge>()); }
//查找目标为指定GUID的连边 public IEnumerable <IEdge> GetEdgesByGuid(string nodeGuid, EdgeDirection direction) { if (nodeGuid == null) { return(new List <IEdge>()); } if (direction == EdgeDirection.In) { return(InBound.Where(x => x.From.Guid == nodeGuid)); } if (direction == EdgeDirection.Out) { return(OutBound.Where(x => x.To.Guid == nodeGuid)); } return(new List <IEdge>()); }
//查找类型为指定Type的连边 public IEnumerable <Edge> GetEdgesByType(IEnumerable <Type> types, EdgeDirection direction) { if (types == null) { return(new List <Edge>()); } if (direction == EdgeDirection.In) { return(InBound.Where(x => types.Contains(x.GetType()))); } if (direction == EdgeDirection.Out) { return(OutBound.Where(x => types.Contains(x.GetType()))); } return(new List <Edge>()); }
//查找目标为指定Name的连边 public IEnumerable <Edge> GetEdgesByName(string nodeName, EdgeDirection direction) { if (nodeName == null) { return(new List <Edge>()); } if (direction == EdgeDirection.In) { return(InBound.Where(x => x.From.Name == nodeName)); } if (direction == EdgeDirection.Out) { return(OutBound.Where(x => x.To.Name == nodeName)); } return(new List <Edge>()); }
public static string EdgeDirectionToString(EdgeDirection direction) { switch (direction) { case EdgeDirection.Any: return("any"); case EdgeDirection.Inbound: return("inbound"); case EdgeDirection.Outbound: return("outbound"); default: throw new InvalidOperationException($"EdgeDirection {direction} binding not found, this is a client bug"); } }
/// <summary> /// Creates an edge connection between two neighbors. /// </summary> /// <param name="currentMapGraphicsTile"></param> /// <param name="neighborsMapGraphicsTile"></param> /// <param name="edgeDirection"></param> private void CreateEdgeConnectionBetweenNeighbors(MapGraphicsTile currentMapGraphicsTile, MapGraphicsTile neighborsMapGraphicsTile, EdgeDirection edgeDirection) { EdgeConnection edgeConnection = new EdgeConnection(CreateEdgeConnection(edgeDirection),true); currentMapGraphicsTile.ShoreEdgePoints.Add(edgeConnection); neighborsMapGraphicsTile.ShoreEdgePoints.Add(new EdgeConnection(edgeConnection.TranslateConnectionForNeighbor(), true)); }
public Edge(Point p1, Point p2) { _points = new[] { p1, p2 }; direction = new EdgeDirection(this, false); inverseDirection = new EdgeDirection(this, true); }
private int RotationDirection(EdgeDirection previousDirection, EdgeDirection currentDirection) { if (currentDirection == EdgeDirection.Left && previousDirection == EdgeDirection.Bottom) return 1; if (currentDirection == EdgeDirection.Bottom && previousDirection == EdgeDirection.Left) return -1; return currentDirection - previousDirection; }
public void ReverseEdges() { _currentDirection = _currentDirection == EdgeDirection.LeftToRight ? EdgeDirection.RightToLeft : EdgeDirection.LeftToRight; }
internal void RecalculateNextRightDirection() { var prev = a; var curr = b; float minAngle = float.PositiveInfinity; Edge nextEdge = null; foreach (var edge in curr.edges) { if (edge == this.edge) continue; var next = edge.GetInvert(curr); var angleClockwise = m.rightAngle(prev.value, curr.value, next.value); if (angleClockwise < minAngle) { minAngle = angleClockwise; nextEdge = edge; } } if (nextEdge == null) nextEdge = this.edge; nextRightDir = nextEdge.GetRightDirection(b); }
public List<m.polygon> CalculatePolygons(bool withJoin) { if (withJoin) JoinAll(); var directedLines = new EdgeDirection[edges.Count * 2]; //Связываем правые стороны векторов for (int i = 0; i < edges.Count; i++) { var edge = edges[i]; directedLines[i] = edge.direction; directedLines[edges.Count + i] = edge.inverseDirection; edge.direction.RecalculateNextRightDirection(); edge.inverseDirection.RecalculateNextRightDirection(); edge.direction.used = false; edge.inverseDirection.used = false; } //Находим полигоны var polygons = new List<m.polygon>(); for (int i = 0; i < directedLines.Length; i++) { var dir = directedLines[i]; if (dir.used) continue; var path = new List<EdgeDirection>(); int error = 0; while (true) { dir.used = true; path.Add(dir); if (dir.nextRightDir.used)//exit { var firstIndex = path.IndexOf(dir.nextRightDir); if (firstIndex == -1) break; var polygon = new m.polygon<List<EdgeDirection>> {tag = new List<EdgeDirection>()}; for (int j = firstIndex; j < path.Count; j++) { var e = path[j]; polygon.points.Add(e.b.value); polygon.tag.Add(e); e.edge.conditionTouchCount = 0; } if (m.area.simplePolygon(polygon.points.Select(x => (Vector2)x).ToArray()) < 0f) polygons.Add(polygon); break; } dir = dir.nextRightDir; if (error >= directedLines.Length) { Debug.LogWarning("Error"); break; } error++; } } return polygons; }
/// <summary> /// Creates a random edge connection /// </summary> /// <param name="mapGraphicsTile"></param> /// <param name="edgeDirection"></param> private byte CreateEdgeConnection(EdgeDirection edgeDirection) { int min = 0; int max = 0; if (edgeDirection == EdgeDirection.Bottom) { min = 1; max = 3; } else if (edgeDirection == EdgeDirection.Top) { min = 7; max = 9; } else if (edgeDirection == EdgeDirection.Right) { min = 4; max = 6; } else if (edgeDirection == EdgeDirection.Left) { min = 10; max = 12; } return (byte)rnd.Next(min, max); }
/// <summary> /// /// </summary> /// <param name="processKey"></param> /// <param name="varKey"></param> /// <param name="direction"></param> public EdgeInfo(string processKey, string varKey, EdgeDirection direction) { m_proKey = processKey; // Set Relation if (direction == EdgeDirection.Inward) { m_direction = EdgeDirection.Inward; m_type = LineType.Solid; } else if (direction == EdgeDirection.None) { m_direction = EdgeDirection.None; m_type = LineType.Dashed; } else if (direction == EdgeDirection.Outward) { m_direction = EdgeDirection.Outward; m_type = LineType.Solid; } else { m_direction = EdgeDirection.Bidirection; m_type = LineType.Solid; } m_varKey = varKey; }
/// <summary> /// Constructor /// </summary> /// <param name="processKey">The key of process.</param> /// <param name="er">The reference of EcellObject.</param> public EdgeInfo(string processKey, EcellReference er) { m_proKey = processKey; // Set Relation int coef = er.Coefficient; if (coef < 0) { m_direction = EdgeDirection.Inward; m_type = LineType.Solid; } else if (coef == 0) { m_direction = EdgeDirection.None; m_type = LineType.Dashed; } else { m_direction = EdgeDirection.Outward; m_type = LineType.Solid; } m_varKey = er.Key; }
/// <summary> /// Constructor /// </summary> /// <param name="processKey"></param> /// <param name="list"></param> /// <param name="er"></param> public EdgeInfo(string processKey, List<EcellReference> list, EcellReference er) { m_isEndNode = CheckEndNode(list); bool bidir = CheckBidir(list, er); m_proKey = processKey; m_varKey = er.Key; // Set Relation int l_coef = er.Coefficient; if (bidir) { m_direction = EdgeDirection.Bidirection; m_type = LineType.Solid; } else if (l_coef < 0) { m_direction = EdgeDirection.Inward; m_type = LineType.Solid; } else if (l_coef == 0) { m_direction = EdgeDirection.None; m_type = LineType.Dashed; } else { m_direction = EdgeDirection.Outward; m_type = LineType.Solid; } }
/// <summary> /// Sets the Neighbors Edge Connection based on /// </summary> /// <param name="currentMapGraphicsTile"></param> /// <param name="neighborsMapGraphicsTile"></param> /// <param name="edgeDirection"></param> private void GetNeighborsEdgeConnection(MapGraphicsTile currentMapGraphicsTile, MapGraphicsTile neighborsMapGraphicsTile, EdgeDirection edgeDirection) { if (edgeDirection == EdgeDirection.Top && !neighborsMapGraphicsTile.ShoreEdgePoints.Exists(x => x.EdgePosition > 0 && x.EdgePosition < 3)) { CreateEdgeConnectionBetweenNeighbors(currentMapGraphicsTile, neighborsMapGraphicsTile, edgeDirection); currentMapGraphicsTile.TopEdgeType = EdgeType.Both; } else if (edgeDirection == EdgeDirection.Bottom && !neighborsMapGraphicsTile.ShoreEdgePoints.Exists(x => x.EdgePosition > 6 && x.EdgePosition < 10)) { CreateEdgeConnectionBetweenNeighbors(currentMapGraphicsTile, neighborsMapGraphicsTile, edgeDirection); currentMapGraphicsTile.BottomEdgeType = EdgeType.Both; } else if (edgeDirection == EdgeDirection.Left && !neighborsMapGraphicsTile.ShoreEdgePoints.Exists(x => x.EdgePosition > 3 && x.EdgePosition < 7)) { CreateEdgeConnectionBetweenNeighbors(currentMapGraphicsTile, neighborsMapGraphicsTile, edgeDirection); currentMapGraphicsTile.BottomEdgeType = EdgeType.Both; } else if (edgeDirection == EdgeDirection.Right && !neighborsMapGraphicsTile.ShoreEdgePoints.Exists(x => x.EdgePosition > 9 && x.EdgePosition < 13)) { CreateEdgeConnectionBetweenNeighbors(currentMapGraphicsTile, neighborsMapGraphicsTile, edgeDirection); currentMapGraphicsTile.BottomEdgeType = EdgeType.Both; } }