/// <summary> /// Test if the graph link lies within the rectangle /// </summary> /// <param name="outer">The rect to test against</param> /// <param name="link">The link to test the intersection</param> /// <returns>True if intersects, false otherwise</returns> public static bool Intersects(Rect outer, GraphLink link) { if (link == null || link.Input == null || link.Output == null) { return(false); } var p0 = link.Input.WorldPosition; var p1 = link.Output.WorldPosition; if (outer.Contains(p0) || outer.Contains(p1)) { return(true); } var x0 = outer.position.x; var x1 = outer.position.x + outer.size.x; var y0 = outer.position.y; var y1 = outer.position.y + outer.size.y; var outside = (p0.x < x0 && p1.x < x0) || (p0.x > x1 && p1.x > x1) || (p0.y < y0 && p1.y < y0) || (p0.y > y1 && p1.y > y1); return(!outside); }
public static void DrawGraphLink(GraphRendererContext rendererContext, GraphLink link, GraphCamera camera) { if (link.Input == null || link.Output == null) { // Link not initialized yet. nothing to draw return; } Vector2 startPos = camera.WorldToScreen(link.Output.WorldPosition); Vector2 endPos = camera.WorldToScreen(link.Input.WorldPosition); var tangentStrength = link.GetTangentStrength(); Vector3 startTan = startPos + link.Output.Tangent * tangentStrength; Vector3 endTan = endPos + link.Input.Tangent * tangentStrength; var lineColor = new Color(1, 1, 1, 0.75f); Handles.DrawBezier(startPos, endPos, startTan, endTan, lineColor, null, 3); // Draw the arrow cap var rotation = Quaternion.FromToRotation(new Vector3(1, 0, 0), link.Input.Tangent.normalized); float arrowSize = 10.0f; float arrowWidth = 0.5f; var arrowTails = new Vector2[] { rotation *new Vector3(1, arrowWidth) * arrowSize, rotation *new Vector3(1, -arrowWidth) * arrowSize, }; Handles.color = lineColor; //Handles.DrawPolyLine(arrowTails); Handles.DrawLine(endPos, endPos + arrowTails[0]); Handles.DrawLine(endPos, endPos + arrowTails[1]); Handles.DrawLine(endPos + arrowTails[0], endPos + arrowTails[1]); }
public GraphNode GraphNodeRecurs(GraphNode prt, string[] Nodes, int i) { String FullPath = ""; for (int x = 0; x <= i; x++) { if (x != 0) { FullPath += "."; } FullPath += Nodes[x]; } GraphNode node = null; node = graph.Nodes.GetOrCreate(FullPath.ToUpper()); node.Label = FullPath; if (prt != null) { GraphLink gl2 = graph.Links.GetOrCreate(prt, node, "", GraphCommonSchema.Contains); } if (i == (Nodes.Length - 1)) { return(node); } else { node.IsGroup = true; return(GraphNodeRecurs(node, Nodes, ++i)); } }
public void AddState(Moves move) { Platform agentPlatform = _model.AgentPlatform; if (agentPlatform != null) { if (agentPlatform.PercentageCollectiblesCaught < 100) { if (!_intraplatformPlayedStates.ContainsKey(agentPlatform.ID)) { _intraplatformPlayedStates.Add(agentPlatform.ID, new List <IntraPlatformPlayedGameStateInfo>()); } _intraplatformPlayedStates[agentPlatform.ID].Add(new IntraPlatformPlayedGameStateInfo(_model.GetGameState(), move, _model.AgentPlatform.ID, DateTime.Now)); } else { GraphLink closestLink = GetLink(); if (closestLink != null) { interPlatform = true; if (!_interplatformPlayedStates.ContainsKey(closestLink.ID)) { _interplatformPlayedStates.Add(closestLink.ID, new List <InterPlatformPlayedGameStateInfo>()); } _interplatformPlayedStates[closestLink.ID].Add(new InterPlatformPlayedGameStateInfo(_model.GetGameState(), move, closestLink, DateTime.Now)); } } } }
public InterPlatformPlayedGameStateInfo(GameState state, Moves move, GraphLink link, DateTime playedTime) { _state = state; _move = move; _link = link; _playedTime = playedTime; }
public void Destroy() { UnityEngine.Object.DestroyImmediate(mousePin); UnityEngine.Object.DestroyImmediate(link); mousePin = null; link = null; }
/// <summary> /// Destroys a node and removes all references of it from the graph model. Called when the node is deleted from the editor /// </summary> /// <param name="node"></param> public static void DestroyLink(GraphLink link) { var graph = link.Graph; Undo.RecordObject(graph, "Destroy Link"); graph.Links.Remove(link); Undo.DestroyObjectImmediate(link); }
public CursorDragLink(GraphEditor graphEditor) { this.graphEditor = graphEditor; mousePin = ScriptableObject.CreateInstance <GraphPin>(); mousePin.PinType = GraphPinType.Input; mousePin.name = "Cursor_DragPin"; link = ScriptableObject.CreateInstance <GraphLink>(); link.name = "Cursor_DragLink"; mousePin.hideFlags = HideFlags.HideAndDontSave; link.hideFlags = HideFlags.HideAndDontSave; }
internal void CloseLink(GraphLink link, DateTime endTime) { try { List <InterPlatformPlayedGameStateInfo> states = _interplatformPlayedStates[link.ID]; _interplatformPlayedStates.Remove(link.ID); link.StartTime = states[0].PlayedTime; foreach (InterPlatformPlayedGameStateInfo state in states) { UpdateLearning(state, endTime); } } catch (KeyNotFoundException ex) { //nothing this falls here when is jumping to other agent } }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static GraphNode <T> OppositeNode <T>(this GraphLink <T> link, GraphNode <T> node) { if (node == link.StartNode) { return(link.EndNode); } else if (node == link.EndNode) { return(link.StartNode); } else { return(null); } }
public SixthGameState(float xPos, float yPos, float xSpeed, Platform agentPlatform) { _xPos = xPos; _yPos = yPos; _xSpeed = xSpeed; if (agentPlatform != null) { _agentPlatform = agentPlatform.Clone(); } else { _agentPlatform = null; } _closestLink = null; }
// Add the facets ignoring any null or "". // // Pre : edge != null private static void AddFacetsToLink <TargetType>(GraphLink <TargetType> edge, IDictionary <string, string> facets) where TargetType : IEdgeTarget { Debug.Assert(edge != null); if (facets != null) { foreach (var kv in facets) { if (!string.IsNullOrEmpty(kv.Key) && !string.IsNullOrEmpty(kv.Value)) { edge.Facets.Add(kv.Key, kv.Value); } } } }
public GraphNode addNode(String Node, String Type) { string[] Groups = Node.Split('.'); GraphNode dbGroup = null; if (Groups.Length == 3) { dbGroup = graph.Nodes.GetOrCreate(Groups[0].ToUpper()); dbGroup.Label = Groups[0]; dbGroup.IsGroup = true; } GraphNode schemaGroup = null; if (Groups.Length >= 2) { schemaGroup = graph.Nodes.GetOrCreate(Groups[0].ToUpper() + "." + Groups[1].ToUpper()); schemaGroup.Label = Groups[0] + "." + Groups[1]; schemaGroup.IsGroup = true; if (dbGroup != null) { GraphLink gl = graph.Links.GetOrCreate(dbGroup, schemaGroup, "", GraphCommonSchema.Contains); } } GraphPropertyCollection properties = graph.DocumentSchema.Properties; GraphProperty background = properties.AddNewProperty("Background", typeof(Brush)); GraphProperty objecttype = properties.AddNewProperty("ObjectType", typeof(String)); GraphNode nodeSource = graph.Nodes.GetOrCreate(Node.ToUpper()); nodeSource.Label = Node; if (Type != "") { nodeSource[background] = getBrushForType(Type); nodeSource[objecttype] = Type; } if (schemaGroup != null) { GraphLink gl2 = graph.Links.GetOrCreate(schemaGroup, nodeSource, "", GraphCommonSchema.Contains); } return(nodeSource); }
public List <GraphLink> ParseLinks(string response, string userid) { var links = new List <GraphLink>(); MatchCollection matches = Util.FindRegexs(response, @"user\?id=\w*"); var list = matches.Cast <Match>().Select(match => match.Value.Replace("user?id=", "")).ToList(); foreach (var d in list) { var link = new GraphLink() { source = d, target = userid, Value = 1 }; links.Add(link); } return(links); }
public void WriteToFile(FxArchive OwningArchive, BinaryWriter writer) { writer.Write((uint)NodeType); Name.WriteToFile(OwningArchive, writer); writer.Write(NodeMin); writer.Write(OneOverNodeMin); writer.Write(NodeMax); writer.Write(OneOverNodeMax); writer.Write((uint)InputOperation); // Write Links writer.Write(InputLinks.Length); foreach (FxCompiledFaceGraphLink GraphLink in InputLinks) { GraphLink.WriteToFile(OwningArchive, writer); } writer.Write(ArrayUnk1); }
private string InLinkStateId() { string s = ""; GraphLink l = null; if (l == null) { return("In no link"); } int height = (int)(_model.Height - SquareWorldModel.MIN_HEIGHT) / 5; int speed = ((int)xSpeed / 20); s += "/Speed: " + speed; s += "/Height: " + height; if (l.DeltaY != 0) { int jump = (int)l.DeltaY / 25; s += "/Vertical Jump: " + jump; } else { int unitVector; int distance; if (l.DeltaX < 0) { unitVector = -1; distance = (int)(l.ToNode.Platform.Right - _model.AgentXPosition) / 60; } else { unitVector = 1; distance = (int)(l.ToNode.Platform.Left - _model.AgentXPosition) / 60; } s += "/UnitVector = " + unitVector; s += "/Distance = " + distance; } return(s); }
private void PopulateChildrenOfNodes(IGraphContext context) { using (var scope = new GraphTransactionScope()) { foreach (var file in context.InputNodes.Where(IsMdFile)) { Graph graph = file.Owner; var fn = file.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File).LocalPath; foreach (var heading in GetMdHeadings(file)) { GraphNodeId valueId = file.Id + GraphNodeId.GetPartial(MarkdownSchema.MdValueName, heading.Item1); GraphNode node = graph.Nodes.GetOrCreate(valueId, heading.Item1, MarkdownSchema.Heading); node.SetValue(CodeNodeProperties.SourceLocation, heading.Item2); GraphLink link = graph.Links.GetOrCreate(file, node, null, MarkdownSchema.File2HeadingLink); context.OutputNodes.Add(node); } } scope.Complete(); } }
/// <summary> /// Adds the node to the graph asset so it can be serialized to disk /// </summary> /// <param name="graph">The owning graph</param> /// <param name="link">The link to add to the graph</param> public static void AddToAsset(Graph graph, GraphLink link) { AssetDatabase.AddObjectToAsset(link, graph); }
/***************************************************/ public static void AddLink <T>(this Graph <T> graph, GraphLink <T> link) { graph.Links.Add(link); }
/***************************************************/ public static void RemoveLink <T>(this Graph <T> graph, GraphLink <T> link) { graph.Links.Remove(link); }
/// <summary> /// Загружает поля GraphData.Nodes и Links из VmlData /// </summary> private void RenderNodes() { //Определим максимальное и минимальное значение частоты узла int MinNodeFreq = _vmlData.GetMinNodeFreq(); int MaxNodeFreq = _vmlData.GetMaxNodeFreq(); int freqDelta = (MaxNodeFreq == MinNodeFreq) ? 1 : MaxNodeFreq - MinNodeFreq; var nodeItems = _vmlData.GetNodeItems(); var nodes = new GraphNode[nodeItems.Length]; var dictNodeIndexes = new Dictionary <int, int>(); for (int i = 0; i < nodeItems.Length; i++) { var nodeItem = nodeItems[i]; dictNodeIndexes[nodeItem.nID] = i; var nodeName = nodeItem.sName; nodeName = (nodeName.Length <= MAX_NODE_NAME_LENGTH) ? nodeName : (nodeName.Substring(0, MAX_NODE_NAME_LENGTH) + "..."); nodes[i] = new GraphNode() { id = nodeItem.nID, //+, eid = nodeItem.sID, //+ Size = (nodeItem.nFreq - MinNodeFreq) / (float)freqDelta, name = nodeName, //+ onclick = nodeItem.sOnClick, //+ ondblclick = nodeItem.sOnDblClick, //+ selected = nodeItem.bSelected, //+ nType = nodeItem.nType, //+ title = nodeItem.sToolTip, //+ icon = nodeItem.sImageUrl, //+ X = (float)nodeItem.X, //+ Y = (float)nodeItem.Y, //+ text = nodeItem.sText, //+ highlight = nodeItem.nType <= 0 ? null : GetNodeFillColor(nodeItem.nType), //+ marker = nodeItem.bMarked, //+ }; } //Расчитать толщину связей double minLinkWeight = _vmlData.GetMinLinkWeight(); double maxLinkWeight = _vmlData.GetMaxLinkWeight(); double deltaLinkWeight = maxLinkWeight - minLinkWeight; //В цикле нарисовать все связи VmlLinkItem[] linkItems = _vmlData.GetLinkItems(); var g = linkItems.GroupBy(l => l.nNodeFrom ^ l.nNodeTo); var links = new GraphLink[linkItems.Length]; for (int i = 0; i < linkItems.Length; i++) { VmlLinkItem linkItem = linkItems[i]; int src, dst; if (!dictNodeIndexes.TryGetValue(linkItem.nNodeFrom, out src) || !dictNodeIndexes.TryGetValue(linkItem.nNodeTo, out dst)) { throw new Exception("В списке отсутствует объект(NodeFrom) указанный в данных связи: " + linkItem.nNodeFrom); } links[i] = new GraphLink() { eid = linkItem.sID, //+ source = src, //+ target = dst, //+ LinkType = linkItem.LinkType, onclick = linkItem.sOnClick, //+ ondblclick = linkItem.sOnDblClick, //+ title = Server.HtmlEncode(linkItem.sToolTip), //+ type = ArrowTypeCode(linkItem.ArrowType), //+ Color = !string.IsNullOrEmpty(linkItem.LinkColor) ? linkItem.LinkColor : null, //+ Size = (float)((linkItem.fWeight - minLinkWeight) / deltaLinkWeight), //+ Width = linkItem.SizeAbsolute > 0 ? (int?)linkItem.SizeAbsolute : null, //+ }; } var g2 = links.GroupBy(l => l.source ^ l.target); graph.Nodes = nodes; graph.Links = links; }
public SquareGameState(float xPos, float yPos, float xSpeed, Platform agentPlatform, SquareWorldModel model, GraphLink closestLink) : base(xPos, yPos, xSpeed, agentPlatform, closestLink) { _model = model; }