private void SetLength(object data) { if (Builder[0].ReferenceBuilder.FunctionName == FunctionNames.Circle) { BeginUpdate(); var nb = new NodeBuilder(Builder[0].ReferenceBuilder.Node); nb[1].Real = (double)data / 2; nb.ExecuteFunction(); EndVisualUpdate("Updated radius"); } if (Builder[0].ReferenceBuilder.FunctionName != FunctionNames.LineTwoPoints) { return; } BeginUpdate(); TreeUtils.SetLineLength(Builder[0].ReferenceBuilder.Node, (double)data); var document = _viewInfo.Document; var constraint = NodeBuilderUtils.ShapeHasConstraint(Builder[0].ReferenceBuilder.Node, Constraint2DNames.LineLengthFunction, document); if (constraint != -1) { var nb = new NodeBuilder(document.Root[constraint]); nb.Dependency[2].Real = (double)data; nb.ExecuteFunction(); } CallSolverForLineChanges(Builder[0].ReferenceBuilder.Node); EndVisualUpdate("Updated Length"); }
public int Line(int p1, int p2) { Log.Info("Line drawn"); var lineNode = TreeUtils.AddLineToNode(Document, p1, p2); return(lineNode.Node.Index); }
public int Cone(double x, double y, double z, double radius1, double radius2, double height, double angle) { var axis = new gpAx1(new gpPnt(x, y, z), new gpDir()); var node = TreeUtils.AddCone(Document, axis, radius1, radius2, height, GeomUtils.DegreesToRadians(angle)); return(node.Index); }
protected override List <Item> BuildItems(ref Item defaultItem) { if (Prefab == null) { return(new List <Item>()); } var defaultTree = TreeUtils.GetDefaultTree(Prefab, Position); if (defaultTree == null) { return(new List <Item>()); } var trees = TreeUtils.GetAvailableTrees(); var items = new List <Item> { new SimpleItem("#NONE#", null) }; foreach (var tree in trees) { var item = new SimpleItem(tree.name, tree); items.Add(item); if (tree == defaultTree) { defaultItem = item; } } //Debug.Log($"Built {items.Count} tree items with default {defaultTree} in lane {Position}"); return(items); }
public void WriteTree() { FileOperations.EnsureFileFolderExist(_brtFileName); var sw = new StreamWriter(_brtFileName); sw.WriteLine("digraph G \n {graph[ \n rankdir = \"TD\"];"); TreeUtils.BreadthFirstTraversal(_tree.Root, (node => _tree.GetChildren(node)), (node, curLevel) => { var children = _tree.GetChildren(node); if (children != null) { for (int j = 0; j < children.Count; j++) { sw.WriteLine(node.Row + "->" + children[j].Row); } } sw.Write(node.Row + "[color = grey, label =\""); DrawNode(node, sw); sw.WriteLine("\"" + ", shape=\"record\"];"); return(true); }); sw.WriteLine("}"); sw.Flush(); sw.Close(); }
public static void FindLcaTest() { var root = TreeUtils.CreateSampleTreeWithLinkToParents(); Console.WriteLine($"16 and 810 is " + BinaryTreeLca.FindLcaWithParentLinks(root, root.left.left, root.right.right)); Console.WriteLine($"16 and 58 is " + BinaryTreeLca.FindLcaWithParentLinks(root, root.left.left, root.left.right)); }
public void Projects_Are_Sorted_By_Priority_In_Tree() { var fixture = new Fixture(); var treeView = new TreeView(); var treeUtils = new TreeUtils(treeView); var projects = new List <ProjectTreeNode>(); var projectWithLowPriorityAndTitleStartingWithA = new ProjectTreeNode(fixture.Create <string>(), "ABC", fixture.Create <DateTime>().ToString(), ProjectPriority.Low.DisplayName, 0); var projectWithLowPriorityAndTitleStartingWithB = new ProjectTreeNode(fixture.Create <string>(), "BC", fixture.Create <DateTime>().ToString(), ProjectPriority.Low.DisplayName, 0); var projectWithMediumPriority = new ProjectTreeNode(fixture.Create <string>(), fixture.Create <string>(), fixture.Create <DateTime>().ToString(), ProjectPriority.Medium.DisplayName, 0); var projectWithNoPriority = new ProjectTreeNode(fixture.Create <string>(), fixture.Create <string>(), fixture.Create <DateTime>().ToString(), ProjectPriority.None.DisplayName, 0); projects.Add(projectWithLowPriorityAndTitleStartingWithA); projects.Add(projectWithLowPriorityAndTitleStartingWithB); projects.Add(projectWithMediumPriority); projects.Add(projectWithNoPriority); treeUtils.PopulateTreeByProjectPriority(projects); TreeNodeCollection nodes = treeView.Nodes; Assert.That(nodes[0].Text, Is.EqualTo(projectWithMediumPriority.Title)); Assert.That(nodes[1].Text, Is.EqualTo(projectWithLowPriorityAndTitleStartingWithA.Title)); Assert.That(nodes[2].Text, Is.EqualTo(projectWithLowPriorityAndTitleStartingWithB.Title)); Assert.That(nodes[3].Text, Is.EqualTo(projectWithNoPriority.Title)); }
private void ApplyCut() { var cutType = cutBuilder[2].Integer; var cutDepth = cutBuilder[1].Real; Document.Transact(); var sketchNode = AutoGroupLogic.FindSketchNode(_selectedNode.Node); // Apply Cut on it cutBuilder = new NodeBuilder(TreeUtils.Cut(Document, sketchNode, cutDepth, cutType == 0? CutTypes.ToDepth:CutTypes.ThroughAll)); if (cutBuilder == null) { Document.Revert(); } else { cutBuilder.ExecuteFunction(); NodeUtils.SetSketchTransparency(Document, sketchNode, ObjectVisibility.Hidden); // Commit Document.Commit("Apply Cut"); UpdateView(); AddNodeToTree(cutBuilder.Node); ResetWorkingPlane(); } Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); BackToNeutralModifier(); //Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); }
public void ExampleTest1() { Solution s = new(); int low = 7; int high = 15; int expected = 32; /* * TreeNode root = new TreeNode(10, * new TreeNode(5, * new TreeNode(3), * new TreeNode(7)), * new TreeNode(15, * null, * new TreeNode(18))); */ int?[] array = { 10, 5, 15, 3, 7, null, 18 }; TreeNode root = TreeUtils.ConstructBinaryTree(array.ToList()); TreeUtils.PrintBinaryTree(root); // root.Print(); Assert.AreEqual(expected, s.RangeSumBST(root, low, high)); }
public void ExampleTest2() { Solution s = new(); int low = 6; int high = 10; int expected = 23; /* * TreeNode root = new TreeNode(10, * new TreeNode(5, * new TreeNode(3, * new TreeNode(1)), * new TreeNode(7, * new TreeNode(6))), * new TreeNode(15, * new TreeNode(13), * new TreeNode(18))); */ int?[] array = { 10, 5, 15, 3, 7, 13, 18, 1, null, 6 }; TreeNode root = TreeUtils.ConstructBinaryTree(array.ToList()); TreeUtils.PrintBinaryTree(root); Assert.AreEqual(expected, s.RangeSumBST(root, low, high)); }
//Преобразование всех эл-тов дерева private void ForEachbutton_Click(object sender, EventArgs e) { try { if (TreeInt != null) { TreeUtils <int> .ForEach(TreeInt, TreeUtils <int> .Action); } else { TreeUtils <string> .ForEach(TreeString, TreeUtils <string> .Action); } NodesTree.Nodes.Clear(); if (TreeInt != null) { TreeInt.DisplayAllTree(NodesTree); } else { TreeString.DisplayAllTree(NodesTree); } } catch (AttemptOfChangingUnmutableTree) { MessageBox.Show("Нельзя изменять неизменяемое дерево", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnSortByEven(object sender, EventArgs e) { var result = TreeUtils.FindAll(_tree, node => node % 2 == 0, _creator.CreateTree); _tree = result; RefreshView(); }
public void Transform() { var tree = TreeUtils.Transform(TestData.GetTestTree(), d => d?.Name); Assert.Equals(tree.Value, null); // Root var childsLv_1 = tree.Childs.ToList(); // A, B Assert.Equals(childsLv_1.Count, 2); Assert.Equals(childsLv_1[0].Value, "A"); Assert.Equals(childsLv_1[1].Value, "B"); var childsLv_2_A = childsLv_1[0].Childs.ToList(); // AA, AB Assert.Equals(childsLv_2_A.Count, 2); Assert.Equals(childsLv_2_A[0].Value, "AA"); Assert.IsTrueWith(!childsLv_2_A[0].Childs.Any(), childsLv_2_A[0].Childs); Assert.Equals(childsLv_2_A[1].Value, "AB"); Assert.IsTrueWith(!childsLv_2_A[1].Childs.Any(), childsLv_2_A[1].Childs); var childsLv_2_B = childsLv_1[1].Childs.ToList(); // BA, BB Assert.Equals(childsLv_2_B.Count, 2); Assert.Equals(childsLv_2_B[0].Value, "BA"); Assert.IsTrueWith(!childsLv_2_B[0].Childs.Any(), childsLv_2_B[0].Childs); Assert.Equals(childsLv_2_B[1].Value, "BB"); var childsLv_3_BB = childsLv_2_B[1].Childs.ToList(); // BBB Assert.Equals(childsLv_3_BB.Count, 1); Assert.Equals(childsLv_3_BB[0].Value, "BBB"); Assert.IsTrueWith(!childsLv_3_BB[0].Childs.Any(), childsLv_3_BB[0].Childs); }
public IActionResult ArticleClassTree() { var classManager = Application.Ioc.Resolve <GenericClassManager>(); var classTree = classManager.GetTreeWithCache(new ArticleClassController().Type); var tree = TreeUtils.Transform(classTree, c => c == null ? null : new { c.Id, c.Name }); return(new JsonResult(new { tree })); }
public IActionResult ClassFilterInfo() { var classManager = Application.Ioc.Resolve <GenericClassManager>(); var classTree = classManager.GetClassTree(new ProductClass().Type); var tree = TreeUtils.Transform(classTree, c => c == null ? null : new { c.Id, c.Name }); return(new JsonResult(new { tree })); }
private void OnSetLengthValueHandler(object data) { BeginUpdate(); TreeUtils.SetLineLength(Parent, (double)data); CallSolverForLineChanges(Parent); NodeBuilderUtils.UpdateSketchesOnFaces(new NodeBuilder(Parent)); EndVisualUpdate("Updated length"); }
public static void InOrderTest() { var root = TreeUtils.CreateRandomTree(); InOrderTraversal.InOrderTraverselIterative(root); Console.WriteLine(); InOrderTraversal.InOrderTraverselIterative(root); }
public int Torus(double x, double y, double z, double radius1, double radius2) { var axis = new gpAx1(new gpPnt(x, y, z), new gpDir()); var node = TreeUtils.AddTorus(Document, axis, radius1, radius2); return(node.Index); }
public static void ComputeLeavesTest() { var tr = TreeUtils.CreateRandomTree(); var leaves = BinaryTreeComputeLeaves.ComputeLeaves(tr); PrintUtils.PrintList(leaves); }
public int Sphere(double x, double y, double z, double radius) { var point1 = new Point3D(x, y, z); var node = TreeUtils.AddSphere(Document, point1, radius); return(node.Index); }
private IEnumerator ExtractCoroutine() { // Check if there is any work being done on the heap at the moment if (working == false) { working = true; if (size > 1) { // Animation: Change colors items[0].ChangeColor(TreeUtils.RED); items[size - 1].ChangeColor(TreeUtils.BLUE); arrayBox.Items[0].ChangeColor(TreeUtils.RED); arrayBox.Items[size - 1].ChangeColor(TreeUtils.BLUE); yield return(new WaitForSeconds(animationSpeed)); items[0].Value = items[size - 1].Value; arrayBox.Items[0].Value = arrayBox.Items[size - 1].Value; // Animation: Change color items[0].ChangeColor(TreeUtils.BLUE); arrayBox.Items[0].ChangeColor(TreeUtils.BLUE); // Extract first element DestroyImmediate(items[size - 1].gameObject); items[size - 1] = null; DestroyImmediate(arrayBox.Items[size - 1].gameObject); arrayBox.Items[size - 1] = null; DestroyImmediate(connections[connections.Count - 1].gameObject); connections.RemoveAt(connections.Count - 1); size--; yield return(new WaitForSeconds(animationSpeed)); // Animation: Change color items[0].ChangeColor(TreeUtils.TRANSPARENT); arrayBox.Items[0].ChangeColor(TreeUtils.TRANSPARENT); yield return(new WaitForSeconds(animationSpeed)); // Update binary heap tree upon extraction TreeUtils.PlaceNodes(items, size); // Heapify down upon extraction Coroutine a = StartCoroutine(HeapifyDown()); yield return(a); } else if (size == 1) { // Extract first element DestroyImmediate(items[0].gameObject); DestroyImmediate(arrayBox.Items[0].gameObject); items[0] = null; arrayBox.Items[0] = null; size--; yield return(new WaitForSeconds(animationSpeed)); } working = false; } }
public override bool Execute() { var rectangleNode = Dependency[0].Reference; var recctangleNewRangeValue = Dependency[1].Real; TreeUtils.RectangleSetHeight(rectangleNode, recctangleNewRangeValue); return(BuildDimensionInteractive(rectangleNode)); }
public void Chamfer2D(int edge1, int edge2, double size) { var edges = new List <int>() { edge1, edge2 }; TreeUtils.Chamfer2D(Document, GetEntitiesById(edges), size); }
/// <summary> /// 获取指定类型的分类树 /// 不包括已删除的分类 /// </summary> /// <param name="type">分类类型</param> /// <returns></returns> public virtual ITreeNode <Database.GenericClass> GetClassTree(string type) { return(ClassTreeCache.GetOrCreate(type, () => { var classes = GetClasses(type); var classMap = classes.ToDictionary(c => c.Id); return TreeUtils.CreateTree(classes, c => c, c => c.Parent == null ? null : classMap.GetOrDefault(c.Parent.Id)); }, ClassCacheTime)); }
public IActionResult ClassFilterInfo() { var classManager = Application.Ioc.Resolve <GenericClassManager>(); var classTree = classManager.GetTreeWithCache(new ProductClassController().Type); var tree = TreeUtils.Transform(classTree, c => c == null ? null : new { Id = c.Id.ToString(), c.Name }); return(new JsonResult(new { tree })); }
public void ExampleTest3() { int?[] rootArr = { }; var root = TreeUtils.ConstructBinaryTree(rootArr.ToList()); var actual = new Solution().LevelOrder(root); int[][] expected = { }; Assert.AreEqual(expected, actual); }
protected override void Build() { base.Build(); if (Prefab != null) { DefaultRepeatDistance = TreeUtils.GetDefaultRepeatDistance(Prefab, Position); SelectedRepeatDistance = LoadSelectedRepeatDistance() ?? DefaultRepeatDistance; } }
public void CloseShape() { LastCreatedShape = TreeUtils.AddLineToNode(_document, _lastPoint, _firstPoint).Node; var result = AutoGroupLogic.TryAutoGroup(_document, LastCreatedShape); if (result != null) { LastCreatedShape = result; } }
public int Sketch(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3) { var point1 = new Point3D(x1, y1, z1); var point2 = new Point3D(x2, y2, z2); var point3 = new Point3D(x3, y3, z3); var node = TreeUtils.AddSketchNode(Document, point1, point2, point3); return(node.Index); }
/// <summary> /// Sets the width of the rectangle shape. The vertex coordinates are recalculated and saved in the OCAF tree. /// </summary> private void SetWidth(double width) { if (width < Precision.Confusion) { return; } BeginUpdate(); TreeUtils.SetWidth(Parent, width); EndVisualUpdate("Changed Width."); }