public void Branch_AddChildBrushOfOtherBranch_MovesBrushToBranch()
        {
            const int brushUserID   = 10;
            const int treeUserID1   = 11;
            const int treeUserID2   = 12;
            const int branchUserID1 = 13;
            const int branchUserID2 = 14;
            var       brush         = CSGTreeBrush.Create(userID: brushUserID);
            var       branch2       = CSGTreeBranch.Create(branchUserID2);
            var       tree2         = CSGTree.Create(treeUserID2, new CSGTreeNode[] { branch2 });
            var       branch1       = CSGTreeBranch.Create(branchUserID1, new CSGTreeNode[] { brush });
            var       tree1         = CSGTree.Create(treeUserID1, new CSGTreeNode[] { branch1 });

            CSGManager.ClearDirty(brush);
            CSGManager.ClearDirty(branch1);
            CSGManager.ClearDirty(branch2);
            CSGManager.ClearDirty(tree1);
            CSGManager.ClearDirty(tree2);

            var result = branch2.Add(brush);

            Assert.AreEqual(true, result);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch1, branchUserID1);
            TestUtility.ExpectValidBranchWithUserID(ref branch2, branchUserID2);
            TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
            TestUtility.ExpectValidTreeWithUserID(ref tree2, treeUserID2);
            Assert.AreEqual(true, branch1.Dirty);
            Assert.AreEqual(true, tree1.Dirty);
            Assert.AreEqual(true, branch2.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(branch2.NodeID, brush.Parent.NodeID);
            Assert.AreEqual(tree1.NodeID, branch1.Tree.NodeID);
            Assert.AreEqual(0, branch1.Parent.NodeID);
            Assert.AreEqual(0, branch1.Count);
            Assert.AreEqual(tree2.NodeID, branch2.Tree.NodeID);
            Assert.AreEqual(0, branch2.Parent.NodeID);
            Assert.AreEqual(1, branch2.Count);
            Assert.AreEqual(2, CSGManager.TreeCount, "Expected 2 Trees to Exist");
            Assert.AreEqual(1, CSGManager.TreeBrushCount, "Expected 1 TreeBrush to Exist");
            Assert.AreEqual(2, CSGManager.TreeBranchCount, "Expected 2 TreeBranches to Exist");
            Assert.AreEqual(5, CSGManager.TreeNodeCount);
        }
Esempio n. 2
0
        public void Tree_RemoveInvalidNode_ReturnsFalse()
        {
            const int treeUserID = 11;
            var       tree       = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(tree);

            var result = tree.Remove(CSGTreeNode.Invalid);

            LogAssert.Expect(LogType.Error, new Regex("is invalid"));

            Assert.IsFalse(result);
            Assert.IsFalse(tree.Dirty);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 3
0
        public void Branch_AddChildBrushOfOtherBranch_MovesBrushToBranch()
        {
            const int brushUserID   = 10;
            const int treeUserID1   = 11;
            const int treeUserID2   = 12;
            const int branchUserID1 = 13;
            const int branchUserID2 = 14;
            var       brush         = CSGTreeBrush.Create(userID: brushUserID);
            var       branch2       = CSGTreeBranch.Create(branchUserID2);
            var       tree2         = CSGTree.Create(treeUserID2, new CSGTreeNode[] { branch2 });

            Assume.That((CSGTreeNode)branch2.Parent, Is.EqualTo((CSGTreeNode)tree2));
            var branch1 = CSGTreeBranch.Create(branchUserID1, new CSGTreeNode[] { brush });

            Assume.That((CSGTreeNode)brush.Parent, Is.EqualTo((CSGTreeNode)branch1));
            var tree1 = CSGTree.Create(treeUserID1, new CSGTreeNode[] { branch1 });

            Assume.That((CSGTreeNode)branch1.Parent, Is.EqualTo((CSGTreeNode)tree1));
            CompactHierarchyManager.ClearDirty(brush);
            CompactHierarchyManager.ClearDirty(branch1);
            CompactHierarchyManager.ClearDirty(branch2);
            CompactHierarchyManager.ClearDirty(tree1);
            CompactHierarchyManager.ClearDirty(tree2);

            var result = branch2.Add(brush);

            Assert.IsTrue(result);
            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch1, branchUserID1);
            TestUtility.ExpectValidBranchWithUserID(ref branch2, branchUserID2);
            TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
            TestUtility.ExpectValidTreeWithUserID(ref tree2, treeUserID2);
            Assert.IsTrue(branch1.Dirty);
            Assert.IsTrue(tree1.Dirty);
            Assert.IsTrue(branch2.Dirty);
            Assert.IsTrue(tree2.Dirty);
            Assert.IsTrue(brush.Dirty);
            Assert.IsTrue(TestUtility.IsInTree(tree2, brush));
            Assert.IsFalse(TestUtility.IsInTree(tree1, brush));
            Assert.AreEqual(0, branch1.Count);
            Assert.AreEqual(1, branch2.Count);
            Assert.AreEqual((CSGTreeNode)tree2, (CSGTreeNode)brush.Tree);
            Assert.AreEqual((CSGTreeNode)branch2, (CSGTreeNode)brush.Parent);
            Assert.AreEqual((CSGTreeNode)tree1, (CSGTreeNode)branch1.Tree);
            Assert.AreEqual((CSGTreeNode)tree1, (CSGTreeNode)branch1.Parent);
            Assert.AreEqual((CSGTreeNode)tree2, (CSGTreeNode)branch2.Tree);
            Assert.AreEqual((CSGTreeNode)tree2, (CSGTreeNode)branch2.Parent);
        }
Esempio n. 4
0
        public void Tree_AddSelf_ReturnsFalse()
        {
            const int treeUserID = 10;
            var       tree       = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(tree);

            var result = tree.Add(tree);

            LogAssert.Expect(LogType.Error, "Cannot add self as child");

            Assert.IsFalse(result);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsFalse(tree.Dirty);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 5
0
    public void DestroyTree_Twice_ReturnsFalse()
    {
        const int treeUserID = 10;
        CSGTree   tree       = CSGTree.Create(treeUserID);

        CSGManager.ClearDirty(tree);

        var result1 = tree.Destroy();
        var result2 = tree.Destroy();

        Assert.AreEqual(true, result1);
        Assert.AreEqual(false, result2);
        TestUtility.ExpectInvalidTree(ref tree);
        Assert.AreEqual(0, CSGManager.TreeCount);
        Assert.AreEqual(0, CSGManager.TreeNodeCount);
    }
Esempio n. 6
0
        public void TreeWithNoChildren_RemoveRange_ReturnsFalse()
        {
            const int treeUserID = 13;
            var       tree       = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(tree);

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

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

            Assert.IsFalse(result);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsFalse(tree.Dirty);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 7
0
        public void TreeWithNoChildren_InsertRangeWithInvalidNode_TreeStaysEmpty()
        {
            const int treeUserID = 13;
            var       tree       = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(tree);

            var result = tree.InsertRange(0, new[] { CSGTreeNode.Invalid });

            LogAssert.Expect(LogType.Error, new Regex("Cannot add an invalid child"));

            Assert.IsFalse(result);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsFalse(tree.Dirty);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 8
0
        public void DestroyTree_Twice_ReturnsFalse()
        {
            const int treeUserID = 10;
            CSGTree   tree       = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(tree);

            var result1 = tree.Destroy();
            var result2 = tree.Destroy();

            LogAssert.Expect(LogType.Error, new Regex("is invalid"));

            Assert.IsTrue(result1);
            Assert.IsFalse(result2);
            TestUtility.ExpectInvalidTree(ref tree);
        }
        public void TreeWithoutChildren_Clear_TreeIsEmpty()
        {
            const int treeUserID = 11;
            var       tree       = CSGTree.Create(treeUserID);

            CSGManager.ClearDirty(tree);

            tree.Clear();

            Assert.AreEqual(false, tree.Dirty);
            Assert.AreEqual(0, tree.Count);
            Assert.AreEqual(0, CSGManager.TreeBrushCount, "Expected 0 TreeBrushes to Exist");
            Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist");
            Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist");
            Assert.AreEqual(1, CSGManager.TreeNodeCount, "Expected 1 TreeNode to Exist");
        }
    public void Tree_RemoveInvalidNode_ReturnsFalse()
    {
        const int treeUserID = 11;
        var       tree       = CSGTree.Create(treeUserID);

        CSGManager.ClearDirty(tree);

        var result = tree.Remove(CSGTreeNode.InvalidNode);

        Assert.AreEqual(false, result);
        Assert.AreEqual(false, tree.Dirty);
        Assert.AreEqual(0, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(0, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeNodeCount);
    }
Esempio n. 11
0
        public void CreateTreeWithInvalidChildren()
        {
            const int treeUserID1 = 10;
            const int treeUserID2 = 11;
            CSGTree   tree1       = CSGTree.Create(treeUserID1);

            CompactHierarchyManager.ClearDirty(tree1);


            CSGTree tree2 = CSGTree.Create(treeUserID2, new CSGTreeNode[] { CSGTreeNode.Invalid, tree1 });


            TestUtility.ExpectInvalidTree(ref tree2);
            TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
            Assert.IsFalse(tree1.Dirty);
            Assert.AreEqual(0, tree1.Count);
        }
Esempio n. 12
0
    public CSGTree CreateTree()
    {
        // Every node can have its own unique ID, this can be used to identify nodes
        const int treeUserID      = 1;
        const int branchUserID    = 2;
        const int brushAUserID    = 3;
        const int brushBUserID    = 4;
        const int brushMeshUserID = 5;

        // Create a cube BrushMesh that we can use for our brushes
        BrushMeshInstance cube = CreateCube(userID: brushMeshUserID);

        // Create a matrix for each brush, each with a different position
        Matrix4x4 brushPositionA = Matrix4x4.TRS(new Vector3(-0.5f, 0, 0), Quaternion.identity, Vector3.one);
        Matrix4x4 brushPositionB = Matrix4x4.TRS(new Vector3(0.5f, 0, 0), Quaternion.identity, Vector3.one);

        // Create two brushes
        CSGTreeBrush brushA, brushB;

        brushA = CSGTreeBrush.Create(userID:                            brushAUserID,
                                     localTransformation:   brushPositionA,
                                     brushMesh:                             cube,
                                     operation:                             CSGOperationType.Additive,
                                     flags:                                 CSGTreeBrushFlags.Default);

        brushB = CSGTreeBrush.Create(userID:                            brushBUserID,
                                     localTransformation:   brushPositionB,
                                     brushMesh:                             cube,
                                     operation:                             CSGOperationType.Subtractive,
                                     flags:                                 CSGTreeBrushFlags.Default);

        // Create a branch that contains both brushes
        CSGTreeBranch branch;

        branch = CSGTreeBranch.Create(userID:                   branchUserID,
                                      operation:            CSGOperationType.Additive,
                                      // children of this branch:
                                      children:                     new CSGTreeNode[] { brushA, brushB });

        // Create a tree that contains the branch
        CSGTree tree;

        tree = CSGTree.Create(userID:           treeUserID,
                              children:             new CSGTreeNode[] { branch });
        return(tree);
    }
Esempio n. 13
0
        public void Tree_SetChildrenWithSelf_DoesNotContainsSelf()
        {
            const int treeUserID = 11;
            var       tree       = CSGTree.Create(treeUserID);

            CSGManager.ClearDirty(tree);

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

            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(false, tree.Dirty);
            Assert.AreEqual(0, tree.Count);
            Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist");
            Assert.AreEqual(0, CSGManager.TreeBrushCount, "Expected 0 TreeBrushes to Exist");
            Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist");
            Assert.AreEqual(1, CSGManager.TreeNodeCount, "Expected 1 TreeNode to Exist");
        }
Esempio n. 14
0
        public void CreateBranchWithInvalidChildren()
        {
            const int treeUserID   = 10;
            const int branchUserID = 11;
            CSGTree   tree         = CSGTree.Create(treeUserID);

            CompactHierarchyManager.ClearDirty(tree);


            CSGTreeBranch branch = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { CSGTreeNode.Invalid, tree });


            TestUtility.ExpectInvalidBranch(ref branch);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.IsFalse(tree.Dirty);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 15
0
        public void Tree_AddBrushes_HaveInOrderIndices()
        {
            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);
            var       result1      = tree.Add(brush1);
            var       result2      = tree.Add(brush2);
            var       result3      = tree.Add(brush3);

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

            var index1 = tree.IndexOf(brush1);
            var index2 = tree.IndexOf(brush2);
            var index3 = tree.IndexOf(brush3);

            Assert.AreEqual(0, index1); //2
            Assert.AreEqual(1, index2); //3
            Assert.AreEqual(2, index3); //0
            Assert.AreEqual(true, result1);
            Assert.AreEqual(true, result2);
            Assert.AreEqual(true, result3);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(false, tree.Dirty);
            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, "Expected 0 TreeBranches to Exist");
            Assert.AreEqual(3, CSGManager.TreeBrushCount, "Expected 3 TreeBrushes to Exist");
            Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist");
            Assert.AreEqual(4, CSGManager.TreeNodeCount, "Expected 4 TreeNodes to Exist");
        }
Esempio n. 16
0
        public void Branch_InsertBrushAtEnd_HasBrushInBack()
        {
            const int brushUserID1 = 10;
            const int brushUserID2 = 11;
            const int brushUserID3 = 12;
            const int branchUserID = 13;
            const int treeUserID   = 14;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1, dummyBrushMeshInstance);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2, dummyBrushMeshInstance);
            var       brush3       = CSGTreeBrush.Create(userID: brushUserID3, dummyBrushMeshInstance);
            var       branch       = CSGTreeBranch.Create(branchUserID, new CSGTreeNode[] { brush1, brush2 });
            var       tree         = CSGTree.Create(treeUserID, new CSGTreeNode[] { branch });

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

            var result = branch.Insert(2, brush3);

            Assert.IsTrue(result);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            Assert.IsTrue(tree.Dirty);
            Assert.IsTrue(branch.Dirty);
            Assert.IsFalse(brush1.Dirty);
            Assert.IsFalse(brush2.Dirty);
            Assert.IsTrue(brush3.Dirty);
            Assert.IsTrue(TestUtility.IsInTree(tree, brush1));
            Assert.IsTrue(TestUtility.IsInTree(tree, brush2));
            Assert.IsTrue(TestUtility.IsInTree(tree, brush3));
            Assert.AreEqual(3, TestUtility.CountOfBrushesInTree(tree));
            Assert.AreEqual(3, branch.Count);
            Assert.AreEqual((CSGTreeNode)branch, (CSGTreeNode)brush1.Parent);
            Assert.AreEqual((CSGTreeNode)branch, (CSGTreeNode)brush2.Parent);
            Assert.AreEqual((CSGTreeNode)branch, (CSGTreeNode)brush3.Parent);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush1.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush2.Tree);
            Assert.AreEqual((CSGTreeNode)tree, (CSGTreeNode)brush3.Tree);
            Assert.AreEqual((CSGTreeNode)brush1, (CSGTreeNode)branch[0]);
            Assert.AreEqual((CSGTreeNode)brush2, (CSGTreeNode)branch[1]);
            Assert.AreEqual((CSGTreeNode)brush3, (CSGTreeNode)branch[2]);
        }
Esempio n. 17
0
        public void CreateTree_Multiple()
        {
            const int treeUserID0 = 10;
            const int treeUserID1 = 11;
            const int treeUserID2 = 12;

            var tree0 = CSGTree.Create(treeUserID0);
            var tree1 = CSGTree.Create(treeUserID1);
            var tree2 = CSGTree.Create(treeUserID2);

            TestUtility.ExpectValidTreeWithUserID(ref tree0, treeUserID0);
            TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
            TestUtility.ExpectValidTreeWithUserID(ref tree2, treeUserID2);
            Assert.IsTrue(tree0.Dirty);
            Assert.IsTrue(tree1.Dirty);
            Assert.IsTrue(tree2.Dirty);
        }
Esempio n. 18
0
        public void TreeWithBrush_DestroyBrush_TreeIsEmpty()
        {
            const int brushUserID = 10;
            const int treeUserID  = 11;
            var       brush       = CSGTreeBrush.Create(userID: brushUserID);
            var       tree        = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush });

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

            var result = brush.Destroy();

            Assert.IsTrue(result);
            TestUtility.ExpectInvalidBrush(ref brush);
            Assert.IsTrue(tree.Dirty);
            Assert.IsFalse(brush.Valid);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 19
0
        public void CreateTreeWithDuplicateChildren()
        {
            const int    brushUserID = 10;
            const int    treeUserID  = 12;
            CSGTreeBrush brush       = CSGTreeBrush.Create(userID: brushUserID);

            CompactHierarchyManager.ClearDirty(brush);


            LogAssert.Expect(LogType.Error, new Regex("Have duplicate child"));
            CSGTree tree = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush, brush });


            TestUtility.ExpectInvalidTree(ref tree);
            Assert.IsFalse(brush.Dirty);
            Assert.IsFalse(brush.Parent.Valid);
            Assert.IsFalse(brush.Tree.Valid);
        }
    public void TreeWithNoChildren_RemoveRange_ReturnsFalse()
    {
        const int treeUserID = 13;
        var       tree       = CSGTree.Create(treeUserID);

        CSGManager.ClearDirty(tree);

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

        Assert.AreEqual(false, result);
        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(false, tree.Dirty);
        Assert.AreEqual(0, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(0, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeNodeCount);
    }
    public void TreeWithNoChildren_InsertRangeWithInvalidNode_TreeStaysEmpty()
    {
        const int treeUserID = 13;
        var       tree       = CSGTree.Create(treeUserID);

        CSGManager.ClearDirty(tree);

        var result = tree.InsertRange(0, new[] { CSGTreeNode.InvalidNode });

        Assert.AreEqual(false, result);
        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(false, tree.Dirty);
        Assert.AreEqual(0, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(0, CSGManager.TreeBrushCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeNodeCount);
    }
    public void TreeWithAChild_InsertRangeWithBrushesAtEnd_TreeContainsBrushesInOrder()
    {
        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[] { brush3 });

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

        var result = tree.InsertRange(1, new CSGTreeNode[] { brush1, brush2 });

        Assert.AreEqual(true, result);
        TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
        TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
        TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(true, tree.Dirty);
        Assert.AreEqual(true, brush1.Dirty);
        Assert.AreEqual(true, brush2.Dirty);
        Assert.AreEqual(false, brush3.Dirty);
        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(brush3.NodeID, tree[0].NodeID);
        Assert.AreEqual(brush1.NodeID, tree[1].NodeID);
        Assert.AreEqual(brush2.NodeID, tree[2].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);
    }
Esempio n. 23
0
    public void Tree_AddSelf_ReturnsFalse()
    {
        const int treeUserID = 10;
        var       tree       = CSGTree.Create(treeUserID);

        CSGManager.ClearDirty(tree);

        var result = tree.Add(tree);

        Assert.AreEqual(false, result);
        TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        Assert.AreEqual(0, tree.CountOfBrushesInTree);
        Assert.AreEqual(false, tree.Dirty);
        Assert.AreEqual(0, tree.Count);
        Assert.AreEqual(0, CSGManager.TreeBrushCount);
        Assert.AreEqual(0, CSGManager.TreeBranchCount);
        Assert.AreEqual(1, CSGManager.TreeCount);
        Assert.AreEqual(1, CSGManager.TreeNodeCount);
    }
Esempio n. 24
0
        public void TreeWithChildBrush_Clear_TreeIsEmpty()
        {
            const int brushUserID = 10;
            const int treeUserID  = 11;
            var       brush       = CSGTreeBrush.Create(userID: brushUserID);
            var       tree        = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush });

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

            tree.Clear();

            TestUtility.ExpectValidBrushWithUserID(ref brush, brushUserID);
            Assert.IsTrue(tree.Dirty);
            Assert.IsTrue(brush.Dirty);
            Assert.IsFalse(brush.Parent.Valid);
            Assert.IsFalse(brush.Tree.Valid);
            Assert.AreEqual(0, tree.Count);
        }
Esempio n. 25
0
        public void TreeWithAChild_InsertRangeWithBrushesAtEnd_TreeContainsBrushesInOrder()
        {
            const int brushUserID1 = 10;
            const int brushUserID2 = 11;
            const int brushUserID3 = 12;
            const int treeUserID   = 13;
            var       brush1       = CSGTreeBrush.Create(userID: brushUserID1, dummyBrushMeshInstance);
            var       brush2       = CSGTreeBrush.Create(userID: brushUserID2, dummyBrushMeshInstance);
            var       brush3       = CSGTreeBrush.Create(userID: brushUserID3, dummyBrushMeshInstance);
            var       tree         = CSGTree.Create(treeUserID, new CSGTreeNode[] { brush3 });

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

            var result = tree.InsertRange(1, new CSGTreeNode[] { brush1, brush2 });

            Assert.IsTrue(result);
            Assert.IsTrue(tree.Dirty);
            Assert.IsTrue(brush1.Dirty);
            Assert.IsTrue(brush2.Dirty);
            Assert.IsFalse(brush3.Dirty);

            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);

            Assert.AreEqual((CSGTreeNode)brush3, (CSGTreeNode)tree[0]);
            Assert.AreEqual((CSGTreeNode)brush1, (CSGTreeNode)tree[1]);
            Assert.AreEqual((CSGTreeNode)brush2, (CSGTreeNode)tree[2]);

            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        }
Esempio n. 26
0
        public void Tree_AddBrushes_HaveInOrderIndices()
        {
            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);
            var       result1      = tree.Add(brush1);
            var       result2      = tree.Add(brush2);
            var       result3      = tree.Add(brush3);

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

            var index1 = tree.IndexOf(brush1);
            var index2 = tree.IndexOf(brush2);
            var index3 = tree.IndexOf(brush3);

            Assert.AreEqual(0, index1); //2
            Assert.AreEqual(1, index2); //3
            Assert.AreEqual(2, index3); //0
            Assert.IsTrue(result1);
            Assert.IsTrue(result2);
            Assert.IsTrue(result3);
            Assert.IsFalse(tree.Dirty);
            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);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
        }
Esempio n. 27
0
        public void DestroyTree_Multiple()
        {
            const int treeUserID0 = 10;
            const int treeUserID1 = 11;
            const int treeUserID2 = 12;
            var       tree0       = CSGTree.Create(treeUserID0);
            var       tree1       = CSGTree.Create(treeUserID1);
            var       tree2       = CSGTree.Create(treeUserID2);

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

            var result = DestroyNodes(new CSGTreeNode[] { tree0, tree1, tree2 });

            Assert.IsTrue(result);
            TestUtility.ExpectInvalidTree(ref tree0);
            TestUtility.ExpectInvalidTree(ref tree1);
            TestUtility.ExpectInvalidTree(ref tree2);
        }
Esempio n. 28
0
        public void Branch_SetChildrenWithTree_DoesNotContainTree()
        {
            const int treeUserID   = 10;
            const int branchUserID = 11;
            var       tree         = CSGTree.Create(treeUserID);
            var       branch       = CSGTreeBranch.Create(branchUserID);

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

            branch.InsertRange(0, new CSGTreeNode[] { tree });
            LogAssert.Expect(LogType.Error, new Regex("Cannot add a tree as a child"));

            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            TestUtility.ExpectValidBranchWithUserID(ref branch, branchUserID);
            Assert.IsFalse(branch.Dirty);
            Assert.IsFalse(tree.Dirty);
            Assert.AreEqual(0, tree.Count);
            Assert.AreEqual(0, branch.Count);
        }
Esempio n. 29
0
        public void Tree_SetChildrenWithTree_DoesNotContainTree()
        {
            const int treeUserID1 = 10;
            const int treeUserID2 = 11;
            var       tree1       = CSGTree.Create(treeUserID1);
            var       tree2       = CSGTree.Create(treeUserID2);

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

            tree2.InsertRange(0, new CSGTreeNode[] { tree1 });
            LogAssert.Expect(LogType.Error, new Regex("Cannot add a tree as a child"));

            TestUtility.ExpectValidTreeWithUserID(ref tree1, treeUserID1);
            TestUtility.ExpectValidTreeWithUserID(ref tree2, treeUserID2);
            Assert.IsFalse(tree1.Dirty);
            Assert.IsFalse(tree2.Dirty);
            Assert.AreEqual(0, tree1.Count);
            Assert.AreEqual(0, tree2.Count);
        }
Esempio n. 30
0
        public void TreeWith3Children_RemoveRangeAt0WithCount2_TreeContainsLastBrush()
        {
            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(index: 0, count: 2);

            Assert.AreEqual(true, result);
            TestUtility.ExpectValidBrushWithUserID(ref brush1, brushUserID1);
            TestUtility.ExpectValidBrushWithUserID(ref brush2, brushUserID2);
            TestUtility.ExpectValidBrushWithUserID(ref brush3, brushUserID3);
            TestUtility.ExpectValidTreeWithUserID(ref tree, treeUserID);
            Assert.AreEqual(true, brush1.Dirty);
            Assert.AreEqual(true, brush2.Dirty);
            Assert.AreEqual(false, brush3.Dirty);
            Assert.AreEqual(true, tree.Dirty);

            Assert.AreEqual(0, brush1.Parent.NodeID);
            Assert.AreEqual(0, brush1.Tree.NodeID);
            Assert.AreEqual(0, brush2.Parent.NodeID);
            Assert.AreEqual(0, brush2.Tree.NodeID);
            Assert.AreEqual(0, brush3.Parent.NodeID);
            Assert.AreEqual(tree.NodeID, brush3.Tree.NodeID);
            Assert.AreEqual(brush3.NodeID, tree[0].NodeID);
            Assert.AreEqual(1, tree.Count);
            Assert.AreEqual(0, CSGManager.TreeBranchCount, "Expected 0 TreeBranches to Exist");
            Assert.AreEqual(3, CSGManager.TreeBrushCount, "Expected 3 TreeBrushes to Exist");
            Assert.AreEqual(1, CSGManager.TreeCount, "Expected 1 Tree to Exist");
            Assert.AreEqual(4, CSGManager.TreeNodeCount, "Expected 4 TreeNodes to Exist");
        }