/*
  This file is part of CDO. CDO is a collection of Operators to manipulate and analyse Climate model Data.

  Author: Uwe Schulzweida

*/

#ifndef CELLSEARCH_UTILS_H
#define CELLSEARCH_UTILS_H

#include <cstddef>
#include <memory>
#include <array>

extern "C"
{
#include "libyac/src/grid_cell.h"
}

struct GridCell
{
  std::unique_ptr<double[]> coordinatesX;
  std::unique_ptr<double[]> coordinatesY;
  std::unique_ptr<std::array<double, 3>[]> coordinatesXYZ;
  yac_grid_cell yacGridCell{};

  void
  init(size_t numCorners, enum yac_edge_type *edgeType)
  {
    coordinatesX = std::make_unique<double[]>(numCorners);
    coordinatesY = std::make_unique<double[]>(numCorners);
    coordinatesXYZ = std::make_unique<std::array<double, 3>[]>(numCorners);
    yacGridCell.array_size = numCorners;
    yacGridCell.num_corners = numCorners;
    yacGridCell.edge_type = edgeType;
    yacGridCell.coordinates_xyz = reinterpret_cast<double (*)[3]>(coordinatesXYZ.get());
  }
};

struct CellsearchParams
{
  size_t dims[2] = { 0 };
  double (*m_xyzCoords)[3]{ nullptr };
  bool fast{ false };
};

#endif
