-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export symbols with “polygon” prefix.
- Loading branch information
Showing
12 changed files
with
106 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export {default as area} from "./src/area"; | ||
export {default as centroid} from "./src/centroid"; | ||
export {default as hull} from "./src/hull"; | ||
export {default as inside} from "./src/inside"; | ||
export {default as perimeter} from "./src/perimeter"; | ||
export {default as polygonArea} from "./src/area"; | ||
export {default as polygonCentroid} from "./src/centroid"; | ||
export {default as polygonHull} from "./src/hull"; | ||
export {default as polygonContains} from "./src/contains"; | ||
export {default as polygonLength} from "./src/length"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var tape = require("tape"), | ||
polygon = require("../"); | ||
|
||
tape("polygonContains(polygon, point) returns the expected value for closed counterclockwise polygons", function(test) { | ||
test.equal(polygon.polygonContains([[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [0.5, 0.5]), true); | ||
test.equal(polygon.polygonContains([[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [1.5, 0.5]), false); | ||
test.equal(polygon.polygonContains([[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [-0.5, 0.5]), false); | ||
test.equal(polygon.polygonContains([[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [0.5, 1.5]), false); | ||
test.equal(polygon.polygonContains([[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]], [0.5, -0.5]), false); | ||
test.end(); | ||
}); | ||
|
||
tape("polygonContains(polygon, point) returns the expected value for closed clockwise polygons", function(test) { | ||
test.equal(polygon.polygonContains([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]], [0.5, 0.5]), true); | ||
test.equal(polygon.polygonContains([[1, 1], [3, 2], [2, 3], [1, 1]], [1.5, 1.5]), true); | ||
test.end(); | ||
}); | ||
|
||
tape("polygonContains(polygon, point) returns the expected value for open counterclockwise polygons", function(test) { | ||
test.equal(polygon.polygonContains([[0, 0], [0, 1], [1, 1], [1, 0]], [0.5, 0.5]), true); | ||
test.end(); | ||
}); | ||
|
||
tape("polygonContains(polygon, point) returns the expected value for open clockwise polygons", function(test) { | ||
test.equal(polygon.polygonContains([[0, 0], [1, 0], [1, 1], [0, 1]], [0.5, 0.5]), true); | ||
test.equal(polygon.polygonContains([[1, 1], [3, 2], [2, 3]], [1.5, 1.5]), true); | ||
test.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
var tape = require("tape"), | ||
polygon = require("../"); | ||
|
||
tape("hull(points) returns null if points has fewer than three elements", function(test) { | ||
test.equal(polygon.hull([]), null); | ||
test.equal(polygon.hull([[0, 1]]), null); | ||
test.equal(polygon.hull([[0, 1], [1, 0]]), null); | ||
tape("polygonHull(points) returns null if points has fewer than three elements", function(test) { | ||
test.equal(polygon.polygonHull([]), null); | ||
test.equal(polygon.polygonHull([[0, 1]]), null); | ||
test.equal(polygon.polygonHull([[0, 1], [1, 0]]), null); | ||
test.end(); | ||
}); | ||
|
||
tape("hull(points) returns the convex hull of the specified points", function(test) { | ||
test.deepEqual(polygon.hull([[200, 200], [760, 300], [500, 500]]), [[760, 300], [200, 200], [500, 500]]); | ||
test.deepEqual(polygon.hull([[200, 200], [760, 300], [500, 500], [400, 400]]), [[760, 300], [200, 200], [500, 500]]); | ||
tape("polygonHull(points) returns the convex hull of the specified points", function(test) { | ||
test.deepEqual(polygon.polygonHull([[200, 200], [760, 300], [500, 500]]), [[760, 300], [200, 200], [500, 500]]); | ||
test.deepEqual(polygon.polygonHull([[200, 200], [760, 300], [500, 500], [400, 400]]), [[760, 300], [200, 200], [500, 500]]); | ||
test.end(); | ||
}); | ||
|
||
tape("hull(points) handles points with duplicate ordinates", function(test) { | ||
test.deepEqual(polygon.hull([[-10, -10], [10, 10], [10, -10], [-10, 10]]), [[10, 10], [10, -10], [-10, -10], [-10, 10]]); | ||
tape("polygonHull(points) handles points with duplicate ordinates", function(test) { | ||
test.deepEqual(polygon.polygonHull([[-10, -10], [10, 10], [10, -10], [-10, 10]]), [[10, 10], [10, -10], [-10, -10], [-10, 10]]); | ||
test.end(); | ||
}); | ||
|
||
tape("hull(points) handles overlapping upper and lower hulls", function(test) { | ||
test.deepEqual(polygon.hull([[0, -10], [0, 10], [0, 0], [10, 0], [-10, 0]]), [[10, 0], [0, -10], [-10, 0], [0, 10]]); | ||
tape("polygonHull(points) handles overlapping upper and lower hulls", function(test) { | ||
test.deepEqual(polygon.polygonHull([[0, -10], [0, 10], [0, 0], [10, 0], [-10, 0]]), [[10, 0], [0, -10], [-10, 0], [0, 10]]); | ||
test.end(); | ||
}); | ||
|
||
// Cases below taken from http://uva.onlinejudge.org/external/6/681.html | ||
tape("hull(points) handles various non-trivial hulls", function(test) { | ||
test.deepEqual(polygon.hull([[60, 20], [250, 140], [180, 170], [79, 140], [50, 60], [60, 20]]), [[250, 140], [60, 20], [50, 60], [79, 140], [180, 170]]); | ||
test.deepEqual(polygon.hull([[50, 60], [60, 20], [70, 45], [100, 70], [125, 90], [200, 113], [250, 140], [180, 170], [105, 140], [79, 140], [60, 85], [50, 60]]), [[250, 140], [60, 20], [50, 60], [79, 140], [180, 170]]); | ||
test.deepEqual(polygon.hull([[30, 30], [50, 60], [60, 20], [70, 45], [86, 39], [112, 60], [200, 113], [250, 50], [300, 200], [130, 240], [76, 150], [47, 76], [36, 40], [33, 35], [30, 30]]), [[300, 200], [250, 50], [60, 20], [30, 30], [47, 76], [76, 150], [130, 240]]); | ||
tape("polygonHull(points) handles various non-trivial hulls", function(test) { | ||
test.deepEqual(polygon.polygonHull([[60, 20], [250, 140], [180, 170], [79, 140], [50, 60], [60, 20]]), [[250, 140], [60, 20], [50, 60], [79, 140], [180, 170]]); | ||
test.deepEqual(polygon.polygonHull([[50, 60], [60, 20], [70, 45], [100, 70], [125, 90], [200, 113], [250, 140], [180, 170], [105, 140], [79, 140], [60, 85], [50, 60]]), [[250, 140], [60, 20], [50, 60], [79, 140], [180, 170]]); | ||
test.deepEqual(polygon.polygonHull([[30, 30], [50, 60], [60, 20], [70, 45], [86, 39], [112, 60], [200, 113], [250, 50], [300, 200], [130, 240], [76, 150], [47, 76], [36, 40], [33, 35], [30, 30]]), [[300, 200], [250, 50], [60, 20], [30, 30], [47, 76], [76, 150], [130, 240]]); | ||
test.end(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var tape = require("tape"), | ||
polygon = require("../"); | ||
|
||
tape("polygonLength(polygon) returns the expected value for closed counterclockwise polygons", function(test) { | ||
test.equal(polygon.polygonLength([[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]), 4); | ||
test.end(); | ||
}); | ||
|
||
tape("polygonLength(polygon) returns the expected value for closed clockwise polygons", function(test) { | ||
test.equal(polygon.polygonLength([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]), 4); | ||
test.equal(polygon.polygonLength([[1, 1], [3, 2], [2, 3], [1, 1]]), Math.sqrt(20) + Math.sqrt(2)); | ||
test.end(); | ||
}); | ||
|
||
tape("polygonLength(polygon) returns the expected value for open counterclockwise polygons", function(test) { | ||
test.equal(polygon.polygonLength([[0, 0], [0, 1], [1, 1], [1, 0]]), 4); | ||
test.end(); | ||
}); | ||
|
||
tape("polygonLength(polygon) returns the expected value for open clockwise polygons", function(test) { | ||
test.equal(polygon.polygonLength([[0, 0], [1, 0], [1, 1], [0, 1]]), 4); | ||
test.equal(polygon.polygonLength([[1, 1], [3, 2], [2, 3]]), Math.sqrt(20) + Math.sqrt(2)); | ||
test.end(); | ||
}); |
This file was deleted.
Oops, something went wrong.