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
rustlings
in 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
exercises
folder) and the submit script torlogin
and 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-coordinate
increases from left to right. -
The
y-coordinate
increases from top to bottom.
-
The
-
A
Circle
can be created from itscenter
andradius
. -
A
Rectangle
can be created from-
the top-left corner (the corner of the rectangle with the smallest
x
andy
coordinate), a width (in the positivex
direction), and a height (in the positivey
direction) -
any two diagonally opposing corners
-
-
A
Rectangle
should provide the following information:-
x_min
: the smallestx-coordinate
located within the rectangle (or thex-coordinate
of the left edge of the rectangle) -
x_max
: the largestx-coordinate
located within the rectangle (or thex-coordinate
of the right edge of the rectangle) -
y_min
: the smallesty-coordinate
located within the rectangle (or they-coordinate
of the top edge of the rectangle) -
y_max
: the largesty-coordinate
located within the rectangle (or they-coordinate
of 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: