import * as macro from '../../../macro';
import { VtkDataTypes } from '../DataArray/Constants';
import vtkDataArray from '../DataArray';
// ----------------------------------------------------------------------------
// vtkPoints methods
// ----------------------------------------------------------------------------

function vtkPoints(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkPoints');

  // Forwarding methods
  publicAPI.getNumberOfPoints = publicAPI.getNumberOfTuples;

  publicAPI.setNumberOfPoints = (nbPoints, dimension = 3) => {
    if (publicAPI.getNumberOfPoints() !== nbPoints) {
      model.size = nbPoints * dimension;
      model.values = new window[model.dataType](model.size);
      publicAPI.setNumberOfComponents(dimension);
      publicAPI.modified();
    }
  };

  publicAPI.setPoint = (idx, ...xyz) => {
    const offset = idx * model.numberOfComponents;
    for (let i = 0; i < model.numberOfComponents; i++) {
      model.values[offset + i] = xyz[i];
    }
  };

  publicAPI.getPoint = publicAPI.getTuple;

  publicAPI.getBounds = () => {
    if (model.data.getNumberOfComponents() === 3) {
      return [].concat(
        model.data.getRange(0),
        model.data.getRange(1),
        model.data.getRange(2));
    }

    if (model.data.getNumberOfComponents() !== 2) {
      console.error('getBounds called on an array with components of ',
        model.data.getNumberOfComponents());
      return [1, -1, 1, -1, 1, -1];
    }

    return [].concat(
      model.data.getRange(0),
      model.data.getRange(1));
  };

  // Trigger the computation of bounds
  publicAPI.computeBounds = publicAPI.getBounds;
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
  numberOfComponents: 3,
  dataType: VtkDataTypes.FLOAT,
};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);

  vtkDataArray.extend(publicAPI, model, initialValues);
  vtkPoints(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkPoints');

// ----------------------------------------------------------------------------

export default { newInstance, extend };

@@ -1095,34 +1095,33 @@
 %3E %7B%0A    if (
-model.data
+publicAPI
 .getNumberOf
@@ -1170,34 +1170,33 @@
 at(%0A        
-model.data
+publicAPI
 .getRange(0)
@@ -1201,34 +1201,33 @@
 0),%0A        
-model.data
+publicAPI
 .getRange(1)
@@ -1232,34 +1232,33 @@
 1),%0A        
-model.data
+publicAPI
 .getRange(2)
@@ -1275,26 +1275,25 @@
     if (
-model.data
+publicAPI
 .getNumb
@@ -1394,34 +1394,33 @@
  ',%0A        
-model.data
+publicAPI
 .getNumberOf
@@ -1501,34 +1501,33 @@
 ncat(%0A      
-model.data
+publicAPI
 .getRange(0)
@@ -1534,26 +1534,25 @@
 ,%0A      
-model.data
+publicAPI
 .getRang
@@ -1859,16 +1859,31 @@
 UES = %7B%0A
+  empty: true,%0A
   number

Fix getBounds method to use itself instead of data