コード例 #1
0
        public void RayMissesCSGObject()
        {
            var c  = new shape.CSG(shape.Operation.Union, new shape.Sphere(), new shape.Cube());
            var r  = new Ray(pt.Point(0, 2, -5), pt.Vector(0, 0, 1));
            var xs = c.Intersect(r);

            Assert.Empty(xs);
        }
コード例 #2
0
        public void CSGCreatedWithOperationAndTwoShapes()
        {
            var s1 = new shape.Sphere();
            var s2 = new shape.Cube();
            var c  = new shape.CSG(shape.Operation.Union, s1, s2);

            Assert.Equal(shape.Operation.Union, c.Operation);
            Assert.Equal(s1, c.Left);
            Assert.Equal(s2, c.Right);
            Assert.Equal(c, s1.Parent);
            Assert.Equal(c, s2.Parent);
        }
コード例 #3
0
        public void RayHitsCSGObject()
        {
            var s1 = new shape.Sphere();
            var s2 = new shape.Sphere(transform.Translation(0, 0, 0.5));
            var c  = new shape.CSG(shape.Operation.Union, s1, s2);
            var r  = new Ray(pt.Point(0, 0, -5), pt.Vector(0, 0, 1));
            var xs = c.Intersect(r);

            Assert.Equal(2, xs.Count());
            Assert.Equal(4, xs[0].T);
            Assert.Equal(s1, xs[0].Object);
            Assert.Equal(6.5, xs[1].T);
            Assert.Equal(s2, xs[1].Object);
        }
コード例 #4
0
        public void FilteringListIntersections(string op, int x0, int x1)
        {
            var operation = (shape.Operation)Enum.Parse(typeof(shape.Operation), op);
            var s1        = new shape.Sphere();
            var s2        = new shape.Cube();

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

            List <Intersection> result = c.FilterIntersections(xs);

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