Code Monkey home page Code Monkey logo

polygon-area-scala's Introduction

Build Status Coverage Status

Overview

This project computes the area of a polygon shape, composed of three or more points, or a group of shapes using the Monte Carlo method.

  • algebraic data types and their representation as case classes
  • pattern matching
  • recursive functions
  • relationship with composite, decorator, and visitor patterns
  • test-driven development (TDD) in Scala and Intellij IDEA
  • some simple computational geometry problems
  • Monte Carlo method

The features of this program can be viewed through the implementation of the test suites.

Code references:

Testing

To run the tests:

sbt test

To determine test coverage:

sbt coverage test

Then open this file in a web browser:

target/scala-2.10/scoverage-report/index.html

Additional Comments

As I was coding what I considered one of the most difficult parts, checking if line segments intersect, I found that it was better to pull as many smaller functions and methods as I could out of lineLineIntersect into the lineSegment case. It allowed me to debug and test the code more easily by first running the outer methods and functions that were then used to determine if two line segments intersect.

The behaviors of checking if a point can be found inside a shape, determining the location and rectangle components of a shape's bounding box, and computing the area of a shape are all abstractly implemented as objects and use pattern matching. This abstraction allows for the reuse of the rectangle and polygon cases when applying these behaviors to a group of shapes or shapes transposed to a different location.

At first, I had the pointInsideShape function inside the polygon case class, but when I wanted to use the function on a group of shapes, I realized it there would be a lot of DRY code. I also made the bounding box and area computations abstract because it's easier to modify the behavior as needed for the location and group cases. It also makes it easier to account for overlapping shapes.

polygon-area-scala's People

Contributors

csoulakian avatar klaeufer avatar

Watchers

James Cloos avatar  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.