var Vector2 = require('../math/Vector2'); var ShiftPosition = function (items, x, y, direction, output){ if (direction === undefined) { direction = 0; } if (output === undefined) { output = new Vector2(); } var px; var py; if (_AN_Read_length('length', items) > 1) { var i; var cx; var cy; var cur; if (direction === 0) { var len = _AN_Read_length('length', items) - 1; px = items[len].x; py = items[len].y; for (i = len - 1; i >= 0; i-- ){ cur = items[i]; cx = cur.x; cy = cur.y; cur.x = px; cur.y = py; px = cx; py = cy; } items[len].x = x; items[len].y = y; } else { px = items[0].x; py = items[0].y; for (i = 1; i < _AN_Read_length('length', items); i++ ){ cur = items[i]; cx = cur.x; cy = cur.y; cur.x = px; cur.y = py; px = cx; py = cy; } items[0].x = x; items[0].y = y; } } else { px = items[0].x; py = items[0].y; items[0].x = x; items[0].y = y; } output.x = px; output.y = py; return output; } ; module.exports = ShiftPosition;