take advantage of new equal<%> and snip% setup to make image-snip%s equal to 2htdp/image images (when appropriate)

This commit is contained in:
Robby Findler 2010-12-23 21:45:03 -06:00
parent 2f009ca529
commit e896360dcf
2 changed files with 17 additions and 4 deletions

View File

@ -1312,6 +1312,12 @@
=>
(to-img (make-object image-snip% green-blue-20x10-bitmap)))
;; make sure that raw image snips are equal to image snips
(let ([i1 (make-object image-snip% (collection-file-path "bug09.png" "icons"))]
[i2 (make-object image-snip% (collection-file-path "bug09.png" "icons"))])
(test (equal? (rotate 0 i1) i2) => #t)
(test (equal? i1 (rotate 0 i2)) => #t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; cropping (and place-image)

View File

@ -223,9 +223,13 @@ has been moved out).
(send bdc set-bitmap #f))))
(define image%
(class* snip% (png-convertible<%> equal<%> image<%>)
(class* snip% (png-convertible<%> image<%>)
(init-field shape bb normalized? pinhole)
(define/public (equal-to? that eq-recur)
(define/override (equal-to? that eq-recur) (compare-em that eq-recur))
(define/override (other-equal-to? that eq-recur) (compare-em that eq-recur))
(define/private (compare-em that eq-recur)
(or (eq? this that)
(let ([that
(cond
@ -256,8 +260,11 @@ has been moved out).
(render-image obj bdc 0 0)
(send bdc get-argb-pixels 0 0 (send bm get-width) (send bm get-height) bytes))
(define/public (equal-hash-code-of y) 42)
(define/public (equal-secondary-hash-code-of y) 3)
;; this could render the image into a bitmap and then get the hash code of the bytes
;; cannot render the tree into a string and then get the hash code of that string
;; b/c that might make equal things have the same code.
(define/override (equal-hash-code-of y) 42)
(define/override (equal-secondary-hash-code-of y) 3)
(define/public (get-shape) shape)
(define/public (set-shape s) (set! shape s))