cij11 / merge-polygon-geometry

Solution to merge polygon exercise

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Usage

Install the exercise by running npm install from the directory containing package.json.
Run unit tests by running npm test from the directory containing package.json.

Overview

Implement an alogrthim that merges a pair of input polygons.

Excersise

Provide an implemention for the mergePolygons() function.

Please avoid the use of existing polygon manipulation/merging libraries such as this one when completing this excersise.

Your mergePolygons() function should:

  • return a single polygon representing the merge result of input polygons
  • should be a generalised, capable of merging input polygons with arbitrary geometry
  • return undefined if invalid input arguments provided
  • return undefined if no overlap detected between input polygons
  • return undefined if either polygon is fully contained by the other

A polygon is defined as a collection of half-edge data structures, linked together to define the polygons boundary:

polygon

When input polygons overlap, mergePolygons() should correctly detect and process intersections between respective half-edges as they occour. When merged polygon returned by mergePolygons() should be encoded as a colllection of half-edges, as shown above. The expected merging behaviour is illustrated as:

merge

Assume that input polygons are simple polygons. Verify your solution by extending the test suite: test/merge-polygons.spec.js

Bonus points

  • Check the validity of input polygons before performing the merge operation (are invariants satisfied? do input polygons form closed loops? are half-edge pairs defined? etc)
  • If either input polygon is detected to be a complex polygon the function returns undefined

About

Solution to merge polygon exercise


Languages

Language:JavaScript 100.0%