Giter Site home page Giter Site logo

nuvalence's Introduction

Reference Documentation

Requirements

  • jdk19 (linux install instructions here.)
  • bash/zsh - need to run with ./gradlew (see the quickstart section of this README for how to run)

Description

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.:

Code Structure

src

config
  • this is where the Spring AppConfig lives. I just used this to initialize a bean.
controller
  • this is where the API Controller live, it basically just parses API input and hands it off the the rectangle engine.
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.

Types

  • 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).

src/test

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.

QuickStart

  1. Move to the repository root
cd <path/to/repository/root>
  1. Start the server
# this will not work if JDK19 is not installed
./gradlew bootRun
  1. Test that the server is up
curl localhost:8080
# you should see this as a response
> "Greetings from Spring Boot!"

Running Unit Tests

  1. Move to the repository root
cd <path/to/repository/root>
  1. Run the unit tests using the gradle wrapper.
./gradlew test

API

Endpoints

GET /

This is the test API, it should always return

"Greetings from Spring Boot!"

POST /api/rectangles/intersects

Description

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.

Request Body

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
        }
    }
}

ResponseBody

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
    }
]

POST /api/rectangles/contains

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
        }
    }
}

ResponseBody

type: JSON
body:

  • boolean (true if a or b are contained, else false)

Sample Response:

true

POST /api/rectangles/isAdjacent

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
        }
    }
}

ResponseBody

type: JSON
body:

  • boolean (true if a or b are contained, else false)

Sample Response:

true

Types

Rectangle

type: JSON body:

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
  }
}

Coordinate

type: JSON body:

  • x: float
  • y: float

Example:

{
  "x": 1.1,
  "y": 1.2
}

nuvalence's People

Contributors

persa188 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.