示例#1
0
        public async Task AutoArrangeChildrenTests()
        {
            // arrange a single item around the origin
            {
                var      scene = new InteractiveScene();
                Object3D cube1;
                scene.Children.Add(cube1 = new Object3D()
                {
                    Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                    Matrix = Matrix4X4.CreateTranslation(34, 22, 10)
                });

                Assert.IsTrue(new AxisAlignedBoundingBox(24, 12, 0, 44, 32, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));

                await scene.AutoArrangeChildren(Vector3.Zero);

                Assert.IsTrue(new AxisAlignedBoundingBox(-10, -10, 0, 10, 10, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));
            }

            // arrange a single item around a typical bed center
            {
                var      scene = new InteractiveScene();
                Object3D cube1;
                scene.Children.Add(cube1 = new Object3D()
                {
                    Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                    Matrix = Matrix4X4.CreateTranslation(34, 22, 10)
                });

                Assert.IsTrue(new AxisAlignedBoundingBox(24, 12, 0, 44, 32, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));

                await scene.AutoArrangeChildren(new Vector3(100, 100, 0));

                Assert.IsTrue(new AxisAlignedBoundingBox(90, 90, 0, 110, 110, 20).Equals(cube1.GetAxisAlignedBoundingBox(), .001));
            }

            // arrange 4 items
            {
                var scene = new InteractiveScene();
                for (int i = 0; i < 4; i++)
                {
                    scene.Children.Add(new Object3D()
                    {
                        Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                        Matrix = Matrix4X4.CreateTranslation(i * 134, i * -122, 10)
                    });
                }

                var sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Greater(sceneAabb.XSize, 160);
                Assert.Greater(sceneAabb.YSize, 160);

                await scene.AutoArrangeChildren(Vector3.Zero);

                sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Less(sceneAabb.XSize, 60);
                Assert.Less(sceneAabb.YSize, 75);
            }

            // arrange 4 items, starting with 1 selected
            {
                var      scene = new InteractiveScene();
                Object3D child = null;
                for (int i = 0; i < 4; i++)
                {
                    scene.Children.Add(child = new Object3D()
                    {
                        Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                        Matrix = Matrix4X4.CreateTranslation(i * 134, i * -122, 10)
                    });
                }

                scene.SelectedItem = child;

                var sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Greater(sceneAabb.XSize, 160);
                Assert.Greater(sceneAabb.YSize, 160);

                await scene.AutoArrangeChildren(Vector3.Zero);

                sceneAabb = scene.GetAxisAlignedBoundingBox();
                Assert.Less(sceneAabb.XSize, 60);
                Assert.Less(sceneAabb.YSize, 75);
            }
        }