ShapeCollection.js 708 B

1234567891011121314151617181920212223242526272829
  1. import {
  2. createSizedArray,
  3. } from '../helpers/arrays';
  4. import shapePool from '../pooling/shape_pool';
  5. function ShapeCollection() {
  6. this._length = 0;
  7. this._maxLength = 4;
  8. this.shapes = createSizedArray(this._maxLength);
  9. }
  10. ShapeCollection.prototype.addShape = function (shapeData) {
  11. if (this._length === this._maxLength) {
  12. this.shapes = this.shapes.concat(createSizedArray(this._maxLength));
  13. this._maxLength *= 2;
  14. }
  15. this.shapes[this._length] = shapeData;
  16. this._length += 1;
  17. };
  18. ShapeCollection.prototype.releaseShapes = function () {
  19. var i;
  20. for (i = 0; i < this._length; i += 1) {
  21. shapePool.release(this.shapes[i]);
  22. }
  23. this._length = 0;
  24. };
  25. export default ShapeCollection;