public void TreeWithChildBrush_RemoveBrush_IsEmpty()
    {
        const int brushUserID = 10;
        const int treeUserID  = 11;
        var       brush       = CSGTreeBrush.Create(userID: brushUserID);
        var       tree        = CSGTree.Create(treeUserID, brush);

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(tree);

        var result = tree.Remove(brush);

        Assert.AreEqual(true, result);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(true, tree.Dirty);
        Assert.AreEqual(false, tree.IsInTree(brush));
        Assert.AreEqual(0, tree.CountOfBrushesInTree);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(0, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(2, CSGManager.TreeNodeCount);
    }
Beispiel #2
0
        public void CreateBrush_WithoutUserID()
        {
            CSGTreeBrush brush = CSGTreeBrush.Create();

            TestUtility.ExpectValidBrushWithUserID(ref brush, 0);
            Assert.IsTrue(brush.Dirty);
        }
    public void BranchWithBrush_DestroyBrush_BranchIsEmpty()
    {
        const int brushUserID  = 10;
        const int branchUserID = 11;
        var       brush        = CSGTreeBrush.Create(userID: brushUserID);
        var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush });

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch);

        var result = brush.Destroy();

        Assert.AreEqual(true, result);
        TestUtility.ExpectInvalidBrush(ref brush);
        Assert.AreEqual(true, branch.Dirty);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(0, branch.Parent.NodeID);
        Assert.AreEqual(0, branch.Tree.NodeID);
        Assert.AreEqual(0, branch.Count);
        Assert.AreEqual(0, CSGManager.TreeBrushCount);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBranchCount);
        Assert.AreEqual(1, CSGManager.TreeNodeCount);
    }
    public void Branch_AddBrush_ContainsBrush()
    {
        const int brushUserID  = 10;
        const int branchUserID = 11;
        var       brush        = CSGTreeBrush.Create(userID: brushUserID);
        var       branch       = CSGTreeBranch.Create(userID: branchUserID);

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch);

        var result = branch.Add(brush);

        Assert.AreEqual(true, result);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
        Assert.AreEqual(true, branch.Dirty);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(branch.NodeID, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(1, branch.Count);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeBranchCount);
        Assert.AreEqual(2, CSGManager.TreeNodeCount);
    }
    public void Tree_AddSameBrushTwice_ReturnsFalse()
    {
        const int brushUserID = 10;
        const int treeUserID  = 11;
        var       brush       = CSGTreeBrush.Create(userID: brushUserID);
        var       tree        = CSGTree.Create(treeUserID);

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(tree);

        var result1 = tree.Add(brush);
        var result2 = tree.Add(brush);

        Assert.AreEqual(true, result1);
        Assert.AreEqual(false, result2);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(true, tree.IsInTree(brush));
        Assert.AreEqual(1, tree.CountOfBrushesInTree);
        Assert.AreEqual(true, tree.Dirty);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(tree.NodeID, brush.Tree.NodeID);
        Assert.AreEqual(1, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(2, CSGManager.TreeNodeCount);
    }
Beispiel #6
0
        public void BranchWithTwoChildren_RemoveLastNode_StillHasFirstNode()
        {
            const int branchUserID = 10;
            const int brushUserID1 = 11;
            const int brushUserID2 = 12;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2);
            var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush1, brush2 });

            CSGManager.ClearDirty(brush1);
            CSGManager.ClearDirty(brush2);
            CSGManager.ClearDirty(branch);

            var result = branch.RemoveAt(1);

            Assert.AreEqual(true, result);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            Assert.AreEqual(false, brush1.Dirty);
            Assert.AreEqual(true, brush2.Dirty);
            Assert.AreEqual(true, branch.Dirty);
            Assert.AreEqual(branch.NodeID, brush1.Parent.NodeID);
            Assert.AreEqual(0, brush1.Tree.NodeID);
            Assert.AreEqual(0, brush2.Parent.NodeID);
            Assert.AreEqual(0, brush2.Tree.NodeID);
            Assert.AreEqual(1, branch.Count);
            Assert.AreEqual(brush1.NodeID, branch[0].NodeID);
            Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist");
            Assert.AreEqual(2, CSGManager.TreeBrushCount, "Expected 2 TreeBrushes to Exist");
            Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist");
            Assert.AreEqual(3, CSGManager.TreeNodeCount, "Expected 3 TreeNodes to Exist");
        }
Beispiel #7
0
        public void Tree_SetChildrenWithBranchWithBrushReversed_ContainsBranchThatContainsBrush()
        {
            const int brushUserID  = 10;
            const int branchUserID = 11;
            const int treeUserID   = 12;
            var       brush        = CSGTreeBrush.Create(userID: brushUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID);
            var       tree         = CSGTree.Create(treeUserID);

            CSGManager.ClearDirty(brush);
            CSGManager.ClearDirty(branch);
            CSGManager.ClearDirty(tree);

            tree.InsertRange(0, new CSGTreeNode[] { branch });
            branch.InsertRange(0, new CSGTreeNode[] { brush });

            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(true, brush.Dirty);
            Assert.AreEqual(true, branch.Dirty);
            Assert.AreEqual(true, tree.Dirty);
            Assert.AreEqual(true, tree.IsInTree(brush));
            Assert.AreEqual(1, tree.CountOfBrushesInTree);
            Assert.AreEqual(branch.NodeID, brush.Parent.NodeID);
            Assert.AreEqual(tree.NodeID, brush.Tree.NodeID);
            Assert.AreEqual(0, branch.Parent.NodeID);
            Assert.AreEqual(tree.NodeID, branch.Tree.NodeID);
            Assert.AreEqual(1, branch.Count);
            Assert.AreEqual(1, tree.Count);
            Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist");
            Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist");
            Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist");
            Assert.AreEqual(3, CSGManager.TreeNodeCount, "Expected 3 TreeNodes to Exist");
        }
Beispiel #8
0
        public void TreeWith3Children_RemoveRangeAt1WithTooLargeCount_ReturnsFalse()
        {
            const int brushUserID1 = 10;
            const int brushUserID2 = 11;
            const int brushUserID3 = 12;
            const int treeUserID   = 13;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2);
            var       brush3       = CSGTreeBrush.Create(userID: brushUserID3);
            var       tree         = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush1, brush2, brush3 });

            CompactHierarchyManager.ClearDirty(brush1);
            CompactHierarchyManager.ClearDirty(brush2);
            CompactHierarchyManager.ClearDirty(brush3);
            CompactHierarchyManager.ClearDirty(tree);

            var result = tree.RemoveRange(1, 3);

            LogAssert.Expect(LogType.Error, new Regex("must be below or equal to"));

            Assert.IsFalse(result);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(3, tree.Count);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush1.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush1.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush2.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush2.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush3.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush3.Tree);
        }
Beispiel #9
0
        public void TreeWith3Children_RemoveRangeWithCount0AndInvalidIndex_ReturnsTrue()
        {
            const int brushUserID1 = 10;
            const int brushUserID2 = 11;
            const int brushUserID3 = 12;
            const int treeUserID   = 13;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2);
            var       brush3       = CSGTreeBrush.Create(userID: brushUserID3);
            var       tree         = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush1, brush2, brush3 });

            CompactHierarchyManager.ClearDirty(brush1);
            CompactHierarchyManager.ClearDirty(brush2);
            CompactHierarchyManager.ClearDirty(brush3);
            CompactHierarchyManager.ClearDirty(tree);

            var result = tree.RemoveRange(3, 0);

            Assert.IsTrue(result);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(3, tree.Count);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush1.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush1.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush2.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush2.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush3.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush3.Tree);
        }
Beispiel #10
0
        public void Branch_InsertBrushNegativeIndex_ReturnsFalse()
        {
            const int brushUserID  = 10;
            const int branchUserID = 11;
            var       brush        = CSGTreeBrush.Create(userID: brushUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID);

            CSGManager.ClearDirty(brush);
            CSGManager.ClearDirty(branch);

            var result = branch.Insert(-1, brush);

            Assert.AreEqual(false, result);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            Assert.AreEqual(false, brush.Dirty);
            Assert.AreEqual(false, branch.Dirty);
            Assert.AreEqual(0, brush.Parent.NodeID);
            Assert.AreEqual(0, brush.Tree.NodeID);
            Assert.AreEqual(0, branch.Count);
            Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist");
            Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist");
            Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist");
            Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist");
        }
Beispiel #11
0
        public void TreeWith3Children_RemoveRangeAt0WithCount3_TreeIsEmpty()
        {
            const int brushUserID1 = 10;
            const int brushUserID2 = 11;
            const int brushUserID3 = 12;
            const int treeUserID   = 13;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2);
            var       brush3       = CSGTreeBrush.Create(userID: brushUserID3);
            var       tree         = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush1, brush2, brush3 });

            CompactHierarchyManager.ClearDirty(brush1);
            CompactHierarchyManager.ClearDirty(brush2);
            CompactHierarchyManager.ClearDirty(brush3);
            CompactHierarchyManager.ClearDirty(tree);

            var result = tree.RemoveRange(0, 3);

            Assert.IsTrue(result);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsTrue(brush1.Dirty);
            Assert.IsTrue(brush2.Dirty);
            Assert.IsTrue(brush3.Dirty);
            Assert.IsTrue(tree.Dirty);
            Assert.IsFalse(brush1.Parent.Valid);
            Assert.IsFalse(brush1.Tree.Valid);
            Assert.IsFalse(brush2.Parent.Valid);
            Assert.IsFalse(brush2.Tree.Valid);
            Assert.IsFalse(brush3.Parent.Valid);
            Assert.IsFalse(brush3.Tree.Valid);
            Assert.AreEqual(0, tree.Count);
        }
Beispiel #12
0
 public SurfaceReference(ChiselNode node, int descriptionIndex, CSGTreeBrush brush, int surfaceIndex)
 {
     this.node             = node as ChiselGeneratorComponent;
     this.brush            = brush;
     this.descriptionIndex = descriptionIndex;
     this.surfaceIndex     = surfaceIndex;
 }
    public void Branch_RemoveUnknownBrush_ReturnsFalse()
    {
        const int brushUserID  = 10;
        const int branchUserID = 11;
        var       brush        = CSGTreeBrush.Create(userID: brushUserID);
        var       branch       = CSGTreeBranch.Create(branchUserID);

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch);

        var result = branch.Remove(brush);

        Assert.AreEqual(false, result);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        Assert.AreEqual(false, brush.Dirty);
        Assert.AreEqual(false, branch.Dirty);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(0, branch.Parent.NodeID);
        Assert.AreEqual(0, branch.Tree.NodeID);
        Assert.AreEqual(0, branch.Count);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeBranchCount);
        Assert.AreEqual(2, CSGManager.TreeNodeCount);
    }
    public void BranchWithChildBrush_RemoveSameBrushTwice_ReturnsFalse()
    {
        const int brushUserID  = 10;
        const int branchUserID = 11;
        var       brush        = CSGTreeBrush.Create(userID: brushUserID);
        var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush });

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch);

        var result1 = branch.Remove(brush);
        var result2 = branch.Remove(brush);

        Assert.AreEqual(true, result1);
        Assert.AreEqual(false, result2);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(true, branch.Dirty);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(0, branch.Parent.NodeID);
        Assert.AreEqual(0, branch.Tree.NodeID);
        Assert.AreEqual(0, branch.Count);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeBranchCount);
        Assert.AreEqual(2, CSGManager.TreeNodeCount);
    }
Beispiel #15
0
    public void CreateTreeWithChildren()
    {
        const int     brushUserID  = 10;
        const int     branchUserID = 11;
        const int     treeUserID   = 12;
        CSGTreeBrush  brush        = CSGTreeBrush.Create(userID: brushUserID);
        CSGTreeBranch branch       = CSGTreeBranch.Create(branchUserID);

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch);


        CSGTree tree = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush, branch });


        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(true, branch.Dirty);
        Assert.AreEqual(true, tree.Dirty);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(tree.NodeID, brush.Tree.NodeID);
        Assert.AreEqual(0, branch.Parent.NodeID);
        Assert.AreEqual(tree.NodeID, branch.Tree.NodeID);
        Assert.AreEqual(0, branch.Count);
        Assert.AreEqual(2, tree.Count);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeBranchCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(3, CSGManager.TreeNodeCount);
    }
Beispiel #16
0
    public void BranchWithSingleChild_RemoveLastNode_IsEmptyBranch()
    {
        const int branchUserID = 10;
        const int brushUserID  = 11;
        var       brush        = CSGTreeBrush.Create(userID: brushUserID);
        var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush });

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch);

        var result = branch.RemoveAt(0);

        Assert.AreEqual(true, result);
        TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(true, branch.Dirty);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(0, branch.Count);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeBranchCount);
        Assert.AreEqual(2, CSGManager.TreeNodeCount);
    }
Beispiel #17
0
    public void CreateBranchWithChildren()
    {
        const int     brushUserID   = 10;
        const int     branchUserID1 = 11;
        const int     branchUserID2 = 12;
        CSGTreeBrush  brush         = CSGTreeBrush.Create(userID: brushUserID);
        CSGTreeBranch branch1       = CSGTreeBranch.Create(branchUserID1);

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(branch1);


        CSGTreeBranch branch2 = CSGTreeBranch.Create(branchUserID2, new CSGTreeNode[] { brush, branch1 });


        TestUtility.ExpectValidBranchWithUserID(ref branch2, branchUserID2);
        Assert.AreEqual(true, branch1.Dirty);
        Assert.AreEqual(true, branch2.Dirty);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(branch2.NodeID, brush.Parent.NodeID);
        Assert.AreEqual(0, brush.Tree.NodeID);
        Assert.AreEqual(branch2.NodeID, branch1.Parent.NodeID);
        Assert.AreEqual(0, branch1.Tree.NodeID);
        Assert.AreEqual(0, branch1.Count);
        Assert.AreEqual(0, branch2.Parent.NodeID);
        Assert.AreEqual(0, branch2.Tree.NodeID);
        Assert.AreEqual(2, branch2.Count);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(2, CSGManager.TreeBranchCount);
        Assert.AreEqual(3, CSGManager.TreeNodeCount);
    }
Beispiel #18
0
        public void Tree_AddBranchAddBrushReversed_ContainsBranchThatContainsBrush()
        {
            const int brushUserID  = 10;
            const int branchUserID = 11;
            const int treeUserID   = 12;
            var       brush        = CSGTreeBrush.Create(userID: brushUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID);
            var       tree         = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(brush);
            CompactHierarchyManager.ClearDirty(branch);
            CompactHierarchyManager.ClearDirty(tree);

            var result1 = tree.Add(branch);
            var result2 = branch.Add(brush);

            Assert.IsTrue(result1);
            Assert.IsTrue(result2);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsTrue(branch.Dirty);
            Assert.IsTrue(tree.Dirty);
            Assert.IsTrue(brush.Dirty);
            Assert.IsTrue(TestUtility.IsInTree(tree, brush));
            Assert.AreEqual(1, branch.Count);
            Assert.AreEqual(1, tree.Count);
            Assert.AreEqual((CSGTreeNode)branch, (CSGTreeNode)brush.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)branch.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)branch.Tree);
        }
        public void GenerateAllTreeNodes()
        {
            var instanceID         = GetInstanceID();
            var instances          = brushContainerAsset ? brushContainerAsset.Instances : null;
            var requiredNodeLength = RequiredNodeLength(instances);

            if (requiredNodeLength == 0)
            {
                Nodes    = new CSGTreeNode[1];
                Nodes[0] = CSGTreeBrush.Create(userID: instanceID, localTransformation: TopTransformation, operation: operation);
            }
            else
            if (requiredNodeLength == 1)
            {
                Nodes    = new CSGTreeNode[1];
                Nodes[0] = CSGTreeBrush.Create(userID: instanceID, localTransformation: TopTransformation, operation: operation);
            }
            else
            {
                Nodes = new CSGTreeNode[requiredNodeLength];
                var children = new CSGTreeNode[requiredNodeLength - 1];
                for (int i = 0; i < requiredNodeLength - 1; i++)
                {
                    children[i] = CSGTreeBrush.Create(userID: instanceID);
                }

                Nodes[0] = CSGTreeBranch.Create(instanceID, operation, children);
                for (int i = 1; i < Nodes.Length; i++)
                {
                    Nodes[i] = children[i - 1];
                }
            }
            Nodes[0].Operation           = operation;
            Nodes[0].LocalTransformation = TopTransformation;
        }
Beispiel #20
0
        public void Tree_SetChildrenWithBranchWithBrushReversed_ContainsBranchThatContainsBrush()
        {
            const int brushUserID  = 10;
            const int branchUserID = 11;
            const int treeUserID   = 12;
            var       brush        = CSGTreeBrush.Create(userID: brushUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID);
            var       tree         = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(brush);
            CompactHierarchyManager.ClearDirty(branch);
            CompactHierarchyManager.ClearDirty(tree);

            tree.InsertRange(0, new CSGTreeNode[] { branch });
            branch.InsertRange(0, new CSGTreeNode[] { brush });

            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsTrue(brush.Dirty);
            Assert.IsTrue(branch.Dirty);
            Assert.IsTrue(tree.Dirty);
            Assert.IsTrue(TestUtility.IsInTree(tree, brush));
            Assert.AreEqual(1, TestUtility.CountOfBrushesInTree(tree));
            Assert.AreEqual(1, branch.Count);
            Assert.AreEqual(1, tree.Count);
            Assert.AreEqual((CSGTreeNode)branch, (CSGTreeNode)brush.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)branch.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)branch.Tree);
        }
        public void BranchWithChildBrush_Clear_BranchIsEmpty()
        {
            const int brushUserID  = 10;
            const int branchUserID = 11;
            var       brush        = CSGTreeBrush.Create(userID: brushUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush });

            CSGManager.ClearDirty(brush);
            CSGManager.ClearDirty(branch);

            branch.Clear();

            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            Assert.AreEqual(true, branch.Dirty);
            Assert.AreEqual(true, brush.Dirty);
            Assert.AreEqual(0, brush.Parent.NodeID);
            Assert.AreEqual(0, brush.Tree.NodeID);
            Assert.AreEqual(0, branch.Parent.NodeID);
            Assert.AreEqual(0, branch.Tree.NodeID);
            Assert.AreEqual(0, branch.Count);
            Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist");
            Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist");
            Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist");
            Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist");
        }
Beispiel #22
0
        public void Tree_InsertChildBrushOfOtherTree_MovesBrushToTree()
        {
            const int brushUserID = 10;
            const int treeUserID1 = 11;
            const int treeUserID2 = 12;
            var       brush       = CSGTreeBrush.Create(userID: brushUserID, dummyBrushMeshInstance);
            var       tree2       = CSGTree.Create(treeUserID2);
            var       tree1       = CSGTree.Create(treeUserID1, new CSGTreeNode[] { brush });

            CompactHierarchyManager.ClearDirty(brush);
            CompactHierarchyManager.ClearDirty(tree1);
            CompactHierarchyManager.ClearDirty(tree2);

            var result = tree2.Insert(0, brush);

            Assert.IsTrue(result);
            Assert.IsTrue(brush.Dirty);
            Assert.IsTrue(tree1.Dirty);
            Assert.IsTrue(tree2.Dirty);
            Assert.IsFalse(TestUtility.IsInTree(tree1, brush));
            Assert.IsTrue(TestUtility.IsInTree(tree2, brush));
            Assert.AreEqual(0, TestUtility.CountOfBrushesInTree(tree1));
            Assert.AreEqual(1, TestUtility.CountOfBrushesInTree(tree2));
            Assert.AreEqual(0, tree1.Count);
            Assert.AreEqual(1, tree2.Count);
            Assert.AreEqual((CSGTreeNode)tree2, (CSGTreeNode)brush.Tree);
            Assert.AreEqual((CSGTreeNode)tree2, (CSGTreeNode)brush.Parent);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
            TestUtility.ExpectValidTreeWithUserID(ref tree2, treeUserID2);
        }
    public void Tree_AddChildBrushOfOtherTree_MovesBrushToTree()
    {
        const int brushUserID = 10;
        const int treeUserID1 = 11;
        const int treeUserID2 = 12;
        var       brush       = CSGTreeBrush.Create(userID: brushUserID);
        var       tree2       = CSGTree.Create(treeUserID2);
        var       tree1       = CSGTree.Create(treeUserID1, new CSGTreeNode[] { brush });

        CSGManager.ClearDirty(brush);
        CSGManager.ClearDirty(tree1);
        CSGManager.ClearDirty(tree2);
        var result = tree2.Add(brush);

        Assert.AreEqual(true, result);
        TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
        TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
        TestUtility.ExpectValidTreeWithUserID(ref tree2, treeUserID2);
        Assert.AreEqual(true, tree1.Dirty);
        Assert.AreEqual(true, tree2.Dirty);
        Assert.AreEqual(true, brush.Dirty);
        Assert.AreEqual(false, tree1.IsInTree(brush));
        Assert.AreEqual(true, tree2.IsInTree(brush));
        Assert.AreEqual(0, tree1.CountOfBrushesInTree);
        Assert.AreEqual(1, tree2.CountOfBrushesInTree);
        Assert.AreEqual(tree2.NodeID, brush.Tree.NodeID);
        Assert.AreEqual(0, brush.Parent.NodeID);
        Assert.AreEqual(0, tree1.Count);
        Assert.AreEqual(1, tree2.Count);
        Assert.AreEqual(2, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeBrushCount);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(3, CSGManager.TreeNodeCount);
    }
Beispiel #24
0
        public void BranchWithTwoChildren_RemoveFirstNode_StillHasLastNode()
        {
            const int branchUserID = 10;
            const int brushUserID1 = 11;
            const int brushUserID2 = 12;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2);
            var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush1, brush2 });

            CompactHierarchyManager.ClearDirty(brush1);
            CompactHierarchyManager.ClearDirty(brush2);
            CompactHierarchyManager.ClearDirty(branch);

            var result = branch.RemoveAt(0);

            Assert.IsTrue(result);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            Assert.IsTrue(brush1.Dirty);
            Assert.IsFalse(brush2.Dirty);
            Assert.IsTrue(branch.Dirty);
            Assert.IsFalse(brush1.Parent.Valid);
            Assert.IsFalse(brush1.Tree.Valid);
            Assert.IsFalse(brush2.Tree.Valid);
            Assert.AreEqual(1, branch.Count);
            Assert.AreEqual((CSGTreeNode)brush2, (CSGTreeNode)branch[0]);
            Assert.AreEqual((CSGTreeNode)branch, (CSGTreeNode)brush2.Parent);
        }
Beispiel #25
0
        public void CreateTreeWithChildren()
        {
            const int     brushUserID  = 10;
            const int     branchUserID = 11;
            const int     treeUserID   = 12;
            CSGTreeBrush  brush        = CSGTreeBrush.Create(userID: brushUserID);
            CSGTreeBranch branch       = CSGTreeBranch.Create(branchUserID);

            CompactHierarchyManager.ClearDirty(brush);
            CompactHierarchyManager.ClearDirty(branch);


            CSGTree tree = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush, branch });


            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsTrue(branch.Dirty);
            Assert.IsTrue(tree.Dirty);
            Assert.IsTrue(brush.Dirty);
            Assert.AreEqual(0, branch.Count);
            Assert.AreEqual(2, tree.Count);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)branch.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)branch.Tree);
        }
Beispiel #26
0
        public void Tree_AddBrush_ContainsBrush()
        {
            const int brushUserID = 10;
            const int treeUserID  = 11;
            var       brush       = CSGTreeBrush.Create(userID: brushUserID);
            var       tree        = CSGTree.Create(treeUserID);

            CSGManager.ClearDirty(brush);
            CSGManager.ClearDirty(tree);

            var result = tree.Add(brush);

            Assert.AreEqual(true, result);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(true, tree.Dirty);
            Assert.AreEqual(true, brush.Dirty);
            Assert.AreEqual(true, tree.IsInTree(brush));
            Assert.AreEqual(1, tree.CountOfBrushesInTree);
            Assert.AreEqual(0, brush.Parent.NodeID);
            Assert.AreEqual(tree.NodeID, brush.Tree.NodeID);
            Assert.AreEqual(1, tree.Count);
            Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist");
            Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist");
            Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist");
            Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist");
        }
Beispiel #27
0
        public void CreateBranchWithChildren()
        {
            const int     brushUserID   = 10;
            const int     branchUserID1 = 11;
            const int     branchUserID2 = 12;
            CSGTreeBrush  brush         = CSGTreeBrush.Create(userID: brushUserID);
            CSGTreeBranch branch1       = CSGTreeBranch.Create(branchUserID1);

            CompactHierarchyManager.ClearDirty(brush);
            CompactHierarchyManager.ClearDirty(branch1);


            CSGTreeBranch branch2 = CSGTreeBranch.Create(branchUserID2, new CSGTreeNode[] { brush, branch1 });


            TestUtility.ExpectValidBranchWithUserID(ref branch2, branchUserID2);
            Assert.IsTrue(branch1.Dirty);
            Assert.IsTrue(branch2.Dirty);
            Assert.IsTrue(brush.Dirty);
            Assert.IsFalse(brush.Tree.Valid);
            Assert.IsFalse(branch1.Tree.Valid);
            Assert.IsFalse(branch2.Parent.Valid);
            Assert.IsFalse(branch2.Tree.Valid);
            Assert.AreEqual(0, branch1.Count);
            Assert.AreEqual(2, branch2.Count);
            Assert.AreEqual((CSGTreeNode)branch2, (CSGTreeNode)brush.Parent);
            Assert.AreEqual((CSGTreeNode)branch2, (CSGTreeNode)branch1.Parent);
        }
Beispiel #28
0
        public void Branch_AddSameBrushTwice_ReturnsFalse()
        {
            const int brushUserID  = 10;
            const int branchUserID = 11;
            var       brush        = CSGTreeBrush.Create(userID: brushUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID);

            CSGManager.ClearDirty(brush);
            CSGManager.ClearDirty(branch);

            var result1 = branch.Add(brush);
            var result2 = branch.Add(brush);

            Assert.AreEqual(true, result1);
            Assert.AreEqual(false, result2);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            Assert.AreEqual(true, branch.Dirty);
            Assert.AreEqual(true, brush.Dirty);
            Assert.AreEqual(0, brush.Tree.NodeID);
            Assert.AreEqual(branch.NodeID, brush.Parent.NodeID);
            Assert.AreEqual(0, brush.Tree.NodeID);
            Assert.AreEqual(1, branch.Count);
            Assert.AreEqual(0, CSGManager.TreeCount, "Expected 0 Trees to Exist");
            Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist");
            Assert.AreEqual(1, CSGManager.TreeBranchCount, "Expected 1 TreeBranch to Exist");
            Assert.AreEqual(2, CSGManager.TreeNodeCount, "Expected 2 TreeNodes to Exist");
        }
Beispiel #29
0
        public static void SelectBrushVariant(CSGTreeBrush brush, bool uniqueSelection = false)
        {
            Undo.RecordObject(ChiselSyncSelection.Instance, "Selected brush variant");
            var node = ChiselNodeHierarchyManager.FindChiselNodeByTreeNode(brush);

            if (node)
            {
                node.hierarchyItem.SetBoundsDirty();
            }
            var selectedBrushesLookup = Instance.selectedBrushesLookup;
            var modified = false;/*
                                  * if (uniqueSelection)
                                  * {
                                  * foreach (var variant in brush.AllSynchronizedVariants)
                                  * {
                                  * if (variant != brush)
                                  * modified = selectedBrushesLookup.Remove(variant) || modified;
                                  * }
                                  * }*/

            modified = selectedBrushesLookup.Add(brush);
            if (modified)
            {
                ChiselOutlineRenderer.Instance.OnSelectionChanged();
            }
        }
    public void TreeWith3Children_RemoveRangeWithCount0AndInvalidIndex_ReturnsFalse()
    {
        const int brushUserID1 = 10;
        const int brushUserID2 = 11;
        const int brushUserID3 = 12;
        const int treeUserID   = 13;
        var       brush1       = CSGTreeBrush.Create(userID: brushUserID1);
        var       brush2       = CSGTreeBrush.Create(userID: brushUserID2);
        var       brush3       = CSGTreeBrush.Create(userID: brushUserID3);
        var       tree         = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush1, brush2, brush3 });

        CSGManager.ClearDirty(brush1);
        CSGManager.ClearDirty(brush2);
        CSGManager.ClearDirty(brush3);
        CSGManager.ClearDirty(tree);

        var result = tree.RemoveRange(3, 0);

        Assert.AreEqual(false, result);
        TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
        TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
        TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(0, brush1.Parent.NodeID);
        Assert.AreEqual(tree.NodeID, brush1.Tree.NodeID);
        Assert.AreEqual(0, brush2.Parent.NodeID);
        Assert.AreEqual(tree.NodeID, brush2.Tree.NodeID);
        Assert.AreEqual(0, brush3.Parent.NodeID);
        Assert.AreEqual(tree.NodeID, brush3.Tree.NodeID);
        Assert.AreEqual(3, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(3, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(4, CSGManager.TreeNodeCount);
    }