fix problem with rotation on images such as bitmaps
and replace internal `bring-between' with an efficient version Closes PR 11124
This commit is contained in:
parent
7e1a6ec908
commit
e0d9d2565c
|
@ -616,8 +616,8 @@
|
|||
(make-bitmap (bitmap-raw-bitmap bitmap)
|
||||
(bitmap-raw-mask bitmap)
|
||||
(bring-between (if flipped?
|
||||
(+ θ (bitmap-angle bitmap))
|
||||
(- (+ θ (bitmap-angle bitmap))))
|
||||
(- (bitmap-angle bitmap) θ)
|
||||
(+ (bitmap-angle bitmap) θ))
|
||||
360)
|
||||
(bitmap-x-scale bitmap)
|
||||
(bitmap-y-scale bitmap)
|
||||
|
@ -647,19 +647,14 @@
|
|||
(make-point x y)))
|
||||
|
||||
|
||||
;; bring-between : number number -> number
|
||||
;; returns a number that is much like the modulo of 'x' and 'upper-bound'
|
||||
;; but does this by repeated subtraction (or addition if it is negative),
|
||||
;; bring-between : rational integer -> rational
|
||||
;; returns a number that is much like the modulo of 'x' and 'upper-bound',
|
||||
;; since modulo only works on integers
|
||||
(define (bring-between x upper-bound)
|
||||
(let loop ([x x])
|
||||
(cond
|
||||
[(< x 0)
|
||||
(loop (+ x upper-bound))]
|
||||
[(< x upper-bound)
|
||||
x]
|
||||
[else
|
||||
(loop (- x upper-bound))])))
|
||||
(let* ([x-floor (floor x)]
|
||||
[fraction (- x x-floor)])
|
||||
(+ (modulo x-floor upper-bound)
|
||||
fraction)))
|
||||
|
||||
(define/chk (flip-horizontal image)
|
||||
(rotate 90 (flip-vertical (rotate -90 image))))
|
||||
|
|
|
@ -1262,15 +1262,28 @@
|
|||
=>
|
||||
(image-snip->image (make-object image-snip% blue-20x10-bitmap)))
|
||||
|
||||
(test (rotate 90 (make-object image-snip% green-blue-20x10-bitmap))
|
||||
(test (rotate -90 (make-object image-snip% green-blue-20x10-bitmap))
|
||||
=>
|
||||
(image-snip->image (make-object image-snip% green-blue-10x20-bitmap)))
|
||||
|
||||
(test (rotate 90 (rotate 90 (make-object image-snip% green-blue-20x10-bitmap)))
|
||||
=>
|
||||
(rotate 180 (make-object image-snip% green-blue-20x10-bitmap)))
|
||||
|
||||
(test (rotate 90 (flip-vertical (rotate 90 (make-object image-snip% green-blue-20x10-bitmap))))
|
||||
=>
|
||||
(rotate 0 (make-object image-snip% green-blue-20x10-bitmap)))
|
||||
|
||||
;; there was a bug in the bounding box computation for scaled bitmaps that this test exposes
|
||||
(test (image-width (frame (rotate 90 (scale 1/2 (bitmap icons/plt-logo-red-diffuse.png)))))
|
||||
=>
|
||||
128)
|
||||
|
||||
;; Rotation by 0 should produce an equivalent object
|
||||
(test (rotate 0 (make-object image-snip% green-blue-20x10-bitmap))
|
||||
=>
|
||||
(to-img (make-object image-snip% green-blue-20x10-bitmap)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; cropping (and place-image)
|
||||
|
|
Loading…
Reference in New Issue
Block a user