Skip to content

Commit dccda7a

Browse files
committed
PlaceOnRectangle now uses MarchingAnts and has a new shift argument.
1 parent 081b281 commit dccda7a

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

v3/src/actions/PlaceOnRectangle.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
var PerimeterPoint = require('../geom/rectangle/PerimeterPoint');
1+
var MarchingAnts = require('../geom/rectangle/MarchingAnts');
2+
var RotateLeft = require('../utils/array/RotateLeft');
3+
var RotateRight = require('../utils/array/RotateRight');
24

3-
var PlaceOnRectangle = function (items, rect)
5+
// Place the items in the array around the perimeter of the given rectangle.
6+
7+
// Placement starts from the top-left of the rectangle, and proceeds in a
8+
// clockwise direction. If the shift parameter is given you can offset where
9+
// placement begins.
10+
11+
var PlaceOnRectangle = function (items, rect, shift)
412
{
5-
var angle = 0;
6-
var step = 360 / items.length;
13+
if (shift === undefined) { shift = 0; }
714

8-
for (var i = 0; i < items.length; i++)
15+
var points = MarchingAnts(rect, false, items.length);
16+
17+
if (shift > 0)
918
{
10-
PerimeterPoint(rect, angle, items[i]);
19+
RotateLeft(points, shift);
20+
}
21+
else if (shift < 0)
22+
{
23+
RotateRight(points, Math.abs(shift));
24+
}
1125

12-
angle += step;
26+
for (var i = 0; i < items.length; i++)
27+
{
28+
items[i].x = points[i].x;
29+
items[i].y = points[i].y;
1330
}
1431

1532
return items;

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: '2bdd4310-14b0-11e7-829e-c915fb3f8068'
2+
build: '237de9e0-14b5-11e7-9970-cb460f4880e6'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/layer/Layer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ var Layer = new Class({
231231
return this;
232232
},
233233

234-
placeOnRectangle: function (rect)
234+
placeOnRectangle: function (rect, shift)
235235
{
236-
Actions.PlaceOnRectangle(this.children.entries, rect);
236+
Actions.PlaceOnRectangle(this.children.entries, rect, shift);
237237

238238
return this;
239239
},

0 commit comments

Comments
 (0)