Exemplo n.º 1
0
        public void FilterIntersectionList()
        {
            string[] str = new string[3] {
                "union", "intersection", "difference"
            };
            int[,] intersectionIndices = new int[3, 2] {
                //lhit  inl   inr   result
                { 0, 3 },
                { 1, 2 },
                { 0, 1 }
            };
            Shape s1 = new Sphere();
            Shape s2 = new Cube();
            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(1, s1));
            xs.Add(new Intersection(2, s2));
            xs.Add(new Intersection(3, s1));
            xs.Add(new Intersection(4, s2));
            for (int i = 0; i < 3; i++)
            {
                CSG c = new CSG(str[i], s1, s2);
                List <Intersection> result = c.FilterIntersections(xs);
                Assert.AreEqual(result.Count, 2);
                Assert.AreEqual(result[0], xs[intersectionIndices[i, 0]]);
                Assert.AreEqual(result[1], xs[intersectionIndices[i, 1]]);
            }
        }
Exemplo n.º 2
0
        public void TestCsgFilteringIntersections()
        {
            var s1 = new Sphere();
            var s2 = new Cube();

            var i1 = new Intersection(1, s1);
            var i2 = new Intersection(2, s2);
            var i3 = new Intersection(3, s1);
            var i4 = new Intersection(4, s2);
            var xs = new Intersections(i1, i2, i3, i4);

            var op = new CsgOperation[] { CsgOperation.Union, CsgOperation.Intersection, CsgOperation.Difference };
            var x0 = new int[] { 0, 1, 0 };
            var x1 = new int[] { 3, 2, 1 };

            for (int i = 0; i < op.Length; i++)
            {
                var           c      = new CSG(op[i], s1, s2);
                Intersections result = c.FilterIntersections(xs);

                Assert.AreEqual(result.Count, 2, i.ToString());
                Assert.AreEqual(result[0], xs[x0[i]], i.ToString());
                Assert.AreEqual(result[1], xs[x1[i]], i.ToString());
            }
        }
        public void FilteringAListOfIntersections(string operation, int x0, int x1)
        {
            var s1 = new Sphere();
            var s2 = new Cube();

            var c  = new CSG(Operation.OfKind(operation), s1, s1);
            var xs = new Intersections(
                new Intersection(1, s1),
                new Intersection(2, s2),
                new Intersection(3, s1),
                new Intersection(4, s2));
            var result = c.FilterIntersections(xs);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(xs[x0], result[0]);
            Assert.AreEqual(xs[x1], result[1]);
        }
Exemplo n.º 4
0
        public void T05_FilteringAListOfIntersections()
        {
            Sphere s1 = new Sphere();
            Cube   s2 = new Cube();

            CSG c1 = new CSG(CSG.Operation.Union, s1, s2);
            CSG c2 = new CSG(CSG.Operation.Intersection, s1, s2);
            CSG c3 = new CSG(CSG.Operation.Difference, s1, s2);

            List <Intersection> xs = new List <Intersection>();

            xs.Add(new Intersection(s1, 1));
            xs.Add(new Intersection(s2, 2));
            xs.Add(new Intersection(s1, 3));
            xs.Add(new Intersection(s2, 4));

            List <CSG.Operation> operation = new List <CSG.Operation>();
            List <int>           x0        = new List <int>();
            List <int>           x1        = new List <int>();

            operation.Add(CSG.Operation.Union);
            operation.Add(CSG.Operation.Intersection);
            operation.Add(CSG.Operation.Difference);

            x0.Add(0); x0.Add(1); x0.Add(0);
            x1.Add(3); x1.Add(2); x1.Add(1);

            //Union
            List <Intersection> result = c1.FilterIntersections(xs);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(xs[x0[0]], result[0]);
            Assert.AreEqual(xs[x1[0]], result[1]);

            //Intersection
            result = c2.FilterIntersections(xs);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(xs[x0[1]], result[0]);
            Assert.AreEqual(xs[x1[1]], result[1]);

            //Difference
            result = c3.FilterIntersections(xs);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(xs[x0[2]], result[0]);
            Assert.AreEqual(xs[x1[2]], result[1]);
        }