modeling/src/operations/extrusions/slice/clone.js

  1. const create = require('./create')
  2. const vec3 = require('../../../maths/vec3')
  3. /**
  4. * Create a deep clone of the given slice.
  5. *
  6. * @param {slice} [out] - receiving slice
  7. * @param {slice} slice - slice to clone
  8. * @returns {slice} a new slice
  9. * @alias module:modeling/extrusions/slice.clone
  10. */
  11. const clone = (...params) => {
  12. let out
  13. let slice
  14. if (params.length === 1) {
  15. out = create()
  16. slice = params[0]
  17. } else {
  18. out = params[0]
  19. slice = params[1]
  20. }
  21. // deep clone of edges
  22. out.edges = slice.edges.map((edge) => [vec3.clone(edge[0]), vec3.clone(edge[1])])
  23. return out
  24. }
  25. module.exports = clone