Implementation of largest-cover difference #23@title Implementation of largest-cover difference def rectangle_difference(r, t): "Computes the rectangle difference rt, and outputs the result as a list of rectangles." assert len(r) == len(t), "Rectangles have different dimensions" ### YOUR SOLUTION HERE In the above code, we notice how it paid off to encapsulate intervals in their own abstraction. Now that we need to reason about rectangles, we do not need to get bogged down into complicated considerations of how to perform difference; the comparisons between endpoints are all done in the context of intervals, where it is easier to reason about them. It is often the case that problems become easy, once you think at them in the appropriate context. It is much easier to develop the code for the difference of intervals, as we have done, and then move on to difference of rectangles, rather than trying to write code for rectangle difference directly. The result is also far more elegant. # Let us test visually what happens. r = Rectangle((0., 4.), (0., 4.), name="R") t = Rectangle((2., 6.), (2., 6.), name="T") d = rectangle_difference (r, t) draw rectangles (r, t) draw rectangles (*d) [ ] # Whooho!! Let's try with another example. Now T is inside R. r = Rectangle((0., 4.), (0., 4.), name="R") t = Rectangle((1.5, 3.5), (1., 3.), name="T") d = rectangle_difference (r, t) draw rectangles (r, t) draw rectangles (*d)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Implementation of largest-cover difference
#23@title Implementation of largest-cover difference
def rectangle_difference(r, t):
"Computes the rectangle difference rt, and outputs the result
as a list of rectangles."
assert len(r) == len(t), "Rectangles have different dimensions"
### YOUR SOLUTION HERE
In the above code, we notice how it paid off to encapsulate intervals in their own abstraction. Now that we need to reason about rectangles, we
do not need to get bogged down into complicated considerations of how to perform difference; the comparisons between endpoints are all
done in the context of intervals, where it is easier to reason about them. It is often the case that problems become easy, once you think at them
in the appropriate context. It is much easier to develop the code for the difference of intervals, as we have done, and then move on to difference
of rectangles, rather than trying to write code for rectangle difference directly. The result is also far more elegant.
# Let us test visually what happens.
r = Rectangle((0., 4.), (0., 4.), name="R")
t = Rectangle((2., 6.), (2., 6.), name="T")
d = rectangle_difference (r, t)
draw rectangles (r, t)
draw rectangles (*d)
[ ] # Whooho!! Let's try with another example. Now T is inside R.
r = Rectangle((0., 4.), (0., 4.), name="R")
t = Rectangle((1.5, 3.5), (1., 3.), name="T")
d = rectangle_difference (r, t)
draw rectangles (r, t)
draw rectangles (*d)
Transcribed Image Text:Implementation of largest-cover difference #23@title Implementation of largest-cover difference def rectangle_difference(r, t): "Computes the rectangle difference rt, and outputs the result as a list of rectangles." assert len(r) == len(t), "Rectangles have different dimensions" ### YOUR SOLUTION HERE In the above code, we notice how it paid off to encapsulate intervals in their own abstraction. Now that we need to reason about rectangles, we do not need to get bogged down into complicated considerations of how to perform difference; the comparisons between endpoints are all done in the context of intervals, where it is easier to reason about them. It is often the case that problems become easy, once you think at them in the appropriate context. It is much easier to develop the code for the difference of intervals, as we have done, and then move on to difference of rectangles, rather than trying to write code for rectangle difference directly. The result is also far more elegant. # Let us test visually what happens. r = Rectangle((0., 4.), (0., 4.), name="R") t = Rectangle((2., 6.), (2., 6.), name="T") d = rectangle_difference (r, t) draw rectangles (r, t) draw rectangles (*d) [ ] # Whooho!! Let's try with another example. Now T is inside R. r = Rectangle((0., 4.), (0., 4.), name="R") t = Rectangle((1.5, 3.5), (1., 3.), name="T") d = rectangle_difference (r, t) draw rectangles (r, t) draw rectangles (*d)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education