-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for polygonArea to return signed areas
- Loading branch information
1 parent
ab99d27
commit 0a1d2ff
Showing
6 changed files
with
76 additions
and
67 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 was deleted.
Oops, something went wrong.
Binary file not shown.
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,12 +1,21 @@ | ||
var tape = require("tape"), | ||
const tape = require("tape"), | ||
geometric = require("../"); | ||
|
||
tape("polygonArea(polygon) calculates the area of a polygon", function(test) { | ||
tape("polygonArea(polygon) calculates the area of a polygon", test => { | ||
test.equal(geometric.polygonArea([[0, 0], [1, 0], [1, 1], [0, 1]]), 1); | ||
test.equal(geometric.polygonArea([[0, 0], [2, 0], [2, 2], [0, 2]]), 4); | ||
test.equal(geometric.polygonArea([[0, 0], [3, 0], [3, 3], [0, 3]]), 9); | ||
test.equal(geometric.polygonArea([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]), 1); | ||
test.equal(geometric.polygonArea([[0, 0], [2, 0], [2, 2], [0, 2], [0, 0]]), 4); | ||
test.equal(geometric.polygonArea([[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]), 9); | ||
test.end(); | ||
}); | ||
}); | ||
|
||
tape("If the polygon's winding order is counter-clockwise and signed is set to true, returns a negative area", test => { | ||
const p = [[119, 87], [61, 150], [131, 197], [206, 135]]; | ||
test.equal(geometric.polygonArea(p, true), -8065); | ||
test.equal(geometric.polygonArea(p, false), 8065); | ||
test.equal(geometric.polygonArea(p), 8065); | ||
test.end(); | ||
}); | ||
|