Skip to content

Commit 78d2867

Browse files
committed
change polygon and its tests to multi-exports form
1 parent 76926d7 commit 78d2867

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/lib/polygon.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
* don't double-count the edge where they meet.
2626
* returns boolean: is pt inside the polygon (including on its edges)
2727
*/
28-
module.exports = function polygon(ptsIn) {
28+
var polygon = module.exports = {};
29+
30+
polygon.tester = function tester(ptsIn) {
2931
var pts = ptsIn.slice(),
3032
xmin = pts[0][0],
3133
xmax = xmin,
@@ -115,3 +117,5 @@ module.exports = function polygon(ptsIn) {
115117
contains: contains
116118
};
117119
};
120+
121+

test/jasmine/tests/polygon_test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
var polygon = require('@src/lib/polygon');
1+
var polygon = require('@src/lib/polygon'),
2+
polygonTester = polygon.tester;
23

3-
describe('polygon', function() {
4+
describe('polygon.tester', function() {
45
'use strict';
56

67
var squareCW = [[0, 0], [0, 1], [1, 1], [1, 0]],
@@ -51,7 +52,7 @@ describe('polygon', function() {
5152
notInDonut = [[1.5, -0.5], [1.5, 1.5], [1.5, 3.5], [-0.5, 1.5], [3.5, 1.5]];
5253

5354
it('should exclude points outside the bounding box', function() {
54-
var poly = polygon([[1,2], [3,4]]);
55+
var poly = polygonTester([[1,2], [3,4]]);
5556
var pts = [[0, 3], [4, 3], [2, 1], [2, 5]];
5657
pts.forEach(function(pt) {
5758
expect(poly.contains(pt)).toBe(false);
@@ -67,7 +68,7 @@ describe('polygon', function() {
6768
];
6869

6970
polyPts.forEach(function(polyPt) {
70-
var poly = polygon(polyPt),
71+
var poly = polygonTester(polyPt),
7172
xArray = polyPt.map(function(pt) { return pt[0]; }),
7273
yArray = polyPt.map(function(pt) { return pt[1]; });
7374

@@ -89,7 +90,7 @@ describe('polygon', function() {
8990
var np = 6; // number of intermediate points on each edge to test
9091

9192
polyPts.forEach(function(polyPt) {
92-
var poly = polygon(polyPt);
93+
var poly = polygonTester(polyPt);
9394
poly.pts.forEach(function(pt1, i) {
9495
if(!i) return;
9596
var pt0 = poly.pts[i - 1],
@@ -123,16 +124,16 @@ describe('polygon', function() {
123124
});
124125

125126
it('should find only the right interior points', function() {
126-
var zzpoly = polygon(zigzag);
127+
var zzpoly = polygonTester(zigzag);
127128
inZigzag.forEach(function(pt) {
128129
expect(zzpoly.contains(pt)).toBe(true);
129130
});
130131
notInZigzag.forEach(function(pt) {
131132
expect(zzpoly.contains(pt)).toBe(false);
132133
});
133134

134-
var donutpoly = polygon(donut),
135-
donut2poly = polygon(donut2);
135+
var donutpoly = polygonTester(donut),
136+
donut2poly = polygonTester(donut2);
136137
inDonut.forEach(function(pt) {
137138
expect(donutpoly.contains(pt)).toBe(true);
138139
expect(donut2poly.contains(pt)).toBe(true);

0 commit comments

Comments
 (0)