-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera-tests.rkt
74 lines (64 loc) · 1.98 KB
/
camera-tests.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#lang typed/racket
;; CMSC 15100 Winter 2022
;; Project 2
;; camera-tests.rkt module
;;
;; Eyeball tests for the camera.rkt module.
;;
;; load custom definitions
;;
(require "../include/cs151-core.rkt")
;; load image library definitions
;;
(require "../include/cs151-image.rkt")
;; load testing infrastructure
;;
(require typed/test-engine/racket-tests)
;; project modules
;;
(require "util.rkt")
(require "math-util.rkt")
(require "color.rkt")
(require "camera.rkt")
(define cam-400x200x1-0.0 (simple-camera 400 200 1 0.0))
(define cam-400x200x1-0.25 (simple-camera 400 200 1 0.25))
(define cam-400x200x1 (simple-camera 400 200 1 1.0))
(define cam-400x200x4 (simple-camera 400 200 4 0.25))
;; Test foreach-pixel
;;
"== eyeball test foreach-pixel"
(local
{(define wid : Natural 400)
(define ht : Natural 200)}
(foreach-pixel
cam-400x200x1-0.0
(make-pixel-renderer
(lambda ([r : Natural] [c : Natural])
(if (and (< r ht) (< c wid))
(RGB (/ (->fl c) (->fl wid))
(/ (->fl (- ht r)) (->fl ht))
0.2)
(error "row/column out of range")))
rgb->color)))
"== background test"
(foreach-pixel cam-400x200x1-0.25
(make-pixel-renderer
(pixel->rgb cam-400x200x1-0.25 ray->rgb)
rgb->color))
"== test ray-for-pixel"
(foreach-pixel cam-400x200x1-0.25
(make-pixel-renderer
(pixel->rgb cam-400x200x1-0.25
(lambda ([ray : Ray])
(match ray
[(Ray _ dir)
(RGB
(* 0.5 (+ 1.0 (Float3-x dir)))
(* 0.5 (+ 1.0 (Float3-y dir)))
(* 0.5 (+ 1.0 (Float3-z dir))))])))
rgb->color))
"== AA-4 background"
(foreach-pixel cam-400x200x4
(make-pixel-renderer
(antialias-pixel->rgb cam-400x200x4 ray->rgb)
rgb->color))