@@ -92,4 +92,33 @@ class WorldSuite extends munit.FunSuite {
9292
9393 assertEquals(contains(w, randomSphere), false )
9494 }
95+
96+ test(" Shading an intersection" ) {
97+ val w = defaultWorld()
98+ val r = ray.ray(tuple.makePoint(0 , 0 , - 5 ), tuple.makeVector(0 , 0 , 1 ))
99+ val shape = w.objects(0 ) // the first object in w
100+ val i = com.samuelcantrell.raytracer.intersection.intersection(4 , shape)
101+ val comps =
102+ com.samuelcantrell.raytracer.intersection.prepareComputations(i, r)
103+ val c = shadeHit(w, comps)
104+ val expected = color.Color (0.38066 , 0.47583 , 0.2855 )
105+
106+ assertEquals(color.isEqual(c, expected, 0.00001 ), true )
107+ }
108+
109+ test(" Shading an intersection from the inside" ) {
110+ val w = defaultWorld()
111+ val newLight =
112+ light.pointLight(tuple.makePoint(0 , 0.25 , 0 ), color.Color (1 , 1 , 1 ))
113+ val wWithNewLight = w.copy(lightSource = Some (newLight))
114+ val r = ray.ray(tuple.makePoint(0 , 0 , 0 ), tuple.makeVector(0 , 0 , 1 ))
115+ val shape = wWithNewLight.objects(1 ) // the second object in w
116+ val i = com.samuelcantrell.raytracer.intersection.intersection(0.5 , shape)
117+ val comps =
118+ com.samuelcantrell.raytracer.intersection.prepareComputations(i, r)
119+ val c = shadeHit(wWithNewLight, comps)
120+ val expected = color.Color (0.90498 , 0.90498 , 0.90498 )
121+
122+ assertEquals(color.isEqual(c, expected, 0.00001 ), true )
123+ }
95124}
0 commit comments