diff --git a/dist/boid.js b/dist/boid.js index 213fecb..0bb49a6 100644 --- a/dist/boid.js +++ b/dist/boid.js @@ -86,15 +86,18 @@ function Boid(options) { }; var bounce = function() { - if (position.x > bounds.width) { - position.x = bounds.width; + var maxX = bounds.x + bounds.width; + if (position.x > maxX) { + position.x = maxX; velocity.x *= -1; } else if (position.x < bounds.x) { position.x = bounds.x; velocity.x *= -1; } - if (position.y > bounds.height) { - position.y = bounds.height; + + var maxY = bounds.y + bounds.height; + if (position.y > maxY) { + position.y = maxY; velocity.y *= -1; } else if (position.y < bounds.y) { position.y = bounds.y; @@ -103,15 +106,18 @@ function Boid(options) { }; var wrap = function() { - if (position.x > bounds.width) { + var maxX = bounds.x + bounds.width; + if (position.x > maxX) { position.x = bounds.x; } else if (position.x < bounds.x) { - position.x = bounds.width; + position.x = maxX; } - if (position.y > bounds.height) { + + var maxY = bounds.y + bounds.height; + if (position.y > maxY) { position.y = bounds.y; } else if (position.y < bounds.y) { - position.y = bounds.height; + position.y = maxY; } }; @@ -330,6 +336,7 @@ function Boid(options) { // methods var boid = { + bounds: bounds, setBounds: setBounds, update: update, pursue: pursue, @@ -690,5 +697,4 @@ if (typeof module === 'object' && module.exports) { } },{}]},{},[1])(1) -}); -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYm9pZC5qcyIsInNyYy92ZWMyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FDQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ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m4gYm9pZDtcbiAgICB9O1xuXG4gICAgdmFyIGJvdW5jZSA9IGZ1bmN0aW9uKCkge1xuICAgICAgICBpZiAocG9zaXRpb24ueCA+IGJvdW5kcy53aWR0aCkge1xuICAgICAgICAgICAgcG9zaXRpb24ueCA9IGJvdW5kcy53aWR0aDtcbiAgICAgICAgICAgIHZlbG9jaXR5LnggKj0gLTE7XG4gICAgICAgIH0gZWxzZSBpZiAocG9zaXRpb24ueCA8IGJvdW5kcy54KSB7XG4gICAgICAgICAgICBwb3NpdGlvbi54ID0gYm91bmRzLng7XG4gICAgICAgICAgICB2ZWxvY2l0eS54ICo9IC0xO1xuICAgICAgICB9XG4gICAgICAgIGlmIChwb3NpdGlvbi55ID4gYm91bmRzLmhlaWdodCkge1xuICAgICAgICAgICAgcG9zaXRpb24ueSA9IGJvdW5kcy5oZWlnaHQ7XG4gICAgICAgICAgICB2ZWxvY2l0eS55ICo9IC0xO1xuICAgICAgICB9IGVsc2UgaWYgKHBvc2l0aW9uLnkgPCBib3VuZHMueSkge1xuICAgICAgICAgICAgcG9zaXRpb24ueSA9IGJvdW5kcy55O1xuICAgICAgICAgICAgdmVsb2NpdHkueSAqPSAtMTtcbiAgICAgICAgfVxuICAgIH07XG5cbiAgICB2YXIgd3JhcCA9IGZ1bmN0aW9uKCkge1xuICAgICAgICBpZiAocG9zaXRpb24ueCA+IGJvdW5kcy53aWR0aCkge1xuICAgICAgICAgICAgcG9zaXRpb24ueCA9IGJvdW5kcy54O1xuICAgICAgICB9IGVsc2UgaWYgKHBvc2l0aW9uLnggPCBib3VuZHMueCkge1xuICAgICAgICAgICAgcG9zaXRpb24ueCA9IGJvdW5kcy53aWR0aDtcbiAgICAgICAgfVxuICAgICAgICBpZiAocG9zaXRpb24ueSA+IGJvdW5kcy5oZWlnaHQpIHtcbiAgICAgICAgICAgIHBvc2l0aW9uLnkgPSBib3VuZHMueTtcbiAgICAgICAgfSBlbHNlIGlmIChwb3NpdGlvbi55IDwgYm91bmRzLnk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pZiAoZGlzdGFuY2UgPCAob2JzdGFjbGUucmFkaXVzIHx8IDApICsgYXZvaWRCdWZmZXIgJiYgcHJvamVjdGlvbi5sZW5ndGggPCBmZWVsZXIubGVuZ3RoKSB7XG4gICAgICAgICAgICAgICAgICAgIC8vIGNhbGMgYSBmb3JjZSArLy0gOTAgZGVnIGZyb20gdmVjIHRvIGNpcmNcbiAgICAgICAgICAgICAgICAgICAgdmFyIGZvcmNlID0gaGVhZGluZy5jbG9uZSgpLnNjYWxlQnkobWF4U3BlZWQpO1xuICAgICAgICAgICAgICAgICAgICBmb3JjZS5hbmdsZSArPSBkaWZmZXJlbmNlLnNpZ24odmVsb2NpdHkpICogTWF0aC5QSSAvIDI7XG4gICAgICAgICAgICAgICAgICAgIC8vIHNjYWxlIGZvcmNlIGJ5IGRpc3RhbmNlIChmdXJ0aGVyID0gc21hbGxlciBmb3JjZSlcbiAgICAgICAgICAgICAgICAgICAgZm9yY2Uuc2NhbGVCeSgxIC0gcHJvamVjdGlvbi5sZW5ndGggLyBmZWVsZXIubGVuZ3RoKTtcbiAgICAgICAgICAgICAgICAgICAgLy8gYWRkIHRvIHN0ZWVyaW5nIGZvcmNlXG4gICAgICAgICAgICAgICAgICAgIHN0ZWVyaW5nRm9yY2UuYWRkKGZvcmNlKTtcbiAgICAgICAgICAgICAgICAgICAgLy8gYnJha2luZyBmb3JjZSAtIHNsb3dzIGJvaWQgZG93biBzbyBpdCBoYXMgdGltZSB0byB0dXJuIChjbG9zZXIgPSBoYXJkZXIpXG4gICAgICAgICAgICAgICAgICAgIHZlbG9jaXR5LnNjYWxlQnkocHJvamVjdGlvbi5sZW5ndGggLyBmZWVsZXIubGVuZ3RoKTtcblxuICAgICAgICAgICAgICAgICAgICBmb3JjZS5kaXNwb3NlKCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIGZlZWxlci5kaXNwb3NlKCk7XG4gICAgICAgICAgICAgICAgcHJvamVjdGlvbi5kaXNwb3NlKCk7XG4gICAgICAgICAgICAgICAgdmVjRGlzdGFuY2UuZGlzcG9zZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaGVhZGluZy5kaXNwb3NlKCk7XG4gICAgICAgICAgICBkaWZmZXJlbmNlLmRpc3Bvc2UoKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gYm9pZDtcbiAgICB9O1xuXG4gICAgLy8gZm9sbG93IGEgcGF0aCBtYWRlIHVwIG9mIGFuIGFycmF5IG9yIHZlY3RvcnNcbiAgICB2YXIgZm9sbG93UGF0aCA9IGZ1bmN0aW9uKHBhdGgsIGxvb3ApIHtcbiAgICAgICAgbG9vcCA9ICEhbG9vcDtcblxuICAgICAgICB2YXIgd2F5UG9pbnQgPSBwYXRoW3BhdGhJbmRleF07XG4gICAgICAgIGlmICghd2F5UG9pbnQpIHtcbiAgICAgICAgICAgIHBhdGhJbmRleCA9IDA7XG4gICAgICAgICAgICByZXR1cm4gYm9pZDtcbiAgICAgICAgfVxuICAgICAgICBpZiAocG9zaXRpb24uZGlzdGFuY2VTcSh3YXlQb2ludCkgPCBwYXRoVGhyZXNob2xkU3EpIHtcbiAgICAgICAgICAgIGlmIChwYXRoSW5kZXggPj0gcGF0aC5sZW5ndGggLSAxKSB7XG4gICAgICAgICAgICAgICAgaWYgKGxvb3ApIHtcbiAgICAgICAgICAgICAgICAgICAgcGF0aEluZGV4ID0gMDtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHBhdGhJbmRleCsrO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICAgIGlmIChwYXRoSW5kZXggPj0gcGF0aC5sZW5ndGggLSAxICYmICFsb29wKSB7XG4gICAgICAgICAgICBhcnJpdmUod2F5UG9pbnQpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgc2Vlayh3YXlQb2ludCk7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIGJvaWQ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gICAgICBzZXRCb3VuZHM6IHNldEJvdW5kcyxcbiAgICAgICAgdXBkYXRlOiB1cGRhdGUsXG4gICAgICAgIHB1cnN1ZTogcHVyc3VlLFxuICAgICAgICBldmFkZTogZXZhZGUsXG4gICAgICAgIHdhbmRlcjogd2FuZGVyLFxuICAgICAgICBhdm9pZDogYXZvaWQsXG4gICAgICAgIGZvbGxvd1BhdGg6IGZvbGxvd1BhdGgsXG4gICAgICAgIGZsb2NrOiBmbG9jayxcbiAgICAgICAgYXJyaXZlOiBhcnJpdmUsXG4gICAgICAgIHNlZWs6IHNlZWssXG4gICAgICAgIGZsZWU6IGZsZWUsXG4gICAgICAgIHBvc2l0aW9uOiBwb3NpdGlvbixcbiAgICAgICAgdmVsb2NpdHk6IHZlbG9jaXR5LFxuICAgICAgICB1c2VyRGF0YToge31cbiAgICB9O1xuXG4gICAgLy8gZ2V0dGVycyAvIHNldHRlcnNcbiAgICBPYmplY3QuZGVmaW5lUHJvcGVydGllcyhib2lkLCB7XG4gICAgICAgIGVkZ2VCZWhhdmlvcjoge1xuICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gZWRnZUJlaGF2aW9yO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHNldDogZnVuY3Rpb24odmFsdWUpIHtcbiAgICAgICAgICAgICAgICBlZGdlQmVoYXZpb3IgPSB2YWx1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgbWFzczoge1xuICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gbWFzcztcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBzZXQ6IGZ1bmN0aW9uKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgbWFzcyA9IHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LFxuICAgICAgICBtYXhTcGVlZDoge1xuICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gbWF4U3BlZWQ7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgc2V0OiBmdW5jdGlvbih2YWx1ZSkge1xuICAgICAgICAgICAgICAgIG1heFNwZWVkID0gdmFsdWU7XG4gICAgICAgICAgICAgICAgbWF4U3BlZWRTcSA9IHZhbHVlICogdmFsdWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIG1heEZvcmNlOiB7XG4gICAgICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBtYXhGb3JjZTtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBzZXQ6IGZ1bmN0aW9uKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgbWF4Rm9yY2UgPSB2YWx1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgLy8gYXJyaXZlXG4gICAgICAgIGFycml2ZVRocmVzaG9sZDoge1xuICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gYXJyaXZlVGhyZXNob2xkO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHNldDogZnVuY3Rpb24odmFsdWUpIHtcbiAgICAgICAgICAgICAgICBhcnJpdmVUaHJlc2hvbGQgPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICBhcnJpdmVUaHJlc2hvbGRTcSA9IHZhbHVlICogdmFsdWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIC8vIHdhbmRlclxuICAgICAgICB3YW5kZXJEaXN0YW5jZToge1xuICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gd2FuZGVyRGlzdGFuY2U7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgc2V0OiBmdW5jdGlvbih2YWx1ZSkge1xuICAgICAgICAgICAgICAgIHdhbmRlckRpc3RhbmNlID0gdmFsdWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIHdhbmRlclJhZGl1czoge1xuICAgICAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gd2FuZGVyUmFkaXVzO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHNldDogZnVuY3Rpb24odmFsdWUpIHtcbiAgICAgICAgICAgICAgICB3YW5kZXJSYWRpdXMgPSB2YWx1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgd2FuZGVyUmFuZ2U6IHtcbiAgICAgICAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHdhbmRlclJhbmdlO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHNldDogZnVuY3Rpb24odmFsdWUpIHtcbiAgICAgICAgICAgICAgICB3YW5kZXJSYW5nZSA9IHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LFxuICAgICAgICAvLyBhdm9pZFxuICAgICAgICBhdm9pZERpc3RhbmNlOiB7XG4gICAgICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBhdm9pZERpc3RhbmNlO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHNldDogZnVuY3Rpb24odmFsdWUpIHtcbiAgICAgICAgICAgICAgICBhdm9pZERpc3RhbmNlID0gdmFsdWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIGF2b2lkQnVmZmVyOiB7XG4gICAgICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkge1xuICAgICAgICAgICAgICAgIHJldHVybiBhdm9pZEJ1ZmZlcjtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBzZXQ6IGZ1bmN0aW9uKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgYXZvaWRCdWZmZXIgPSB2YWx1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSxcbiAgICAgICAgLy8gZm9sbG93UGF0aFxuICAgICAgICBwYXRoSW5kZXg6IHtcbiAgICAgICAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHBhdGhJbmRleDtcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBzZXQ6IGZ1bmN0aW9uKHZhbHVlKSB7XG4gICAgICAgICAgICAgICAgcGF0aEluZGV4ID0gdmFsdWU7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0sXG4gICAgICAgIHBhdGhUaHJlc2hvbGQ6IHtcbiAgICAgICAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIHBhdGhUaHJlc2hvbGQ7XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgc2V0OiBmdW5jdGlvbih2YWx1ZSkge1xuICAgICAgICAgICAgICAgIHBhdGhUaHJlc2hvbGQgPSB2YWx1ZTtcbiAgICAgICAgICAgICAgICBwYXRoVGhyZXNob2xkU3EgPSB2YWx1ZSAqIHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LFxuICAgICAgICAvLyAgZmxvY2tcbiAgICAgICAgbWF4RGlzdGFuY2U6IHtcbiAgICAgICAgICAgIGdldDogZnVuY3Rpb24oKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIG1heERpc3RhbmNlO1xuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIHNldDogZnVuY3Rpb24odmFsdWUpIHtcbiAgICAgICAgICAgICAgICBtYXhEaXN0YW5jZSA9IHZhbHVlO1xuICAgICAgICAgICAgICAgIG1heERpc3RhbmNlU3EgPSB2YWx1ZSAqIHZhbHVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9LFxuICAgICAgICBtaW5EaXN0YW5jZToge1xuICAgICAgICAg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gICAgICAgICByZXR1cm4gdGhpcztcbiAgICAgICAgfVxuICAgICAgICB0aGlzLnggLz0gbDtcbiAgICAgICAgdGhpcy55IC89IGw7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG4gICAgaXNOb3JtYWxpemVkOiBmdW5jdGlvbigpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMubGVuZ3RoID09PSAxO1xuICAgIH0sXG4gICAgdHJ1bmNhdGU6IGZ1bmN0aW9uKG1heCkge1xuICAgICAgICBpZiAodGhpcy5sZW5ndGggPiBtYXgpIHtcbiAgICAgICAgICAgIHRoaXMubGVuZ3RoID0gbWF4O1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG4gICAgc2NhbGVCeTogZnVuY3Rpb24obXVsKSB7XG4gICAgICAgIHRoaXMueCAqPSBtdWw7XG4gICAgICAgIHRoaXMueSAqPSBtdWw7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG4gICAgZGl2aWRlQnk6IGZ1bmN0aW9uKGRpdikge1xuICAgICAgICB0aGlzLnggLz0gZGl2O1xuICAgICAgICB0aGlzLnkgLz0gZGl2O1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9LFxuICAgIGVxdWFsczogZnVuY3Rpb24odmVjKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnggPT09IHZlYy54ICYmIHRoaXMueSA9PT0gdmVjLnk7XG4gICAgfSxcbiAgICBuZWdhdGU6IGZ1bmN0aW9uKCkge1xuICAgICAgICB0aGlzLnggPSAtdGhpcy54O1xuICAgICAgICB0aGlzLnkgPSAtdGhpcy55O1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9LFxuICAgIGRvdFByb2R1Y3Q6IGZ1bmN0aW9uKHZlYykge1xuICAgICAgICAvKlxuICAgICAgICBJZiBBIGFuZCBCIGFyZSBwZXJwZW5kaWN1bGFyIChhdCA5MCBkZWdyZWVzIHRvIGVhY2ggb3RoZXIpLCB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kgKiBsO1xuICAgICAgICB9XG4gICAgfVxufSk7XG5cbi8vIHN0YXRpY1xuXG5WZWMyLnBvb2wgPSBbXTtcblZlYzIuZ2V0ID0gZnVuY3Rpb24oeCwgeSkge1xuICAgIHZhciB2ID0gVmVjMi5wb29sLmxlbmd0aCA+IDAgPyBWZWMyLnBvb2wucG9wKCkgOiBuZXcgVmVjMigpO1xuICAgIHYuc2V0KHgsIHkpO1xuICAgIHJldHVybiB2O1xufTtcblxuVmVjMi5maWxsID0gZnVuY3Rpb24obikge1xuICAgIHdoaWxlIChWZWMyLnBvb2wubGVuZ3RoIDwgbikge1xuICAgICAgICBWZWMyLnBvb2wucHVzaChuZXcgVmVjMigpKTtcbiAgICB9XG59O1xuXG5WZWMyLmFuZ2xlQmV0d2VlbiA9IGZ1bmN0aW9uKGEsIGIpIHtcbiAgICBpZiAoIWEuaXNOb3JtYWxpemVkKCkpIHtcbiAgICAgICAgYSA9IGEuY2xvbmUoKS5ub3JtYWxpemUoKTtcbiAgICB9XG4gICAgaWYgKCFiLmlzTm9ybWFsaXplZCgpKSB7XG4gICAgICAgIGIgPSBiLmNsb25lKCkubm9ybWFsaXplKCk7XG4gICAgfVxuICAgIHJldHVybiBNYXRoLmFjb3MoYS5kb3RQcm9kdWN0KGIpKTtcbn07XG5cbmlmICh0eXBlb2YgbW9kdWxlID09PSAnb2JqZWN0JyAmJiBtb2R1bGUuZXhwb3J0cykge1xuICAgIG1vZHVsZS5leHBvcnRzID0gVmVjMjtcbn1cbiJdfQ== +}); \ No newline at end of file diff --git a/dist/boid.min.js b/dist/boid.min.js index dc5256d..1534ac4 100644 --- a/dist/boid.min.js +++ b/dist/boid.min.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Boid=t()}}(function(){return function t(e,n,i){function r(s,u){if(!n[s]){if(!e[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var d=n[s]={exports:{}};e[s][0].call(d.exports,function(t){var n=e[s][1][t];return r(n?n:t)},d,d.exports,t,e,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;su.width?(e.x=u.width,n.x*=-1):e.xu.height?(e.y=u.height,n.y*=-1):e.yu.width?e.x=u.x:e.xu.height?e.y=u.y:e.yp)i.scaleBy(d);else{var s=d*o/p;i.scaleBy(s)}var u=i.subtract(n);return r.add(u),u.dispose(),W},_=function(t){var n=e.distanceSq(t.position)/h,i=t.velocity.clone().scaleBy(n),r=t.position.clone().add(i);return N(r),i.dispose(),r.dispose(),W},G=function(t){var n=e.distanceSq(t.position)/h,i=t.velocity.clone().scaleBy(n),r=t.position.clone().add(i);return R(r),i.dispose(),r.dispose(),W},A=function(){var t=n.clone().normalize().scaleBy(y),e=s.get();e.length=g,e.angle=x,x+=Math.random()*v-.5*v;var i=t.add(e);return r.add(i),e.dispose(),i.dispose(),W},F=function(t){for(var i=0;i0){var c=s.clone().scaleBy(m),h=s.clone().scaleBy(a),f=h.subtract(u),l=f.length;if(l<(o.radius||0)+b&&h.length=t.length-1?n&&(w=0):w++),w>=t.length-1&&!n?T(i):N(i),W):(w=0,W)},k=function(t){for(var e=n.clone(),i=s.get(),o=0,u=0;u0&&(e.divideBy(o),i.divideBy(o),N(i),r.add(e.subtract(n))),e.dispose(),i.dispose(),W},C=function(t){if(e.distanceSq(t.position)>E)return!1;var i=n.clone().normalize(),r=t.position.clone().subtract(e),o=r.dotProduct(i);return i.dispose(),r.dispose(),!(0>o)},I=function(t){return e.distanceSq(t.position)t&&(this.length=t),this},scaleBy:function(t){return this.x*=t,this.y*=t,this},divideBy:function(t){return this.x/=t,this.y/=t,this},equals:function(t){return this.x===t.x&&this.y===t.y},negate:function(){return this.x=-this.x,this.y=-this.y,this},dotProduct:function(t){return this.x*t.x+this.y*t.y},crossProduct:function(t){return this.x*t.y-this.y*t.x},distanceSq:function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},distance:function(t){return Math.sqrt(this.distanceSq(t))},clone:function(){return i.get(this.x,this.y)},reset:function(){return this.x=0,this.y=0,this},perpendicular:function(){return i.get(-this.y,this.x)},sign:function(t){var e=this.perpendicular(),n=e.dotProduct(t)<0?-1:1;return e.dispose(),n},set:function(t,e){return this.x=t||0,this.y=e||0,this},dispose:function(){i.pool.push(this.reset())}},Object.defineProperties(i.prototype,{lengthSquared:{get:function(){return this.x*this.x+this.y*this.y}},length:{get:function(){return Math.sqrt(this.lengthSquared)},set:function(t){var e=this.angle;this.x=Math.cos(e)*t,this.y=Math.sin(e)*t}},angle:{get:function(){return Math.atan2(this.y,this.x)},set:function(t){var e=this.length;this.x=Math.cos(t)*e,this.y=Math.sin(t)*e}}}),i.pool=[],i.get=function(t,e){var n=i.pool.length>0?i.pool.pop():new i;return n.set(t,e),n},i.fill=function(t){for(;i.pool.lengtht?(e.x=t,n.x*=-1):e.xi?(e.y=i,n.y*=-1):e.yt?e.x=u.x:e.xn?e.y=u.y:e.yp)i.scaleBy(d);else{var s=d*o/p;i.scaleBy(s)}var u=i.subtract(n);return r.add(u),u.dispose(),W},_=function(t){var n=e.distanceSq(t.position)/h,i=t.velocity.clone().scaleBy(n),r=t.position.clone().add(i);return N(r),i.dispose(),r.dispose(),W},G=function(t){var n=e.distanceSq(t.position)/h,i=t.velocity.clone().scaleBy(n),r=t.position.clone().add(i);return R(r),i.dispose(),r.dispose(),W},A=function(){var t=n.clone().normalize().scaleBy(y),e=s.get();e.length=g,e.angle=x,x+=Math.random()*v-.5*v;var i=t.add(e);return r.add(i),e.dispose(),i.dispose(),W},F=function(t){for(var i=0;i0){var c=s.clone().scaleBy(m),h=s.clone().scaleBy(a),f=h.subtract(u),l=f.length;if(l<(o.radius||0)+b&&h.length=t.length-1?n&&(B=0):B++),B>=t.length-1&&!n?T(i):N(i),W):(B=0,W)},k=function(t){for(var e=n.clone(),i=s.get(),o=0,u=0;u0&&(e.divideBy(o),i.divideBy(o),N(i),r.add(e.subtract(n))),e.dispose(),i.dispose(),W},C=function(t){if(e.distanceSq(t.position)>E)return!1;var i=n.clone().normalize(),r=t.position.clone().subtract(e),o=r.dotProduct(i);return i.dispose(),r.dispose(),0>o?!1:!0},I=function(t){return e.distanceSq(t.position)t&&(this.length=t),this},scaleBy:function(t){return this.x*=t,this.y*=t,this},divideBy:function(t){return this.x/=t,this.y/=t,this},equals:function(t){return this.x===t.x&&this.y===t.y},negate:function(){return this.x=-this.x,this.y=-this.y,this},dotProduct:function(t){return this.x*t.x+this.y*t.y},crossProduct:function(t){return this.x*t.y-this.y*t.x},distanceSq:function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},distance:function(t){return Math.sqrt(this.distanceSq(t))},clone:function(){return i.get(this.x,this.y)},reset:function(){return this.x=0,this.y=0,this},perpendicular:function(){return i.get(-this.y,this.x)},sign:function(t){var e=this.perpendicular(),n=e.dotProduct(t)<0?-1:1;return e.dispose(),n},set:function(t,e){return this.x=t||0,this.y=e||0,this},dispose:function(){i.pool.push(this.reset())}},Object.defineProperties(i.prototype,{lengthSquared:{get:function(){return this.x*this.x+this.y*this.y}},length:{get:function(){return Math.sqrt(this.lengthSquared)},set:function(t){var e=this.angle;this.x=Math.cos(e)*t,this.y=Math.sin(e)*t}},angle:{get:function(){return Math.atan2(this.y,this.x)},set:function(t){var e=this.length;this.x=Math.cos(t)*e,this.y=Math.sin(t)*e}}}),i.pool=[],i.get=function(t,e){var n=i.pool.length>0?i.pool.pop():new i;return n.set(t,e),n},i.fill=function(t){for(;i.pool.length bounds.width) { - position.x = bounds.width; + var maxX = bounds.x + bounds.width; + if (position.x > maxX) { + position.x = maxX; velocity.x *= -1; } else if (position.x < bounds.x) { position.x = bounds.x; velocity.x *= -1; } - if (position.y > bounds.height) { - position.y = bounds.height; + + var maxY = bounds.y + bounds.height; + if (position.y > maxY) { + position.y = maxY; velocity.y *= -1; } else if (position.y < bounds.y) { position.y = bounds.y; @@ -102,15 +105,18 @@ function Boid(options) { }; var wrap = function() { - if (position.x > bounds.width) { + var maxX = bounds.x + bounds.width; + if (position.x > maxX) { position.x = bounds.x; } else if (position.x < bounds.x) { - position.x = bounds.width; + position.x = maxX; } - if (position.y > bounds.height) { + + var maxY = bounds.y + bounds.height; + if (position.y > maxY) { position.y = bounds.y; } else if (position.y < bounds.y) { - position.y = bounds.height; + position.y = maxY; } }; @@ -329,6 +335,7 @@ function Boid(options) { // methods var boid = { + bounds: bounds, setBounds: setBounds, update: update, pursue: pursue, diff --git a/test/boid.spec.js b/test/boid.spec.js index 32414e1..439b146 100644 --- a/test/boid.spec.js +++ b/test/boid.spec.js @@ -5,32 +5,39 @@ var Boid = require('../src/boid.js'); describe('boid', function() { - var boid = new Boid(); - - it ('should have created a boid instance', function() { - expect(boid).to.be.an('object'); - expect(boid.setBounds).to.be.a('function'); - expect(boid.update).to.be.a('function'); - expect(boid.pursue).to.be.a('function'); - expect(boid.evade).to.be.a('function'); - expect(boid.wander).to.be.a('function'); - expect(boid.avoid).to.be.a('function'); - expect(boid.followPath).to.be.a('function'); - expect(boid.flock).to.be.a('function'); - expect(boid.arrive).to.be.a('function'); - expect(boid.flee).to.be.a('function'); - - expect(boid.position).to.be.an('object'); - expect(boid.velocity).to.be.an('object'); - // expect(boid.edgeBehaviour).to.be.a('string'); - expect(boid.mass).to.be.a('number'); - expect(boid.maxSpeed).to.be.a('number'); - expect(boid.maxForce).to.be.a('number'); - }); - - it ('should have static members', function() { - expect(Boid.vec2).to.be.a('function'); - expect(Boid.obstacle).to.be.a('function'); - }); + var boid = new Boid(); + + it('should have created a boid instance', function() { + expect(boid).to.be.an('object'); + }); + + it('should have methods', function() { + expect(boid.setBounds).to.be.a('function'); + expect(boid.update).to.be.a('function'); + expect(boid.pursue).to.be.a('function'); + expect(boid.evade).to.be.a('function'); + expect(boid.wander).to.be.a('function'); + expect(boid.avoid).to.be.a('function'); + expect(boid.followPath).to.be.a('function'); + expect(boid.flock).to.be.a('function'); + expect(boid.arrive).to.be.a('function'); + expect(boid.flee).to.be.a('function'); + expect(boid.seek).to.be.a('function'); + }); + + it('should have props', function() { + expect(boid.position).to.be.an('object'); + expect(boid.velocity).to.be.an('object'); + expect(boid.bounds).to.be.an('object'); + // expect(boid.edgeBehaviour).to.be.a('string'); + expect(boid.mass).to.be.a('number'); + expect(boid.maxSpeed).to.be.a('number'); + expect(boid.maxForce).to.be.a('number'); + }); + + it('should have static members', function() { + expect(Boid.vec2).to.be.a('function'); + expect(Boid.obstacle).to.be.a('function'); + }); });