diff --git a/collects/2htdp/image.rkt b/collects/2htdp/image.rkt index 87b296e4ab..21593414c6 100644 --- a/collects/2htdp/image.rkt +++ b/collects/2htdp/image.rkt @@ -106,6 +106,7 @@ and they all have good sample contracts. (It is amazing what we can do with kids pen-style? pen-cap? pen-join? + real-valued-posn? color-red color-blue color-green color? color pen-color pen-width pen-style pen-cap pen-join diff --git a/collects/2htdp/private/img-err.rkt b/collects/2htdp/private/img-err.rkt index 7e42d26671..698bfcc213 100644 --- a/collects/2htdp/private/img-err.rkt +++ b/collects/2htdp/private/img-err.rkt @@ -10,6 +10,7 @@ pen-style? pen-cap? pen-join? + real-valued-posn? check-mode/color-combination) (require htdp/error @@ -231,6 +232,10 @@ (andmap posn? arg)) 'list-of-posns i arg) + (check-arg fn-name + (andmap real-valued-posn? arg) + 'list-of-posns-with-real-valued-x-and-y-coordinates + i arg) (check-arg fn-name (>= (length arg) 3) 'list-of-at-least-three-posns @@ -293,6 +298,10 @@ (define (pen-join? arg) (member (if (string? arg) (string->symbol arg) arg) '(round bevel miter))) +(define (real-valued-posn? arg) + (and (posn? arg) + (real? (posn-x arg)) + (real? (posn-y arg)))) ;; checks the dependent part of the 'color' specification diff --git a/collects/2htdp/tests/test-image.rkt b/collects/2htdp/tests/test-image.rkt index 89f844134f..644155295f 100644 --- a/collects/2htdp/tests/test-image.rkt +++ b/collects/2htdp/tests/test-image.rkt @@ -1914,6 +1914,11 @@ 'solid (make-pen "black" 12 "solid" "round" "round")) => #rx"^polygon: expected ") +(test/exn (polygon (list (make-posn 0 0+1i) (make-posn 100 0) (make-posn 100 100)) + 'solid (make-pen "black" 12 "solid" "round" "round")) + => + #rx"^polygon: expected ") + (test/exn (save-image "tri.png" (triangle 50 "solid" "purple")) => diff --git a/collects/teachpack/2htdp/scribblings/image.scrbl b/collects/teachpack/2htdp/scribblings/image.scrbl index 78ddc3eaca..1a7bb918fd 100644 --- a/collects/teachpack/2htdp/scribblings/image.scrbl +++ b/collects/teachpack/2htdp/scribblings/image.scrbl @@ -559,11 +559,11 @@ the @scheme[point-count] argument determines how many points the star has. } -@defproc*[([(polygon [vertices (listof posn?)] +@defproc*[([(polygon [vertices (listof real-valued-posn?)] [mode mode?] [color image-color?]) image?] - [(polygon [vertices (listof posn?)] + [(polygon [vertices (listof real-valued-posn?)] [outline-mode (or/c 'outline "outline")] [pen-or-color (or/c pen? image-color?)]) image?])]{ @@ -1266,6 +1266,11 @@ Using @racket["pinhole"] or @racket['pinhole] is only allowed when all of the im Determines if @racket[x] is an integer greater than or equal to @racket[1]. } +@defproc[(real-valued-posn? [x any/c]) boolean?]{ + Determines if @racket[x] is a @racket[posn] whose @racket[_x] and @racket[_y] + fields are both @racket[real?] numbers. +} + @defstruct[pen ([color image-color?] [width (and/c real? (<=/c 0 255))] [style pen-style?]