Exercise 1
Note: This exercise is new! If there are any ambiguities in the specification or given materials, please don’t hesitate to ask for clarification either on the Discourse forum, via an email to Kieran, or during office hours.
Complete the exercise using rustlings, a framework for completing small Rust exercises.
- Install rustlings using the official installation instructions.
- Clone the exercise repository.
-
Run
rustlingsin the cloned repository directory.
The assignment is comprised of 8 mini-exercises and 1 medium exercise. Complete the exercises by either making each exercise compile or by passing the tests included in the exercise.
Note: You are not allowed to modify any tests in the provided tests section.
Submission
Submission deadline: 11:59 pm, Sunday, September 15 2024.
Submission method: Run the included submit.py script in your root exercise repository.
You will need Python and Requests installed. If you do not have Python and/or Requests, you can either:
- Install Python and/or Requests
-
Copy your assignment solution (the
exercisesfolder) and the submit script torloginand run the submit script there# Example: $ scp -r exercises/ submit.py \ <VT_USERNAME_HERE>@rlogin.cs.vt.edu:cs3984-exercise-1
Part 1
The 8 mini-exercises (00_intro to 08_enums) are taken from the official rustlings exercise set.
Part 2
The medium exercise (99_shapes) requires incrementally implementing a Shape type, which provides a method to detect if two shapes are overlapping.
The two shapes to implement are a Circle and a Rectangle.
Each successive exercise
file in 99_shapes builds upon the data structures implemented in the previous exercise file.
Complete the exercise by passing the tests provided in each exercise file. Study the tests to determine what fields and methods to implement, as well as the expected behavior of the method calls.
For q3_overlap, the algorithms to use for each method are given below in the formulas section.
Details
-
The shapes live in an infinite grid with the following coordinate system:
-
The
x-coordinateincreases from left to right. -
The
y-coordinateincreases from top to bottom.
-
The
-
A
Circlecan be created from itscenterandradius. -
A
Rectanglecan be created from-
the top-left corner (the corner of the rectangle with the smallest
xandycoordinate), a width (in the positivexdirection), and a height (in the positiveydirection) -
any two diagonally opposing corners
-
-
A
Rectangleshould provide the following information:-
x_min: the smallestx-coordinatelocated within the rectangle (or thex-coordinateof the left edge of the rectangle) -
x_max: the largestx-coordinatelocated within the rectangle (or thex-coordinateof the right edge of the rectangle) -
y_min: the smallesty-coordinatelocated within the rectangle (or they-coordinateof the top edge of the rectangle) -
y_max: the largesty-coordinatelocated within the rectangle (or they-coordinateof the bottom edge of the rectangle)
-
Formulas
Circle-circle intersection formula for circles and :
Rectangle-rectangle intersection formula for rectangles and :
Circle-rectangle intersection formula for circle and rectangle :
Note: