Skip to content

lequant40/graham_scan_js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

| French version

JavaScript Graham's Scan Convex Hull Algorithm

For usage on my blog Le Quant 40 together with the Highcharts graphical library, I required a Javascript implementation of a fast algorithm to calculate a convex hull from a set of points in x,y coordinates (Graham's Scan then).

I found what I needed on brian3kb's Github, although this implementation lacked the capability of managing points with labels, which I added.

Download

The minified source code, for immediate usage in a browser, is available here.

Building and testing

The following commands produce the minified file graham_scan.min.js and launch the unit tests with QUnit:

npm install
grunt deliver

The QUnit unit tests are located in the file tests/index.html.

Usage

Straightforward:

// Create a new instance.
var aConvexHull = new ConvexHullGrahamScan();

// Points addition, one by one, with an optional label
aConvexHull.addPoint(1.5, 3.1);
aConvexHull.addPoint(1.6, 3.2, 'my label');

// Computation of the convex hull
// The returned array is in JSON format: [{x: x coordinate, y: y coordinate, name: point label }, ...]
var hullPoints = convexHull.getHull();

References

License

MIT License

About

Javascript implementation of Graham's Scan Convex Hull algorithm.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.9%
  • HTML 3.1%