public Vector3 GetMaxPoint(RectangularCuboid r)
 {
     return(new Vector3(
                r.Position.X + r.SizeX / 2,
                r.Position.Y + r.SizeY / 2,
                r.Position.Z + r.SizeZ / 2));
 }
 public Vector3 GetMinPoint(RectangularCuboid r)
 {
     return(new Vector3(
                r.Position.X - r.SizeX / 2,
                r.Position.Y - r.SizeY / 2,
                r.Position.Z - r.SizeZ / 2));
 }
        public void RectangularCuboid_BoxifyVisitor_IsCorrect()
        {
            var start  = new Vector3(1, 2, 3);
            var cuboid = new RectangularCuboid(start, 5, 4, 3);
            var box    = cuboid.TryAcceptVisitor <RectangularCuboid>(new BoxifyVisitor());

            AssertCuboidsEqual(cuboid, box);
        }
        private void AssertCuboidsEqual(RectangularCuboid expected, RectangularCuboid actual)
        {
            var message = " is not equal!";

            Assert.That(expected.Position.Equals(actual.Position, Constants.Inaccuracy), $"{expected.Position} != {actual.Position}");
            Assert.AreEqual(expected.SizeX, actual.SizeX, Constants.Inaccuracy, "Length" + message);
            Assert.AreEqual(expected.SizeY, actual.SizeY, Constants.Inaccuracy, "Width" + message);
            Assert.AreEqual(expected.SizeZ, actual.SizeZ, Constants.Inaccuracy, "Height" + message);
        }
        public void RectangularCuboid_BoundingBoxVisitor_IsCorrect(
            double x, double y, double z,
            double length = 4, double width = 7, double height = 5)
        {
            var cuboid = new RectangularCuboid(new Vector3(x, y, z), length, width, height);
            var box    = cuboid.TryAcceptVisitor <RectangularCuboid>(new BoundingBoxVisitor());

            AssertCuboidsEqual(cuboid, box);
        }
        public void Ball_BoundingBoxVisitor_IsCorrect(double x, double y, double z, double radius)
        {
            var ball        = new Ball(new Vector3(x, y, z), radius);
            var box         = ball.TryAcceptVisitor <RectangularCuboid>(new BoundingBoxVisitor());
            var length      = radius * 2;
            var expectedBox = new RectangularCuboid(new Vector3(x, y, z), length, length, length);

            AssertCuboidsEqual(expectedBox, box);
        }
        public void Ball_BoxifyVisitor_IsCorrect()
        {
            const int radius      = 4;
            var       start       = new Vector3(1, 2, 3);
            var       ball        = new Ball(start, radius);
            var       box         = ball.TryAcceptVisitor <RectangularCuboid>(new BoxifyVisitor());
            var       side        = radius * 2;
            var       expectedBox = new RectangularCuboid(start, side, side, side);

            AssertCuboidsEqual(expectedBox, box);
        }
        public void Cylinder_BoxifyVisitor_IsCorrect()
        {
            const int radius      = 4;
            const int height      = 6;
            var       start       = new Vector3(1, 2, 3);
            var       cylinder    = new Cylinder(start, height, radius);
            var       box         = cylinder.TryAcceptVisitor <RectangularCuboid>(new BoxifyVisitor());
            var       side        = radius * 2;
            var       expectedBox = new RectangularCuboid(start, side, side, height);

            AssertCuboidsEqual(expectedBox, box);
        }
        public void CompoundBody_BoundingBox_IsCorrect(double x, double y, double z, double radius)
        {
            const int    figuresCount = 6;
            const double indent       = 2.2;
            var          height       = radius * 20 + indent * (figuresCount - 1);
            var          expectedBox  = new RectangularCuboid(new Vector3(x, y, height / 2 + z), radius * 2, radius * 2, height);

            foreach (var compoundBody in GetCompoundBodies(new Vector3(x, y, z), radius, indent))
            {
                var box = compoundBody.TryAcceptVisitor <RectangularCuboid>(new BoundingBoxVisitor());
                AssertCuboidsEqual(expectedBox, box);
            }
        }
        public void Cylinder_BoundingBox_IsCorrect(double x, double y, double z, double radius = 4, double height = 5)
        {
            var cylinder = new Cylinder(new Vector3(x, y, z), height, radius);
            var box      = cylinder.TryAcceptVisitor <RectangularCuboid>(new BoundingBoxVisitor());
            var cuboid   = new RectangularCuboid
                           (
                cylinder.Position,
                cylinder.Radius * 2,
                cylinder.Radius * 2,
                cylinder.SizeZ
                           );

            AssertCuboidsEqual(cuboid, box);
        }
        public void CompoundBody_BoxifyVisitor_IsCorrect()
        {
            var ball      = new Ball(new Vector3(1, 2, 3), 4);
            var box       = new RectangularCuboid(new Vector3(8, 9, 10), 2, 3, 4);
            var cylinder  = new Cylinder(new Vector3(-5, -6, -10), 3, 5);
            var cBall     = new Ball(new Vector3(12, 12, 12), 2);
            var cBox      = new RectangularCuboid(new Vector3(-12, -12, -12), 2, 2, 2);
            var cCylinder = new Cylinder(new Vector3(25, 25, 25), 2, 3);
            var compound  = new CompoundBody(new List <Body> {
                cBall, cBox, cCylinder
            });
            var compoundBody = new CompoundBody(new List <Body> {
                ball, box, cylinder, compound
            });

            var actual = compoundBody.TryAcceptVisitor <CompoundBody>(new BoxifyVisitor());

            AssertCompoundBodyBoxified(compoundBody, actual);
        }
 public object VisitRectangle(RectangularCuboid visited)
 {
     return(new BoundingBoxVisitor().VisitRectangle(visited));
 }
 public object VisitRectangle(RectangularCuboid visited)
 {
     return(new RectangularCuboid(visited.Position, visited.SizeX, visited.SizeY, visited.SizeZ));
 }
 public Body Visit(RectangularCuboid element)
 {
     return(element);
 }
 public Body VisitRectangularCuboid(RectangularCuboid rectCuboid)
 {
     return(new RectangularCuboid(rectCuboid.Position, rectCuboid.SizeX, rectCuboid.SizeY, rectCuboid.SizeZ));
 }