tightened up the check on polygon to make sure the posns contain reals
closes PR 10997
This commit is contained in:
parent
c926656b8a
commit
7282e19178
|
@ -106,6 +106,7 @@ and they all have good sample contracts. (It is amazing what we can do with kids
|
||||||
pen-style?
|
pen-style?
|
||||||
pen-cap?
|
pen-cap?
|
||||||
pen-join?
|
pen-join?
|
||||||
|
real-valued-posn?
|
||||||
color-red color-blue color-green color? color
|
color-red color-blue color-green color? color
|
||||||
pen-color pen-width pen-style pen-cap pen-join
|
pen-color pen-width pen-style pen-cap pen-join
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
pen-style?
|
pen-style?
|
||||||
pen-cap?
|
pen-cap?
|
||||||
pen-join?
|
pen-join?
|
||||||
|
real-valued-posn?
|
||||||
check-mode/color-combination)
|
check-mode/color-combination)
|
||||||
|
|
||||||
(require htdp/error
|
(require htdp/error
|
||||||
|
@ -231,6 +232,10 @@
|
||||||
(andmap posn? arg))
|
(andmap posn? arg))
|
||||||
'list-of-posns
|
'list-of-posns
|
||||||
i arg)
|
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
|
(check-arg fn-name
|
||||||
(>= (length arg) 3)
|
(>= (length arg) 3)
|
||||||
'list-of-at-least-three-posns
|
'list-of-at-least-three-posns
|
||||||
|
@ -293,6 +298,10 @@
|
||||||
(define (pen-join? arg)
|
(define (pen-join? arg)
|
||||||
(member (if (string? arg) (string->symbol arg) arg)
|
(member (if (string? arg) (string->symbol arg) arg)
|
||||||
'(round bevel miter)))
|
'(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
|
;; checks the dependent part of the 'color' specification
|
||||||
|
|
|
@ -1914,6 +1914,11 @@
|
||||||
'solid (make-pen "black" 12 "solid" "round" "round"))
|
'solid (make-pen "black" 12 "solid" "round" "round"))
|
||||||
=>
|
=>
|
||||||
#rx"^polygon: expected <image-color>")
|
#rx"^polygon: expected <image-color>")
|
||||||
|
(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 <list-of-posns-with-real-valued-x-and-y-coordinates>")
|
||||||
|
|
||||||
|
|
||||||
(test/exn (save-image "tri.png" (triangle 50 "solid" "purple"))
|
(test/exn (save-image "tri.png" (triangle 50 "solid" "purple"))
|
||||||
=>
|
=>
|
||||||
|
|
|
@ -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?]
|
[mode mode?]
|
||||||
[color image-color?])
|
[color image-color?])
|
||||||
image?]
|
image?]
|
||||||
[(polygon [vertices (listof posn?)]
|
[(polygon [vertices (listof real-valued-posn?)]
|
||||||
[outline-mode (or/c 'outline "outline")]
|
[outline-mode (or/c 'outline "outline")]
|
||||||
[pen-or-color (or/c pen? image-color?)])
|
[pen-or-color (or/c pen? image-color?)])
|
||||||
image?])]{
|
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].
|
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?]
|
@defstruct[pen ([color image-color?]
|
||||||
[width (and/c real? (<=/c 0 255))]
|
[width (and/c real? (<=/c 0 255))]
|
||||||
[style pen-style?]
|
[style pen-style?]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user