How to use the @jscad/io-utils/arrays.toArray function in @jscad/io-utils

To help you get started, we’ve selected a few @jscad/io-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jscad / OpenJSCAD.org / packages / io / svg-serializer / index.js View on Github external
const serialize = (...params) => {
  let options = {}
  let objects
  if (params.length === 0) {
    throw new Error('no arguments supplied to serialize function !')
  } else if (params.length === 1) {
    // assumed to be object(s)
    objects = Array.isArray(params[0]) ? params[0] : params
  } else if (params.length > 1) {
    options = params[0]
    objects = params[1]
  }
  // make sure we always deal with arrays of objects as inputs
  objects = toArray(objects)
  console.log('params', params)
  console.log('options', options)
  console.log('objects', objects)
  const defaults = {
    statusCallback: null,
    unit: 'mm', // em | ex | px | in | cm | mm | pt | pc
    decimals: 10000
  }
  options = Object.assign({}, defaults, options)

  options.statusCallback && options.statusCallback({progress: 0})

  // get the lower and upper bounds of ALL convertable objects
  var bounds = getBounds(objects)

  var width = 0
github jscad / OpenJSCAD.org / packages / io / x3d-serializer / index.js View on Github external
const serialize = (...params) => {
  let options = {}
  let objects
  if (params.length === 0) {
    throw new Error('no arguments supplied to serialize function !')
  } else if (params.length === 1) {
    // assumed to be object(s)
    objects = Array.isArray(params[0]) ? params[0] : params
  } else if (params.length > 1) {
    options = params[0]
    objects = params[1]
  }
  // make sure we always deal with arrays of objects as inputs
  objects = toArray(objects)

  const defaults = {
    statusCallback: null,
    unit: 'millimeter', // millimeter, inch, feet, meter or micrometer
    color: [0, 0, 1, 1.0], // default colorRGBA specification
    decimals: 1000
  }
  options = Object.assign({}, defaults, options)

  options.statusCallback && options.statusCallback({progress: 0})

  // construct the contents of the XML
  var body = ['X3D',
    {
      profile: 'Interchange',
      version: '3.3',
github jscad / OpenJSCAD.org / packages / io / dxf-serializer / index.js View on Github external
const serialize = (...params) => {
  let options = {}
  let objects
  if (params.length === 0) {
    throw new Error('no arguments supplied to serialize function !')
  } else if (params.length === 1) {
    // assumed to be object(s)
    objects = Array.isArray(params[0]) ? params[0] : params
  } else if (params.length > 1) {
    options = params[0]
    objects = params[1]
  }
  // make sure we always deal with arrays of objects as inputs
  objects = toArray(objects)

  const defaults = {
    cagTo: 'lwpolyline', // or polyline
    csgTo: '3dface', // or polyline
    pathTo: 'lwpolyline',
    statusCallback: null
  }
  options = Object.assign({}, defaults, options)

  let dxfContent = `999
DXF generated by JSCAD
${dxfHeaders(options)}
${dxfClasses(options)}
${dxfTables(options)}
${dxfBlocks(options)}
${dxfEntities(objects, options)}
github jscad / OpenJSCAD.org / packages / io / stl-serializer / index.js View on Github external
const serialize = (...params) => {
  let options = {}
  let objects
  if (params.length === 0) {
    throw new Error('no arguments supplied to serialize function !')
  } else if (params.length === 1) {
    // assumed to be object(s)
    objects = Array.isArray(params[0]) ? params[0] : params
  } else if (params.length > 1) {
    options = params[0]
    objects = params[1]
  }
  // make sure we always deal with arrays of objects as inputs
  objects = toArray(objects)

  const defaults = {
    binary: true,
    statusCallback: null
  }
  options = Object.assign({}, defaults, options)

  // only use valid CSG objects
  let csgs = []
  objects.forEach(function (object, i) {
    if (isCSG(object) & object.polygons.length > 0) {
      csgs.push(ensureManifoldness(object))
    }
  })
  return options.binary ? serializeBinary(csgs, options) : serializeText(csgs, options)
}
github jscad / OpenJSCAD.org / packages / io / amf-serializer / index.js View on Github external
const serialize = (...params) => {
  let options = {}
  let objects
  if (params.length === 0) {
    throw new Error('no arguments supplied to serialize function !')
  } else if (params.length === 1) {
    // assumed to be object(s)
    objects = Array.isArray(params[0]) ? params[0] : params
  } else if (params.length > 1) {
    options = params[0]
    objects = params[1]
  }
  // make sure we always deal with arrays of objects as inputs
  objects = toArray(objects)

  const defaults = {
    statusCallback: null,
    unit: 'millimeter', // millimeter, inch, feet, meter or micrometer
    metadata: null
  }
  options = Object.assign({}, defaults, options)

  options.statusCallback && options.statusCallback({progress: 0})

  // construct the contents of the XML
  var body = ['amf',
    {
      unit: options.unit,
      version: '1.1'
    },
github jscad / OpenJSCAD.org / packages / io / dxf-serializer / index.js View on Github external
const dxfEntities = (objects, options) => {
  objects = toArray(objects)
  let entityContents = objects.map(function (object, i) {
    if (isCAG(object)) {
      let paths = object.getOutlinePaths()
      if (options.cagTo === 'polyline') {
        return PathsToPolyine(paths, options)
      }
      return PathsToLwpolyine(paths, options)
    }
    if (isCSG(object)) {
      object = ensureManifoldness(object)
      if (options.csgTo === 'polyline') {
        return PolygonsToPolyline(object, options)
      }
      return PolygonsTo3DFaces(object, options)
    }
    if (isPath(object)) {

@jscad/io-utils

Utilities for JSCAD IO Packages

MIT
Latest version published 1 month ago

Package Health Score

87 / 100
Full package analysis