diff --git a/collects/2htdp/tests/test-image.rkt b/collects/2htdp/tests/test-image.rkt index b11e453ba7..89f844134f 100644 --- a/collects/2htdp/tests/test-image.rkt +++ b/collects/2htdp/tests/test-image.rkt @@ -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) diff --git a/collects/mrlib/image-core.rkt b/collects/mrlib/image-core.rkt index 1d8fdfda7b..b0c3c16c83 100644 --- a/collects/mrlib/image-core.rkt +++ b/collects/mrlib/image-core.rkt @@ -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))