Skip to content

Commit 081b281

Browse files
committed
Added option to have step or quantity in MarchingAnts method.
1 parent 8664c27 commit 081b281

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '11a89730-149a-11e7-a3c1-4b9b632763c1'
2+
build: '2bdd4310-14b0-11e7-829e-c915fb3f8068'
33
};
44
module.exports = CHECKSUM;

v3/src/geom/rectangle/MarchingAnts.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
var Perimeter = require('./Perimeter');
22

33
// Return an array of points from the perimeter of the rectangle
4-
// each spaced out based on the quantity required
4+
// each spaced out based on the quantity or step required
55

6-
// Add option to set a starting offset?
7-
8-
var MarchingAnts = function (rect, quantity, out)
6+
var MarchingAnts = function (rect, step, quantity, out)
97
{
108
if (out === undefined) { out = []; }
119

12-
var step = Perimeter(rect) / quantity;
10+
if (!step && !quantity)
11+
{
12+
// Bail out
13+
return out;
14+
}
15+
16+
// If step is a falsey value (false, null, 0, undefined, etc) then we calculate
17+
// it based on the quantity instead, otherwise we always use the step value
18+
if (!step)
19+
{
20+
step = Perimeter(rect) / quantity;
21+
}
22+
else
23+
{
24+
quantity = Math.round(Perimeter(rect) / step);
25+
}
1326

1427
var x = rect.x;
1528
var y = rect.y;

0 commit comments

Comments
 (0)