- jdk19 (linux install instructions here.)
- bash/zsh - need to run with
./gradlew
(see the quickstart section of this README for how to run)
For this takehome I decided to create 3 API's in a SpingBoot env. Each API maps to one of the functions that needs to be completed as part of the takehome, ie.:
- this is where the Spring AppConfig lives. I just used this to initialize a bean.
- this is where the API Controller live, it basically just parses API input and hands it off the the rectangle engine.
- this is where the biz logic lives
- LineComparisonEngine is a class that does stuff with 2D Lines (using geometry formulas). The rectangle calculations can be simplified if I split a rectangle into 4 lines (between the points). Because of this, I made the Line2D class & this engine to do stuff with lines.
- RectangleComparisonEngine is where the Rectangle magic happens, it does all the math that is involved for achieving what the takehome asks for.
- this package contains a bunch of custom data types like Rectangle, Line2D, Coordinate2D that are used by the engines. They're basically just data classes / POJO's and if we did have a DB it's not too far from what we'd load our DB record into. I tried to keep these classes very simpel and bare bones so that the engine could do all the work (so if we wanted to extend this to compare variosu shapes, we can just use a diff engine).
Unit tests for the above classes in the same structure but under the test directory. Rectangle and line engine are pretty well tested since that's where the biz logic lives. The rest of classes are mainly happy case tests due to time constraints.
There are no integ / smoke / E2E tests due to time constraints.
- Move to the repository root
cd <path/to/repository/root>
- Start the server
# this will not work if JDK19 is not installed
./gradlew bootRun
- Test that the server is up
curl localhost:8080
# you should see this as a response
> "Greetings from Spring Boot!"
- Move to the repository root
cd <path/to/repository/root>
- Run the unit tests using the gradle wrapper.
./gradlew test
This is the test API, it should always return
"Greetings from Spring Boot!"
An API that determines if two rectangles intersect, if they do it'l return the points of intersection, if they dont - it'l return an empty list.
The Request Body is defined as follows:
type: JSON
body:
Sample Request:
{
"rectangle_1": {
"topLeft": {
"x": 0.0,
"y": 1.0
},
"topRight": {
"x": 3.0,
"y": 1.0
},
"bottomLeft": {
"x": 0.0,
"y": 0.0
},
"bottomRight": {
"x": 3.0,
"y": 0.0
}
},
"rectangle_2": {
"topLeft": {
"x": 1.0,
"y": 0.5
},
"topRight": {
"x": 2.0,
"y": 0.5
},
"bottomLeft": {
"x": 1.0,
"y": -0.5
},
"bottomRight": {
"x": 2.0,
"y": -0.5
}
}
}
type: JSON
body:
- List[coordinate]
- this list may be empty if there is no point of intersection.
Sample Response:
[
{
"x": 1.0,
"y": 0.0
},
{
"x": 2.0,
"y": 0.0
}
]
The Request Body is defined as follows:
type: JSON
body:
Sample Request:
{
"rectangle_1": {
"topLeft": {
"x": 0.0,
"y": 1.0
},
"topRight": {
"x": 3.0,
"y": 1.0
},
"bottomLeft": {
"x": 0.0,
"y": 0.0
},
"bottomRight": {
"x": 3.0,
"y": 0.0
}
},
"rectangle_2": {
"topLeft": {
"x": 1.0,
"y": 0.5
},
"topRight": {
"x": 2.0,
"y": 0.5
},
"bottomLeft": {
"x": 1.0,
"y": -0.5
},
"bottomRight": {
"x": 2.0,
"y": -0.5
}
}
}
type: JSON
body:
- boolean (true if a or b are contained, else false)
Sample Response:
true
The Request Body is defined as follows:
type: JSON
body:
Sample Request:
{
"rectangle_1": {
"topLeft": {
"x": 0.0,
"y": 1.0
},
"topRight": {
"x": 3.0,
"y": 1.0
},
"bottomLeft": {
"x": 0.0,
"y": 0.0
},
"bottomRight": {
"x": 3.0,
"y": 0.0
}
},
"rectangle_2": {
"topLeft": {
"x": 1.0,
"y": 0.5
},
"topRight": {
"x": 2.0,
"y": 0.5
},
"bottomLeft": {
"x": 1.0,
"y": -0.5
},
"bottomRight": {
"x": 2.0,
"y": -0.5
}
}
}
type: JSON
body:
- boolean (true if a or b are contained, else false)
Sample Response:
true
type: JSON body:
- topLeft: coordinate
- topRight: coordinate
- bottomLeft: coordinate
- bottomLeft: coordinate
Example:
{
"topLeft": {
"x": 1.0,
"y": 0.5
},
"topRight": {
"x": 2.0,
"y": 0.5
},
"bottomLeft": {
"x": 1.0,
"y": -0.5
},
"bottomRight": {
"x": 2.0,
"y": -0.5
}
}
type: JSON body:
- x: float
- y: float
Example:
{
"x": 1.1,
"y": 1.2
}