special case the four cardinal directions during rotation so they rotate

exactly (this also makes flip-horizontal and flip-vertical work equally
well)

closes PR 12323
This commit is contained in:
Robby Findler 2011-10-26 16:36:07 -05:00
parent 48f9b8895c
commit 0dff5ca92b
2 changed files with 19 additions and 9 deletions

View File

@ -545,7 +545,7 @@
(let* ([unrotated (translate-shape simple-shape)]
[rotated (rotate-atomic θ unrotated)])
(let-values ([(dx dy)
(c->xy (* (make-polar 1 (degrees->radians θ))
(c->xy (* (degrees->complex θ)
(xy->c (translate-dx simple-shape)
(translate-dy simple-shape))))])
(make-translate dx dy rotated)))]))
@ -748,8 +748,18 @@
(make-point x y)))
(define (rotate-c c θ)
(* (make-polar 1 (degrees->radians θ))
c))
(* (degrees->complex θ) c))
(define (degrees->complex θ)
(unless (and (<= 0 θ)
(< θ 360))
(error 'degrees->complex "~s" θ))
(case (modulo θ 360)
[(0) 1+0i]
[(90) 0+1i]
[(180) -1+0i]
[(270) 0-1i]
[else (make-polar 1 (degrees->radians θ))]))
;; rotate-xy : x,y angle -> x,y
(define (rotate-xy x y θ)

View File

@ -1860,12 +1860,12 @@
(test (pinhole-y (flip-vertical (put-pinhole 1 2 (rectangle 10 20 'solid 'red))))
=>
18)
(test (pinhole-x (flip-horizontal (put-pinhole 1 2 (rectangle 10 20 'solid 'red))))
=>
9.0)
(test (pinhole-y (flip-horizontal (put-pinhole 1 2 (rectangle 10 20 'solid 'red))))
=>
2.0)
(check-= (pinhole-x (flip-horizontal (put-pinhole 1 2 (rectangle 10 20 'solid 'red))))
9.0
0)
(check-= (pinhole-y (flip-horizontal (put-pinhole 1 2 (rectangle 10 20 'solid 'red))))
2.0
0)
(test (equal? (center-pinhole (rectangle 10 12 'solid 'blue))
(rectangle 10 12 'solid 'blue))
=>