shape_pool.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import poolFactory from './pool_factory';
  2. import pointPool from './point_pool';
  3. import ShapePath from '../shapes/ShapePath';
  4. const shapePool = (function () {
  5. function create() {
  6. return new ShapePath();
  7. }
  8. function release(shapePath) {
  9. var len = shapePath._length;
  10. var i;
  11. for (i = 0; i < len; i += 1) {
  12. pointPool.release(shapePath.v[i]);
  13. pointPool.release(shapePath.i[i]);
  14. pointPool.release(shapePath.o[i]);
  15. shapePath.v[i] = null;
  16. shapePath.i[i] = null;
  17. shapePath.o[i] = null;
  18. }
  19. shapePath._length = 0;
  20. shapePath.c = false;
  21. }
  22. function clone(shape) {
  23. var cloned = factory.newElement();
  24. var i;
  25. var len = shape._length === undefined ? shape.v.length : shape._length;
  26. cloned.setLength(len);
  27. cloned.c = shape.c;
  28. for (i = 0; i < len; i += 1) {
  29. cloned.setTripleAt(shape.v[i][0], shape.v[i][1], shape.o[i][0], shape.o[i][1], shape.i[i][0], shape.i[i][1], i);
  30. }
  31. return cloned;
  32. }
  33. var factory = poolFactory(4, create, release);
  34. factory.clone = clone;
  35. return factory;
  36. }());
  37. export default shapePool;