;; --- CSU213 Fall 2006 Lecture Notes --------- ;; Copyright 2006 Viera K. Proulx ;; Lecture 6: September 18, 2006 ;; Designing Methods for Unions of Classes ;; HtDP version - data definitions, examples, purpose statements and contracts ;; An IShape is one of ;; -- (make-circle Posn Number String) ;; -- (make-square Posn Number String) (define-struct circle (center radius color)) (define-struct square (nw size color)) ;; Examples: (define pt1 (make-posn 0 0)) (define pt2 (make-posn 3 4)) (define pt3 (make-posn 7 1)) (define c1 (make-circle (make-posn 50 50) 10 "red")) (define c2 (make-circle (make-posn 50 50) 30 "red")) (define c3 (make-circle (make-posn 30 100) 30 "blue")) (define s1 (make-square (make-posn 50 50) 30 "red")) (define s2 (make-square (make-posn 50 50) 50 "red")) (define s3 (make-square (make-posn 20 40) 10 "green")) ;; Function purpose statements and contracts --- with default bodies ;; to compute the area of this shape (define (area this-shape) 0) ;; to compute the distance form this shape to the origin (define (distTo0 this-shape) 0) ;; to increase the size of this shape by the given increment (define (grow this-shape x) this-shape) ;; is the area of this shape is bigger than the area of the that shape? (define (biggerThan? this-shape that-shape) true) ;; does this shape (including the boundary) contain the given point? (define (contains? this-shape pt) true)