Ejemplo n.º 1
0
        public void Test(string scenario, bool expected, string stockCode, int quantity, string customerName)
        {
            // there are no side-effects, so it's OK to re-cycle __Client
            var _Actual = __Client.CreatePartInvoice(stockCode, quantity, customerName);

            CustomAssert.Equal <bool>(expected, _Actual.Success, scenario);
        }
        public void RefractedColorWithRefractedRay()
        {
            var w = World.Default();
            var a = w.Objects[0];

            a.Material.Ambient = 1;
            a.Material.Pattern = new pattern.TestPattern();

            var b = w.Objects[1];

            b.Material.Transparency    = 1;
            b.Material.RefractiveIndex = 1.5;

            var r  = new Ray(pt.Point(0, 0, 0.1), pt.Vector(0, 1, 0));
            var xs = Intersection.Intersections(
                new Intersection(-0.9899, a),
                new Intersection(-0.4899, b),
                new Intersection(0.4899, b),
                new Intersection(0.9899, a)
                );

            var comps = Computation.PrepareComputations(xs[2], r, xs);

            var c   = w.RefractedColor(comps, 5);
            var exp = new c(0, 0.99888, 0.04725);

            CustomAssert.Equal(exp, c, 5);
        }
        public void ReflectedColorForReflectiveMaterial()
        {
            var w     = World.Default();
            var shape = new shape.Plane()
            {
                Material = new Material()
                {
                    Reflective = 0.5
                },
                Transform = transform.Translation(0, -1, 0)
            };

            w.Objects.Add(shape);

            var r = new Ray(
                pt.Point(0, 0, -3),
                pt.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));

            var i     = new Intersection(Math.Sqrt(2), shape);
            var comps = Computation.PrepareComputations(i, r);

            var color = w.ReflectedColor(comps);
            //TODO var exp = new c(0.19032, 0.23790, 0.14274);
            var exp = new c(0.19035, 0.23793, 0.14276);

            CustomAssert.Equal(exp, color, 5);
        }
        public void ShadeHitReflectiveMaterial()
        {
            var w     = World.Default();
            var shape = new shape.Plane()
            {
                Material = new Material()
                {
                    Reflective = 0.5
                },
                Transform = transform.Translation(0, -1, 0)
            };

            w.Objects.Add(shape);

            var r = new Ray(
                pt.Point(0, 0, -3),
                pt.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2));

            var i     = new Intersection(Math.Sqrt(2), shape);
            var comps = Computation.PrepareComputations(i, r);

            var color = w.ShadeHit(comps);
            //TODO var exp = new c(0.87677, 0.92436, 0.82918);
            var exp = new c(0.87677, 0.92436, 0.82919);

            CustomAssert.Equal(exp, color, 5);
        }
Ejemplo n.º 5
0
        public void PuttingItTogether()
        {
            var a = new RTF.Matrix(4, 4);

            a.SetRow(0, new double[] { 3, -9, 7, 3 });
            a.SetRow(1, new double[] { 3, -8, 2, -9 });
            a.SetRow(2, new double[] { -4, 4, 4, 1 });
            a.SetRow(3, new double[] { -6, 5, -1, 1 });

            var identity = RTF.Matrix.GetIdentity(4, 4);

            Assert.Equal(identity, identity.Inverse());

            var idInverted = a * a.Inverse();

            CustomAssert.Equal(identity, idInverted, 0);

            var transposeInvert = a.Transpose().Inverse();
            var invertTranspose = a.Inverse().Transpose();


            CustomAssert.Equal(transposeInvert, invertTranspose, 5);

            var modifiedIdentity = RTF.Matrix.GetIdentity(4, 4);

            modifiedIdentity[2, 2] = 6;
            var tuple         = new double[] { 1, 2, 3, 4 };
            var tupleIdentity = identity * tuple;
            var newTuple      = modifiedIdentity * tuple;

            Assert.Equal(tuple, tupleIdentity);
            Assert.NotEqual(tuple, newTuple);
        }
Ejemplo n.º 6
0
        public void ComputingNormalOnTransformedShape()
        {
            var s   = new shapes.TestShape(tf.Scaling(1, 0.5, 1) * tf.RotationZ(Math.PI / 5));
            var n   = s.NormalAt(pt.Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2));
            var exp = pt.Vector(0, 0.97014, -0.24254);

            CustomAssert.Equal(exp, n, 5);
        }
Ejemplo n.º 7
0
        public void ComputingNormalOnTranslatedShape()
        {
            var s   = new shapes.TestShape(tf.Translation(0, 1, 0));
            var n   = s.NormalAt(pt.Point(0, 1.70711, -0.70711));
            var exp = pt.Vector(0, 0.70711, -0.70711);

            CustomAssert.Equal(exp, n, 5);
        }
Ejemplo n.º 8
0
        public void ConstructingRayThroughCenterCanvas()
        {
            var c = new RTF.Camera(201, 101, Math.PI / 2);
            var r = c.RayForPixel(100, 50);

            Assert.Equal(RTF.PointType.Point(0, 0, 0), r.Origin);
            CustomAssert.Equal(RTF.PointType.Vector(0, 0, -1), r.Direction, 5);
        }
Ejemplo n.º 9
0
        public void TransformingBoudingBox()
        {
            var box    = new shape.BoundingBox(pt.Point(-1, -1, -1), pt.Point(1, 1, 1));
            var matrix = transform.RotationX(Math.PI / 4) * transform.RotationY(Math.PI / 4);
            var box2   = box.Transform(matrix);

            CustomAssert.Equal(pt.Point(-1.4142, -1.7071, -1.7071), box2.Minimum, 4);
            CustomAssert.Equal(pt.Point(1.4142, 1.7071, 1.7071), box2.Maximum, 4);
        }
Ejemplo n.º 10
0
        public void ComputingNormalVectorCone(double pX, double pY, double pZ, double vX, double vY, double vZ)
        {
            var s = new shape.Cone();

            var point  = pt.Point(pX, pY, pZ);
            var normal = pt.Vector(vX, vY, vZ).Normalize();

            var n = s.NormalAt(point);

            CustomAssert.Equal(normal, n, 5);
        }
Ejemplo n.º 11
0
        public void ReflectingVectorOffSlanted()
        {
            var v = pt.Vector(0, -1, 0);
            var n = pt.Vector(Math.Sqrt(2) / 2, Math.Sqrt(2) / 2, 0);

            pt r = RTF.Light.Reflect(v, n);

            var e = pt.Vector(1, 0, 0);

            CustomAssert.Equal(e, r, 5);
        }
Ejemplo n.º 12
0
        public void ColorRayHits()
        {
            var w = RTF.World.Default();
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, -5),
                RTF.PointType.Vector(0, 0, 1));
            var c   = w.ColorAt(r);
            var exp = new RTF.Color(0.38066, 0.47583, 0.2855);

            CustomAssert.Equal(exp, c, 5);
        }
Ejemplo n.º 13
0
        public void ConstructingRayThroughCornerCanvas()
        {
            var c = new RTF.Camera(201, 101, Math.PI / 2);
            var r = c.RayForPixel(0, 0);

            Assert.Equal(RTF.PointType.Point(0, 0, 0), r.Origin);
            CustomAssert.Equal(
                RTF.PointType.Vector(0.66519, 0.33259, -0.66851),
                r.Direction,
                5);
        }
Ejemplo n.º 14
0
        public void ColorRayMissed()
        {
            var w = RTF.World.Default();
            var r = new RTF.Ray(
                RTF.PointType.Point(0, 0, -5),
                RTF.PointType.Vector(0, 1, 0));
            var c   = w.ColorAt(r);
            var exp = RTF.Color.Black;

            CustomAssert.Equal(exp, c, 5);
        }
Ejemplo n.º 15
0
        public void InvertedRotationPointXAxis()
        {
            var p = RTF.PointType.Point(0, 1, 0);

            var halfQuarter = RTH.Transformations.RotationX(Math.PI / 4);
            var inverted    = halfQuarter.Inverse();

            var expected = RTF.PointType.Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);

            CustomAssert.Equal(expected, inverted * p, 5);
        }
Ejemplo n.º 16
0
        public void TestPIT()
        {
            var twelve = RTF.PointType.Point(0, 0, 1);
            var r      = RTH.Transformations.RotationY(3 * (Math.PI / 6));
            var r2     = RTH.Transformations.RotationY(6 * (Math.PI / 6));

            var three = RTF.PointType.Point(1, 0, 0);
            var six   = RTF.PointType.Point(0, 0, -1);

            CustomAssert.Equal(three, r * twelve, 0);
            CustomAssert.Equal(six, r2 * twelve, 0);
        }
Ejemplo n.º 17
0
        public void NormalOnTranslatedSphere()
        {
            var s = new Sphere
            {
                Transform = RTH.Transformations.Translation(0, 1, 0)
            };

            pt  n = s.NormalAt(pt.Point(0, 1.70711, -0.70711));
            var e = pt.Vector(0, 0.70711, -0.70711);

            CustomAssert.Equal(e, n, 5);
        }
Ejemplo n.º 18
0
        public void NormalOnTransformedSphere()
        {
            var s = new Sphere
            {
                Transform = RTH.Transformations.Scaling(1, 0.5, 1) * RTH.Transformations.RotationZ(Math.PI / 5)
            };

            pt  n = s.NormalAt(pt.Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2));
            var e = pt.Vector(0, 0.97014, -0.24254);

            CustomAssert.Equal(e, n, 5);
        }
Ejemplo n.º 19
0
        public void TransformationChained()
        {
            var p = RTF.PointType.Point(1, 0, 1);
            var a = RTH.Transformations.RotationX(Math.PI / 2);
            var b = RTH.Transformations.Scaling(5, 5, 5);
            var c = RTH.Transformations.Translation(10, 5, 7);

            var t = c * b * a;

            var expected = RTF.PointType.Point(15, 0, 7);

            CustomAssert.Equal(expected, t * p, 0);
        }
Ejemplo n.º 20
0
        public void LightingWithEyeOppositeSurfaceOffset45()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, 0, -1);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 10, -10), new RTF.Color(1, 1, 1));
            var result = light.Lighting(m, new Sphere(), position, eyeVector, normalVector, false);

            CustomAssert.Equal(new RTF.Color(0.7364, 0.7364, 0.7364), result, 4);
        }
Ejemplo n.º 21
0
        public void LightingWithEyeBetweenLightSurface()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, 0, -1);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 0, -10), new RTF.Color(1, 1, 1));
            var result = RTF.Light.Lighting(m, new Sphere(), light, position, eyeVector, normalVector, false);

            CustomAssert.Equal(new RTF.Color(1.9, 1.9, 1.9), result, 5);
        }
Ejemplo n.º 22
0
        public void RotationPointXAxis()
        {
            var p = RTF.PointType.Point(0, 1, 0);

            var halfQuarter = RTH.Transformations.RotationX(Math.PI / 4);
            var expected1   = RTF.PointType.Point(0, Math.Sqrt(2) / 2, Math.Sqrt(2) / 2);

            Assert.Equal(expected1, halfQuarter * p);

            var fullQuarter = RTH.Transformations.RotationX(Math.PI / 2);
            var expected2   = RTF.PointType.Point(0, 0, 1);

            CustomAssert.Equal(expected2, fullQuarter * p, 0);
        }
Ejemplo n.º 23
0
        public void FindingNormalOnChildObject()
        {
            var g1 = new shape.Group(transform.RotationY(Math.PI / 2));
            var g2 = new shape.Group(transform.Scaling(1, 2, 3));

            g1.Add(g2);
            var s = new shape.Sphere(transform.Translation(5, 0, 0));

            g2.Add(s);
            var n = s.NormalAt(pt.Point(1.7311, 1.1547, -5.5774));

            //TODO precision error
            CustomAssert.Equal(pt.Vector(0.2856, 0.4286, -0.8572), n, 4);
        }
Ejemplo n.º 24
0
        public void ConvertingNormalFromObjectToWorldSpace()
        {
            var g1 = new shape.Group(transform.RotationY(Math.PI / 2));
            var g2 = new shape.Group(transform.Scaling(1, 2, 3));

            g1.Add(g2);
            var s = new shape.Sphere(transform.Translation(5, 0, 0));

            g2.Add(s);
            var value = Math.Sqrt(3) / 3;
            var n     = s.NormalToWorld(pt.Vector(value, value, value));

            CustomAssert.Equal(pt.Vector(0.2857, 0.4286, -0.8571), n, 4);
        }
Ejemplo n.º 25
0
        public void LightingWithEyePathReflection()
        {
            var m        = new RTF.Material();
            var position = pt.Point(0, 0, 0);

            var eyeVector    = pt.Vector(0, -Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);
            var normalVector = pt.Vector(0, 0, -1);

            var light = new RTF.Light
                            (pt.Point(0, 10, -10), new RTF.Color(1, 1, 1));
            var result = light.Lighting(m, new Sphere(), position, eyeVector, normalVector, false);

            CustomAssert.Equal(new RTF.Color(1.6364, 1.6364, 1.6364), result, 4);
        }
Ejemplo n.º 26
0
        public void ConstructingRayWhenCameraTransformed()
        {
            var c = new RTF.Camera(201, 101, Math.PI / 2)
            {
                Transform = RTH.Transformations.RotationY(Math.PI / 4)
                            * RTH.Transformations.Translation(0, -2, 5)
            };
            var r = c.RayForPixel(100, 50);

            Assert.Equal(RTF.PointType.Point(0, 2, -5), r.Origin);
            CustomAssert.Equal(
                RTF.PointType.Vector(Math.Sqrt(2) / 2, 0, -Math.Sqrt(2) / 2),
                r.Direction,
                5);
        }
Ejemplo n.º 27
0
        public void SmoothTriangleUsesUVNormal()
        {
            var p1 = pt.Point(0, 1, 0);
            var p2 = pt.Point(-1, 0, 0);
            var p3 = pt.Point(1, 0, 0);
            var v1 = pt.Vector(0, 1, 0);
            var v2 = pt.Vector(-1, 0, 0);
            var v3 = pt.Vector(1, 0, 0);

            var tri = shape.Triangle.Smooth(p1, p2, p3, v1, v2, v3);
            var i   = Intersection.WithUV(1, tri, 0.45, 0.25);
            var n   = tri.NormalAt(pt.Point(0, 0, 0), i);

            CustomAssert.Equal(pt.Vector(-0.5547, 0.83205, 0), n, 5);
        }
Ejemplo n.º 28
0
        public void ConvertingPointFromWorldToObjectSpace()
        {
            var g1 = new shape.Group(transform.RotationY(Math.PI / 2));
            var g2 = new shape.Group(transform.Scaling(2, 2, 2));

            g1.Add(g2);

            var s = new shape.Sphere(transform.Translation(5, 0, 0));

            g2.Add(s);

            var p = s.WorldToObject(pt.Point(-2, 0, -10));

            CustomAssert.Equal(pt.Point(0, 0, -1), p, 5);
        }
Ejemplo n.º 29
0
        public void ArbitraryTransformation()
        {
            var from = RTF.PointType.Point(1, 3, 2);
            var to   = RTF.PointType.Point(4, -2, 8);
            var up   = RTF.PointType.Vector(1, 1, 0);

            RTF.Matrix t = RTH.Transformations.ViewTransform(from, to, up);
            var        e = new RTF.Matrix(4, 4);

            e.SetRow(0, new double[] { -0.50709, 0.50709, 0.67612, -2.36643 });
            e.SetRow(1, new double[] { 0.76772, 0.60609, 0.12122, -2.82843 });
            e.SetRow(2, new double[] { -0.35857, 0.59761, -0.71714, 0 });
            e.SetRow(3, new double[] { 0, 0, 0, 1 });

            CustomAssert.Equal(e, t, 5);
        }
Ejemplo n.º 30
0
        public void RenderingWorldWithCamera()
        {
            var w = RTF.World.Default();
            var c = new RTF.Camera(11, 11, Math.PI / 2);

            var from = RTF.PointType.Point(0, 0, -5);
            var to   = RTF.PointType.Point(0, 0, 0);
            var up   = RTF.PointType.Vector(0, 1, 0);

            c.Transform = RTH.Transformations.ViewTransform(from, to, up);

            RTF.Canvas image = RTF.Canvas.Render(c, w);

            var exp = new RTF.Color(0.38066, 0.47583, 0.2855);

            CustomAssert.Equal(exp, image.PixelAt(5, 5), 5);
        }