modeling/src/geometries/poly2/create.js

  1. /**
  2. * Represents a convex 2D polygon consisting of a list of ordered vertices.
  3. * @typedef {Object} poly2
  4. * @property {Array} vertices - list of ordered vertices (2D)
  5. */
  6. /**
  7. * Creates a new polygon with initial values.
  8. *
  9. * @param {Array} [vertices] - list of vertices (2D)
  10. * @returns {poly2} a new polygon
  11. * @alias module:modeling/geometries/poly2.create
  12. *
  13. * @example
  14. * let polygon = create()
  15. */
  16. const create = (vertices) => {
  17. if (vertices === undefined || vertices.length < 3) {
  18. vertices = [] // empty contents
  19. }
  20. return { vertices: vertices }
  21. }
  22. module.exports = create