Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSE 341 HW 7 puble dispatch and a separate use of dynamic dispatch for the line-segment case. Remember all the fferent cases in OCaml will

image text in transcribed
CSE 341 HW 7
puble dispatch and a separate use of dynamic dispatch for the line-segment case. Remember all the fferent cases in OCaml will appear in the Racket OOP solution, just arranged very differently. - Implement preprocess-prog and eval-prog in the intersect\% class. This is not difficult, much like your prior work in the shift\% class is not difficult. This is because every subclass of geometry-value\% will have an intersect method that "knows how to intersect itself" with another geometry-value passed as an argument. - Every subclass of geometry-value\% needs an intersect method, but these will be short. The argument is another geometry-value, but we do not know what kind. So we use double dispatch and call the appropriate method on the argument passing this to the method. For example, the point\% class has an intersect method that calls intersect-point with this. - So methods intersect-no-points, intersect-point, intersect-line, intersect-vertical-line. and intersect-1ine-segment defined in each of our 5 subclasses of geometry-value\% handle the 25 possible intersection combinations: - The 9 cases involving no-points\% are done for you. See the geometry-value\% class - there is nothing more you need to do. - Next do the 9 remaining cases involving combinations that do not involve line segments. You will need to understand double-dispatch to avoid is-a?. As in the OCaml code, 3 of these 9 cases can just use one of the other cases because intersection is commutative. - What remains are the 7 cases where one value is a line-segment\% and the other is not a no-points\%. These cases are all "done" for you because all subclasses of geometry-value\% inherit an intersect-line-segment method that will be correct for all of them. But it calls intersect-with-segment-as-line-result, which you need to implement for each subclass of geometry-value\%. Here is how this method should work: * It takes one argument, which is a line segment. (In OCaml the corresponding variable was a float*float*float*float, but here it will actually be an instance of line-segment\% and you can use the getter methods get-x1, get-y1, get-x2, and get-y2 as needed.) * It assumes that this is the intersection of (1) some not-provided geometry-value and (2) the line (vertical or not) containing the segment given as an argument. * It returns the intersection of the not-provided geometry-value and the segment given as an argument. Together the 5 intersect-with-segment-as-line-result methods you write will implement the same algorithm as on lines 79130 of the OCaml code

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

3. Give examples of four fair disciplinary practices.

Answered: 1 week ago