Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Explain the Neolithic age compared to the paleolithic age ?

Answered: 1 week ago

Question

What is loss of bone density and strength as ?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago