private void paintPersonEdges(PersonNode parent) { var b1 = drawBounds(parent); // Spouse connectors in a multi-marriage case. // All spouses have been drawn to the right/below // this node. if (parent.HasSpouses) { if (parent.Vertical) { // Need to determine the left-most node with narrow spouse nodes. int topX = b1.Left + b1.Width / 2; foreach (var node in parent.Spouses) { var b2 = drawBounds(node); topX = Math.Min((b2.Left + b2.Width / 2), topX); } int topY = b1.Bottom; foreach (var node in parent.Spouses) { var b3 = drawBounds(node); int botY = b3.Top; _g.DrawLine(_multEdge, topX, topY, topX, botY); } } else { int leftX = b1.Right; int leftY = b1.Top + b1.Height / 2; foreach (var node in parent.Spouses) { var b3 = drawBounds(node); int rightX = b3.Left; // TODO consider drawing distinct line for each? _g.DrawLine(_multEdge, leftX, leftY, rightX, leftY); } } } if (GetTree().isLeaf(parent)) // No children, nothing further to do { return; } // center-bottom of parent int parentX = b1.Left + b1.Width / 2; int parentY = b1.Bottom; if (parent.Vertical) { DrawChildrenEdgesV(parent); } else { DrawChildrenEdgesH(parent, parentX, parentY); } }
private TreeNode <TreeViewItem> CreatePersonnalNode(PersonNode personnal) { if (personnal == null) { return(null); } Log.Info("CreatePersonnalNode", "p:" + personnal.Name); TreeViewItem item = null; if (Icons != null && Icons.Count > 0) { Sprite icon = Icons[0];//设备图标 todo:以后可以判断是机柜还是设备,机柜则换上机柜图标 item = new TreeViewItem(personnal.Name, icon); } else { item = new TreeViewItem(personnal.Name); } // item.Tag = personnal.Id; item.Tag = personnal; var node = new TreeNode <TreeViewItem>(item); if (!personDic.ContainsKey(personnal.Id)) { personDic.Add(personnal.Id, node); } return(node); }
public bool Remove(PersonNode pers) { PersonNode temp = head; // is it the first node? if (temp.FirstName == pers.FirstName && temp.LastName == pers.LastName) { // check if only single node if (temp.Next == null) { // currently, cannot allow empty list return(false); } else { head = head.Next; return(true); } } while (temp.Next != null) { PersonNode prev = temp; temp = temp.Next; if (temp.FirstName == pers.FirstName && temp.LastName == pers.LastName) { prev.Next = temp.Next; return(true); } } return(false); }
private static int FindShortestDistance(List <PersonNode> Graph, PersonNode Start, PersonNode End) { int connections = 0; var q = new Queue <PersonNode>(); q.Enqueue(Graph.Single(x => x.Name == Start.Name)); while (q.Count > 0) { connections++; var person = q.Dequeue(); var friends = Graph.Where(x => person.Friends.Contains(x.Name) && !x.Visited); foreach (var friend in friends) { if (friend.Name == End.Name) { return(connections); } else { q.Enqueue(friend); } } person.Visited = true; } return(-1); }
public PersonSearchTestCase(List <PersonNode> graph, PersonNode startPer, PersonNode endPer, int expectedResult) { Graph = graph; StartPerson = startPer; EndPerson = endPer; ExpectedResult = expectedResult; }
public void Initialization() { var childBlock = A.Dummy <IBlock>(); var sut = new PersonNode("alpha", childBlock); sut.PersonName.Should().Be("alpha"); sut.ChildBlock.Should().Be(childBlock); }
private PersonShape AddPersonRect(PersonNode person, double scale, double size = 2) { PersonShape ps = new PersonShape(this, person.Id, person.Name, person.Tag.Pos, scale, size); ps.Moved += Ps_Moved; ps.Show(); return(ps); }
private void paintABox(PersonNode tib, Rectangle box) { PaintHighlight(tib, box); using (Brush b = new SolidBrush(tib.BackColor)) _g.FillRectangle(b, box); _g.DrawRectangle(_border, box); using (var font = tib.DrawVert ? _config.MajorFont.GetFont() : _config.MinorFont.GetFont()) _g.DrawString(tib.Text, font, new SolidBrush(TEXT_COLOR), box.X, box.Y); }
public void DisplayAll() { PersonNode temp = head; do { Console.WriteLine(string.Format("{0} {1}", temp.FirstName, temp.LastName)); temp = temp.Next; } while (temp != null); }
private bool isEscape(PersonNode node) { foreach (Point exit in exits) { if (node.getX() == exit.x && node.getY() == exit.y) { return(true); } } return(false); }
private void increaseNeighborScareValue(PersonNode personNode) { List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(personNode.getPosition(), 3); foreach (PersonNode node in personList) { if (neighborPoints.Contains(node.getPosition())) { node.increaseScareValue(); } } }
private void handleAloneScare(PersonNode personNode) { if (personNode.isAlone() || personNode.isNearFire()) { personNode.increaseScareValue(); increaseNeighborScareValue(personNode); } else { personNode.decreaseScareValue(); } }
private int getNeighborNum(PersonNode node) { int sum = 0; PlaceNode[,] nodes = FloorPlanManager.getInstance().getNodes(); List <Point> neighborPoints = GlobalController.getInstance().findNeighborsWithoutBlock(node.getPosition(), 3); foreach (Point point in neighborPoints) { sum += nodes[point.x, point.y].getPersonNum(); } return(sum); }
public static PersonNode ToTModelS(this TEntity item1) { if (item1 == null) { return(null); } var item2 = new PersonNode(); item2.Id = item1.Id; item2.Name = item1.Name; item2.Sex = item1.Sex.ToString(); item2.ParentId = item1.AreaId; return(item2); }
public static void RunAllTests() { var node1 = new PersonNode("Elliot", new List <string> { "Steph" }); var node2 = new PersonNode("Steph", new List <string> { "Ally", "Kate" }); var node3 = new PersonNode("Kate", new List <string> { "Steph" }); var node4 = new PersonNode("Ally", new List <string> { "Pete", "Andy" }); var node5 = new PersonNode("Jamie", new List <string> { "Richard" }); var node6 = new PersonNode("Pete", new List <string> { }); var node7 = new PersonNode("Andy", new List <string> { }); var testsToRun = new List <PersonSearchTestCase>(); testsToRun.Add(new PersonSearchTestCase(new List <PersonNode> { node1, node2, node3, node4, node5 }, node2, node3, 1)); testsToRun.Add(new PersonSearchTestCase(new List <PersonNode> { node1, node2, node3, node4, node5 }, node1, node3, 2)); testsToRun.Add(new PersonSearchTestCase(new List <PersonNode> { node1, node2, node3, node4, node5, node6, node7 }, node1, node7, 4)); testsToRun.Add(new PersonSearchTestCase(new List <PersonNode> { node1, node2, node3, node4, node5, node6, node7 }, node1, node5, -1)); for (var i = 0; i < testsToRun.Count; i++) { var distance = FindShortestDistance(testsToRun[i].Graph, testsToRun[i].StartPerson, testsToRun[i].EndPerson); if (distance != testsToRun[i].ExpectedResult) { System.Console.WriteLine($"Test {i+1} failed, expected distance {testsToRun[i].ExpectedResult} actual distance {distance}"); } else { System.Console.WriteLine($"Test {i+1} passed!"); } } }
public async Task OnLeaveAsyncShouldUpdateState() { var context = A.Dummy <INavigationContext>(); context.State.PersonName = "amaterasu"; context.State.MoodType = MoodType.Happy; var childBlock = A.Dummy <IBlock>(); var sut = new PersonNode("amaterasu", childBlock); await sut.LeaveAsync(context); context.State.PersonName.Should().BeNull(); context.State.MoodType.Should().BeNull(); }
private List <PersonNode> RandomPersonParent(List <PersonNode> lastPList) { List <PersonNode> newList = new List <PersonNode>(); foreach (var person in lastPList) { PersonNode node = new PersonNode() { Id = person.Id, ParentId = UnityEngine.Random.Range(1, 200) }; newList.Add(node); } return(newList); }
public async Task OnEnterAsyncShouldUpdateState() { var context = A.Dummy <INavigationContext>(); context.State.PersonName = null; var childBlock = A.Dummy <IBlock>(); var sut = new PersonNode("amaterasu", childBlock); var ret = await sut.EnterAsync(context); ret.Should().BeNull(); context.State.PersonName.Should().Be("amaterasu"); }
public bool InsertAfter(PersonNode pExisting, PersonNode pNew) { PersonNode temp = head; do { if (temp.FirstName == pExisting.FirstName && temp.LastName == pExisting.LastName) { pNew.Next = temp.Next; temp.Next = pNew; return(true); } temp = temp.Next; } while (temp != null); return(false); }
public void SetNode(PersonNode node) { if (_model != null) { _model.UnSubscribe(this); } _node = node; _model = node.Model; _model.Subscribe(this); Container.SetActive(true); UpdateInfo(); }
/// <summary> /// 人员区域划分,选中节点 /// </summary> /// <param name="personnelT"></param> /// <param name="nodesT"></param> /// <returns></returns> public TreeNode <TreeViewItem> FindNodeById(object personnelT, IObservableList <TreeNode <TreeViewItem> > nodesT) { TreeNode <TreeViewItem> node = null; if (nodesT != null) { foreach (TreeNode <TreeViewItem> nodeT in nodesT) { try { if (nodeT.Item.Tag is PersonNode) { PersonNode tagp = (PersonNode)nodeT.Item.Tag; int tagId = tagp.Id; if (tagId.ToString() == personnelT.ToString()) { node = nodeT; break; } } if (nodeT.Nodes != null) { try { node = FindNodeById(personnelT, nodeT.Nodes); if (node != null) { break; } } catch { int i = 0; } } } catch { int It = 0; return(null); } } } return(node); }
//private void RemovePersonNode(int id,int pId) //{ // TreeNode<TreeViewItem> personnelP = personDic[id]; // bool IsPer = personDic.ContainsKey(pId); // if (!IsPer) return; // TreeNode<TreeViewItem> ParentPerId = AreaDic[pId]; // personDic.Remove(id); // ParentPerId.Nodes.Remove(personnelP); //} private static List <int> GetRemovePersonList(Dictionary <int, TreeNode <TreeViewItem> > perDic, List <PersonNode> perList) { //perList是从数据库获取的当前的人员列表 //perDic是当前树上的节点 //List<PersonNode> romveNode = new List<PersonNode>(); List <int> removeIds = new List <int>(); foreach (var id in perDic.Keys) { PersonNode perNode = perList.Find(i => i.Id == id); if (perNode == null)//树上的人员id在列表中没有,说明该节点应该被删除 { removeIds.Add(id); } } return(removeIds); }
public void Add(PersonNode pers) { if (head == null) { head = pers; } PersonNode temp = head; // find the last node while (temp.Next != null) { temp = temp.Next; } temp.Next = pers; // ensure that this is the last node pers.Next = null; }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new BlockParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); var parsedText = myContext.ParsedText; if (parsedText is null) { return; } if (parsedText.Length == 0) { parsingContext.LogError(reader, "Era esperado o nome do personagem."); return; } if (reader.ReadState == ReadState.EndOfFile) { return; } await elementParser.ParseAsync(reader, parsingContext, myContext, AggregationSettings); if (myContext.Nodes.Count == 0) { return; } if (parsingContext.SceneContext.HasMood) { parsingContext.LogError(reader, "Foi definido humor mas não foi definida uma fala ou pensamento correspondente."); return; } myContext.Nodes.Insert(0, InitializeMoodNode); myContext.Nodes.Add(DismissMoodNode); var block = parsingContext.BlockFactory.Create(myContext.Nodes); var node = new PersonNode(parsedText, block); parentParsingContext.AddNode(node); }
private void PaintHighlight(PersonNode tib, Rectangle box) { if (tib != (PersonNode)lightNode || _config.HighlightStyle == HighlightStyles.None) { return; } Rectangle r = new Rectangle(box.Location, box.Size); Color c = _config.HighlightColor.GetColor(); switch (_config.HighlightStyle) { case HighlightStyles.Line: r.Inflate(1, 1); using (Pen p = new Pen(c, 3.0f)) _g.DrawRectangle(p, r); break; case HighlightStyles.Glow: int glowwide = 8; Color glowcol = c; int l = 255 / (glowwide + 1); for (int j = 0; j <= glowwide; j++) { r.Inflate(1, 1); using (SolidBrush sb = new SolidBrush(Color.FromArgb(Math.Max(0, 255 - (int)(l * j * 1.25)), glowcol))) { using (Pen p = new Pen(sb, 1)) _g.DrawRectangle(p, r); } } break; case HighlightStyles.ThreeD: r.Inflate(5, 5); ControlPaint.DrawBorder(_g, r, c, 5, ButtonBorderStyle.Outset, c, 5, ButtonBorderStyle.Outset, c, 5, ButtonBorderStyle.Outset, c, 5, ButtonBorderStyle.Outset); break; } }
public async Task OnLeaveAsyncShouldRaiseEvent(string personName, string protagonist) { var isProtagonist = personName == protagonist; var context = A.Dummy <INavigationContext>(); context.State.ProtagonistName = protagonist; var invoker = new TestInvoker(context); var childBlock = A.Dummy <IBlock>(); var sut = new PersonNode(personName, childBlock); await sut.LeaveAsync(context); invoker.ShouldContainSingle <IPersonLeaveEvent>( i => i.Should().BeEquivalentTo(new { PersonName = personName, IsProtagonist = isProtagonist }) ); }
public void PrintShowsVisitedWhenCircularReferenceInObjectGraph() { // Arrange MockObjectVisitor visitor = CreateObjectVisitor(); PersonNode node = new PersonNode { Person = new Person { Name = "David", Age = 23.3 } }; node.Next = node; // Act visitor.Print(node); // Assert Assert.Contains("string Name = David", visitor.Members); Assert.Contains(String.Format("double Age = {0}", 23.3), visitor.Members); Assert.Contains("PersonNode Next = Visited", visitor.Members); }
public void FocusOnNode(PersonNode node) { StopCoroutine("RotateTowardsNodeCoroutine"); StartCoroutine("RotateTowardsNodeCoroutine", node); /* Debug.Log(node.transform.eulerAngles); float xangle = (Mathf.Atan2(finalPos.z, finalPos.y) - Mathf.Atan2(initialPos.z, initialPos.y)) * Mathf.Rad2Deg; Debug.Log(node.transform.position); transform.Rotate(new Vector3(90, 0, 0)); //transform.rotation = transform.rotation * Quaternion.AngleAxis(xangle, Vector3.right); Debug.Log(xangle); float yAngle = (Mathf.Atan2(finalPos.x, finalPos.z) - Mathf.Atan2(node.transform.position.x, node.transform.position.z)) * Mathf.Rad2Deg; Debug.Log(yAngle); //transform.Rotate(new Vector3(xangle, yAngle, 0)); //float zAngle = (Mathf.Atan2(finalPos.y, finalPos.x) - Mathf.Atan2(initialPos.y, initialPos.x)) * Mathf.Rad2Deg; //transform.rotation = transform.rotation * Quaternion.AngleAxis(xangle, Vector3.right) * Quaternion.AngleAxis(yAngle, Vector3.up) * Quaternion.AngleAxis(zAngle, Vector3.forward); */ }
/// <summary> /// 选中节点 /// </summary> /// <param name="node"></param> public void NodeSelected(TreeNode <TreeViewItem> node) { //Debug.Log(node.Item.Name + " selected"); Debug.LogError(node.Item.Name + " selected"); if (node.Item == null || node.Item.Tag == null) { return; } if (node.Item.Tag is PersonNode) { ParkInformationManage.Instance.ShowParkInfoUI(false); PersonNode personNodeT = (PersonNode)node.Item.Tag; LocationObject currentLocationFocusObj = LocationManager.Instance.currentLocationFocusObj; if (currentLocationFocusObj == null || currentLocationFocusObj.Tag.PersonId != personNodeT.Id) { Personnel personnelT = PersonnelTreeManage.Instance.GetPerson(personNodeT.Id); //Personnel personNode = personnels.Find((item) => item.TagId == num); Debug.LogError(node.Item.Name + " selected_FocusPersonAndShowInfo"); //LocationManager.Instance.FocusPersonAndShowInfo(tagP.Id); LocationManager.Instance.FocusPersonAndShowInfo((int)personnelT.TagId); } } else { if (LocationManager.Instance.IsFocus) { LocationManager.Instance.RecoverBeforeFocusAlign(() => { SelectAreaNode(node); }); } else { SelectAreaNode(node); } } }
public void PrintShowsVisitedWhenCircularReferenceInObjectGraph() { // Arrange MockObjectVisitor visitor = CreateObjectVisitor(); PersonNode node = new PersonNode { Person = new Person { Name = "David", Age = 23.3 } }; node.Next = node; // Act visitor.Print(node); // Assert Assert.True(visitor.Members.Contains("string Name = David")); Assert.True(visitor.Members.Contains(String.Format("double Age = {0}", 23.3))); Assert.True(visitor.Members.Contains("PersonNode Next = Visited")); }
private IEnumerator RotateTowardsNodeCoroutine(PersonNode node) { _isRotatingTowardsNode = true; rb.angularVelocity = Vector3.zero; //Vector3 finalPos = new Vector3(0f, 0f, -SphereRadius); Quaternion initialRot = transform.localRotation; transform.localRotation = Quaternion.identity; // Temporary hack for the game jam Vector3 nodePos = node.transform.position; Vector3 longDir = nodePos; longDir.y = 0; float xAngle = Mathf.Asin(nodePos.normalized.y) * Mathf.Rad2Deg; // Latitude float yAngle = Vector3.Angle(-Vector3.forward, longDir) * (longDir.x < 0 ? -1 : 1); // Longitude Quaternion finalRot = Quaternion.AngleAxis(-xAngle, Vector3.right) * Quaternion.AngleAxis(yAngle, Vector3.up); float ratio = 0f; while (ratio < 1f && transform.localRotation != finalRot) { ratio += Time.deltaTime / 1.5f; transform.localRotation = Quaternion.Lerp(initialRot, finalRot, Mathf.SmoothStep(0f, 1f, ratio)); yield return null; } _isRotatingTowardsNode = false; }
private void OnNodeClicked(PersonNode node) { if (lvl.tutorialInt == 2) lvl.allowNext = true; rb.angularVelocity = Vector3.zero; if (_selectedNode != null) { _selectedNode.Select(false); } if (!_isRotatingTowardsNode || node != _selectedNode) { if ((lvl.tutorialInt == -1) || (lvl.tutorialInt > 1) || (lvl.tutorialInt > 1)) FocusOnNode(node); } /* if (_timeSinceLastClick < 0.5f && node == _selectedNode) { // We focus on the node if double clicked FocusOnNode(node); } _timeSinceLastClick = 0f;*/ DetailsPanel.SetNode(node); node.Select(true); _selectedNode = node; }
/// <summary> /// PersonNode类型转化oPersonal /// </summary> public PersonNode PersonnelToPersonNode(Personnel personnelT) { PersonNode nodeT = areaDivideTree.FindPersonNode(personnelT.Id); return(nodeT); }
private void paintNode(ITreeData node) { int currDepth = 0; int genLineY = 0; bool drawVert = false; Rectangle box = drawBounds(node); PersonNode foo = node as PersonNode; if (foo != null) { // Don't draw the fake for multi-marriage at root if (foo.Text != " " || foo.Who != null) { paintABox(foo, box); } currDepth = foo.Depth; genLineY = foo.Vertical ? box.Right : box.Bottom; drawVert = foo.Vertical; } else { // Drawing a union node. Said node consists of two Person boxes. // (Spouse connector drawn in PaintEdges). UnionNode bar = node as UnionNode; if (bar != null) { Rectangle box1 = new Rectangle(box.X, box.Y, bar.P1.Wide, bar.P1.High); Rectangle box2; if (bar.Vertical) { box2 = new Rectangle(box.X, box.Y + bar.P1.High + UNION_BAR_WIDE, bar.P2.Wide, bar.P2.High); } else { box2 = new Rectangle(box.X + bar.P1.Wide + UNION_BAR_WIDE, box.Y, bar.P2.Wide, bar.P2.High); } paintABox(bar.P1, box1); paintABox(bar.P2, box2); currDepth = bar.P1.Depth; genLineY = bar.Vertical ? Math.Max(box1.Right, box2.Right) : Math.Max(box1.Bottom, box2.Bottom); drawVert = bar.Vertical; } // debugging //using (var pen = new Pen(Color.Magenta)) // _g.DrawRectangle(pen, box); } if (currDepth == _nextLevel && _config.GenLines) { _nextLevel += 1; genLineY += 8; if (drawVert) { _g.DrawLine(Pens.Blue, new Point(genLineY, 0), new Point(genLineY, Height)); } else { _g.DrawLine(Pens.Blue, new Point(0, genLineY), new Point(Width, genLineY)); } } }
public void addPerson(PersonNode node) { personList.Add(node); UpdateMap(); }