Question: hello. I need help to write in Dr racket or Scheme program to write the todo part #lang racket (provide rect rect? rect-area rect-intersect rect-list-intersect

hello. I need help to write in Dr racket or Scheme program to write the todo part

#lang racket

(provide rect

rect?

rect-area

rect-intersect

rect-list-intersect

all-sub-rectangles)

; any two opposing corners of a grid-aligned rectangle as pairs (x0,y0), (x1,y1)

; --> `(rect ,lower-left-x ,lower-left-y ,upper-right-x ,upper-right-y)

(define (rect x0 y0 x1 y1)

; return a normalized rect-tagged s-expr representation of the rectangle

(rect , (min x0 x1) , (min y0 y1) , (max x0 x1) , (max y0 y1))

; Predicate defining a rectangle

(define (rect? r)

(match r

[`(rect ,x0 ,y0 ,x1 ,y1)

(and (andmap integer? `(,x0 ,x1 ,y0 ,y1))

(<= x0 x1)

(<= y0 y1))]

[else #f]))

; Given a rect?, yield its (integer?) area

(define (rect-area rect)

'todo)

; Compute the rectangular intersection of any two rectangles

; If there is no intersection, return a rectangle with 0 area.

(define (rect-intersect rect0 rect1)

'todo)

; Compute the intersection of a list of one or more rectangles

; E.g., the list `((rect 0 0 10 10) (rect 0 -5 10 1) (rect -5 -5 2 5))

; has intersection `(rect 0 0 2 1)

(define (rect-list-intersect rect-list)

'todo)

; Compute a Racket (set) of all sub-rectangles in the given rectangle

; We will call any rectangle r', with integer side-lengths of at least 1, a "sub-rectangle" of r iff r fully contains r'

; E.g., (all-sub-rectangles (rect 0 0 0 0)) => (set)

; E.g., (all-sub-rectangles (rect 0 0 1 1)) => (set `(rect 0 0 1 1))

; E.g., (all--sub-rectangles (rect 10 5 11 7)) => (set `(rect 10 5 11 7) `(rect 10 5 11 6) `(rect 10 6 11 7))

; Hint: can you solve this using the `foldl` and `range` functions?

(define (all-sub-rectangles r)

'todo)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!