Esempio n. 1
0
        public void CutHoleWhenParentHaveScale()
        {
            Init();
            // create cube inside of empty with scale, but cube is still 5*5*5 to world
            var empty1Json = new NodeJson("empty1Json", new Vector3(0, 0, 0), new Vector3(5, 2, 1), "", NodeType.EMPTY);

            NodeDataManager.AddNode(empty1Json);
            var empty2Json = new NodeJson("empty2Json", new Vector3(0, 0, 0), new Vector3(1, 2, 2), "", NodeType.EMPTY)
            {
                parentName = "empty1Json"
            };

            NodeDataManager.AddNode(empty2Json);
            var cubeJson = new NodeJson("cubeJson", new Vector3(0, 0, 0), new Vector3(1, 1.2f, 2.4f), "", NodeType.CUBE)
            {
                parentName = "empty2Json"
            };

            NodeDataManager.AddNode(cubeJson);
            NodeFactory.CreateNodes(NodeDataManager.NodeJsons);

            var cutterPos = new Vector3(3, 0.5f, -1);
            var cutterSca = new Vector3(2, 2, 2);

            this.cutter.transform.position   = cutterPos;
            this.cutter.transform.localScale = cutterSca;
            Debug.Log(string.Format("testing cutter with pos:{0} sca:{1}", cutterPos, cutterSca));

            NodeDataManager.onAddNode += this.onAddNode;
            NodeHoleCutter.CutHoles(this.cutter);

            var holeCount = 1;

            Assert.AreEqual(holeCount, this.nodesCreated.Count, string.Format("There are not {0} holes", holeCount));
            foreach (var hole in this.nodesCreated)
            {
                Assert.AreEqual(NodeType.HOLE, hole.nodeType);

                Assert.AreApproximatelyEqual(0.2f, hole.position.x, "hole has wrong X pos");
                Assert.AreApproximatelyEqual(0.125f, hole.position.y, "hole has wrong Y pos");
                Assert.AreApproximatelyEqual(0.4f, hole.scale.x, "hole has wrong X sca");
                Assert.AreApproximatelyEqual(0.5f, hole.scale.y, "hole has wrong Y sca");
            }

            NodeDataManager.onAddNode -= this.onAddNode;
            CleanUp();
        }
Esempio n. 2
0
        private void runCutHoleTest(Vector3 cutterPos, Vector3 cutterSca, TestHoleJson testHoleJson, int expecteHoleCount = 2)
        {
            this.cutter.transform.position   = cutterPos;
            this.cutter.transform.localScale = cutterSca;
            Debug.Log(string.Format("testing cutter with pos:{0} sca:{1}", cutterPos, cutterSca));

            NodeDataManager.onAddNode += this.onAddNode;
            NodeHoleCutter.CutHoles(this.cutter);

            Assert.AreEqual(expecteHoleCount, this.nodesCreated.Count, string.Format("There are not {0} holes", expecteHoleCount));
            foreach (var hole in this.nodesCreated)
            {
                Assert.AreEqual(NodeType.HOLE, hole.nodeType);

                testHoleJson(hole);
            }

            NodeDataManager.onAddNode -= this.onAddNode;
        }
Esempio n. 3
0
        public void CutHolesWhenCubeIsBiggerThanQuad()
        {
            Init();
            createCube(0, 0, 0);
            var cutterPos = new Vector3(3, 0, 0);
            var cutterSca = new Vector3(6, 6, 6);

            this.cutter.transform.position   = cutterPos;
            this.cutter.transform.localScale = cutterSca;
            Debug.Log(string.Format("testing cutter with pos:{0} sca:{1}", cutterPos, cutterSca));

            NodeDataManager.onAddNode += this.onAddNode;
            NodeHoleCutter.CutHoles(this.cutter);

            var expectedHoleCount = 5;

            Assert.AreEqual(expectedHoleCount, this.nodesCreated.Count, string.Format("There are not {0} holes", expectedHoleCount));

            foreach (var hole in this.nodesCreated)
            {
                Assert.AreEqual(NodeType.HOLE, hole.nodeType);
                // json's hole centre will still be outside of quad, but when hole is created it is scaled to fit inside

                if (hole.behaviour.name.Contains("right"))
                {
                    var expect = 0;
                    Assert.AreEqual(expect, hole.behaviour.Children.Length, string.Format("There are not {0} children", expect));
                }
                else
                {
                    var expect = 1;
                    Assert.AreEqual(expect, hole.behaviour.Children.Length, string.Format("There are not {0} children", expect));
                }
            }

            NodeDataManager.onAddNode -= this.onAddNode;
            CleanUp();
        }
Esempio n. 4
0
        public void CutsHoleWhenInOtherSides()
        {
            Init();
            createCube(0, 0, 0);
            NodeDataManager.onAddNode += this.onAddNode;

            var cutterPos = new Vector3(3, 0, 0);
            var cutterSca = new Vector3(2, 2, 2);

            this.cutter.transform.localScale = cutterSca;
            Debug.Log(string.Format("testing cutter with pos:{0} sca:{1}", cutterPos, cutterSca));

            this.cutter.transform.position = new Vector3(3, 0.8f, 1.2f);
            NodeHoleCutter.CutHoles(this.cutter);
            this.cutter.transform.position = new Vector3(-3, 0.8f, 1.2f);
            NodeHoleCutter.CutHoles(this.cutter);
            this.cutter.transform.position = new Vector3(0.8f, 3, 1.2f);
            NodeHoleCutter.CutHoles(this.cutter);
            this.cutter.transform.position = new Vector3(0.8f, -3, 1.2f);
            NodeHoleCutter.CutHoles(this.cutter);
            this.cutter.transform.position = new Vector3(0.8f, 1.2f, 3);
            NodeHoleCutter.CutHoles(this.cutter);
            this.cutter.transform.position = new Vector3(0.8f, 1.2f, -3);
            NodeHoleCutter.CutHoles(this.cutter);

            Assert.AreEqual(6, this.nodesCreated.Count, "There are not 6 holes");
            foreach (var hole in this.nodesCreated)
            {
                Assert.AreEqual(NodeType.HOLE, hole.nodeType);

                if (hole.behaviour.name.Contains("right"))
                {
                    Assert.AreApproximatelyEqual(-1.2f, hole.position.x, "right hole has wrong X pos");
                    Assert.AreApproximatelyEqual(0.8f, hole.position.y, "right hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(2f, hole.scale.x, "right hole has wrong X sca");
                    Assert.AreApproximatelyEqual(2f, hole.scale.y, "right hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("left"))
                {
                    Assert.AreApproximatelyEqual(1.2f, hole.position.x, "left hole has wrong X pos");
                    Assert.AreApproximatelyEqual(0.8f, hole.position.y, "left hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(2f, hole.scale.x, "left hole has wrong X sca");
                    Assert.AreApproximatelyEqual(2f, hole.scale.y, "left hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("front"))
                {
                    Assert.AreApproximatelyEqual(0.8f, hole.position.x, "front hole has wrong X pos");
                    Assert.AreApproximatelyEqual(1.2f, hole.position.y, "front hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(2f, hole.scale.x, "front hole has wrong X sca");
                    Assert.AreApproximatelyEqual(2f, hole.scale.y, "front hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("back"))
                {
                    Assert.AreApproximatelyEqual(-0.8f, hole.position.x, "back hole has wrong X pos");
                    Assert.AreApproximatelyEqual(1.2f, hole.position.y, "back hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(2f, hole.scale.x, "back hole has wrong X sca");
                    Assert.AreApproximatelyEqual(2f, hole.scale.y, "back hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("top"))
                {
                    Assert.AreApproximatelyEqual(0.8f, hole.position.x, "top hole has wrong X pos");
                    Assert.AreApproximatelyEqual(-1.2f, hole.position.y, "top hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(2f, hole.scale.x, "top hole has wrong X sca");
                    Assert.AreApproximatelyEqual(2f, hole.scale.y, "top hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("floor"))
                {
                    Assert.AreApproximatelyEqual(0.8f, hole.position.x, "floor hole has wrong X pos");
                    Assert.AreApproximatelyEqual(1.2f, hole.position.y, "floor hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(2f, hole.scale.x, "floor hole has wrong X sca");
                    Assert.AreApproximatelyEqual(2f, hole.scale.y, "floor hole has wrong Y sca");
                }
            }

            NodeDataManager.onAddNode -= this.onAddNode;
            CleanUp();
        }
Esempio n. 5
0
        public void CutHolesWhenCubeCornerOutSideOfQuad()
        {
            Init();
            createCube(0, 0, 0);
            var cutterPos = new Vector3(3, 3, 3);
            var cutterSca = new Vector3(4, 4, 4);

            this.cutter.transform.position   = cutterPos;
            this.cutter.transform.localScale = cutterSca;
            Debug.Log(string.Format("testing cutter with pos:{0} sca:{1}", cutterPos, cutterSca));

            NodeDataManager.onAddNode += this.onAddNode;
            NodeHoleCutter.CutHoles(this.cutter);

            Assert.AreEqual(3, this.nodesCreated.Count, "There are not 3 holes");

            var expectedPosLong  = new Vector2(0, 0.15f);
            var expectedPosShort = new Vector2(0.15f, 0.35f);

            var expectedScaleLong  = new Vector2(1, 0.7f);
            var expectedScaleShort = new Vector2(0.7f, 0.3f);

            foreach (var hole in this.nodesCreated)
            {
                Assert.AreEqual(NodeType.HOLE, hole.nodeType);
                // json's hole centre will still be outside of quad, but when hole is created it is scaled to fit inside


                if (hole.behaviour.name.Contains("right"))
                {
                    foreach (var child in hole.behaviour.Children)
                    {
                        if (child.name.Contains("right bottom"))
                        {
                            Assert.AreApproximatelyEqual(expectedPosLong.x, child.transform.localPosition.x, "hole behaviour has wrong X pos");
                            Assert.AreApproximatelyEqual(-expectedPosLong.y, child.transform.localPosition.y, "hole behaviour has wrong Y pos");
                            Assert.AreApproximatelyEqual(expectedScaleLong.x, child.transform.localScale.x, "hole behaviour has wrong X sca");
                            Assert.AreApproximatelyEqual(expectedScaleLong.y, child.transform.localScale.y, "hole behaviour has wrong Y sca");
                        }
                        if (child.name.Contains("right right"))
                        {
                            Assert.AreApproximatelyEqual(expectedPosShort.x, child.transform.localPosition.x, "hole behaviour has wrong X pos");
                            Assert.AreApproximatelyEqual(expectedPosShort.y, child.transform.localPosition.y, "hole behaviour has wrong Y pos");
                            Assert.AreApproximatelyEqual(expectedScaleShort.x, child.transform.localScale.x, "hole behaviour has wrong X sca");
                            Assert.AreApproximatelyEqual(expectedScaleShort.y, child.transform.localScale.y, "hole behaviour has wrong Y sca");
                        }
                    }

                    Assert.AreApproximatelyEqual(-3f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(3f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(4f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(4f, hole.scale.y, "hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("front"))
                {
                    foreach (var child in hole.behaviour.Children)
                    {
                        if (child.name.Contains("front bottom"))
                        {
                            Assert.AreApproximatelyEqual(expectedPosLong.x, child.transform.localPosition.x, "hole behaviour has wrong X pos");
                            Assert.AreApproximatelyEqual(-expectedPosLong.y, child.transform.localPosition.y, "hole behaviour has wrong Y pos");
                            Assert.AreApproximatelyEqual(expectedScaleLong.x, child.transform.localScale.x, "hole behaviour has wrong X sca");
                            Assert.AreApproximatelyEqual(expectedScaleLong.y, child.transform.localScale.y, "hole behaviour has wrong Y sca");
                        }
                        if (child.name.Contains("front left"))
                        {
                            Assert.AreApproximatelyEqual(-expectedPosShort.x, child.transform.localPosition.x, "hole behaviour has wrong X pos");
                            Assert.AreApproximatelyEqual(expectedPosShort.y, child.transform.localPosition.y, "hole behaviour has wrong Y pos");
                            Assert.AreApproximatelyEqual(expectedScaleShort.x, child.transform.localScale.x, "hole behaviour has wrong X sca");
                            Assert.AreApproximatelyEqual(expectedScaleShort.y, child.transform.localScale.y, "hole behaviour has wrong Y sca");
                        }
                    }

                    Assert.AreApproximatelyEqual(3f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(3f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(4f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(4f, hole.scale.y, "hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("top"))
                {
                    foreach (var child in hole.behaviour.Children)
                    {
                        if (child.name.Contains("top top"))
                        {
                            Assert.AreApproximatelyEqual(expectedPosLong.x, child.transform.localPosition.x, "hole behaviour has wrong X pos");
                            Assert.AreApproximatelyEqual(expectedPosLong.y, child.transform.localPosition.y, "hole behaviour has wrong Y pos");
                            Assert.AreApproximatelyEqual(expectedScaleLong.x, child.transform.localScale.x, "hole behaviour has wrong X sca");
                            Assert.AreApproximatelyEqual(expectedScaleLong.y, child.transform.localScale.y, "hole behaviour has wrong Y sca");
                        }
                        if (child.name.Contains("top left"))
                        {
                            Assert.AreApproximatelyEqual(-expectedPosShort.x, child.transform.localPosition.x, "hole behaviour has wrong X pos");
                            Assert.AreApproximatelyEqual(-expectedPosShort.y, child.transform.localPosition.y, "hole behaviour has wrong Y pos");
                            Assert.AreApproximatelyEqual(expectedScaleShort.x, child.transform.localScale.x, "hole behaviour has wrong X sca");
                            Assert.AreApproximatelyEqual(expectedScaleShort.y, child.transform.localScale.y, "hole behaviour has wrong Y sca");
                        }
                    }

                    Assert.AreApproximatelyEqual(3f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(-3f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(4f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(4f, hole.scale.y, "hole has wrong Y sca");
                }
            }

            NodeDataManager.onAddNode -= this.onAddNode;
            CleanUp();
        }