#include <camotics/sim/ConicSweep.h>
#include <camotics/sim/SpheroidSweep.h>

#include <emscripten/emscripten.h>

#include <vector>

using CAMotics::ConicSweep;
using CAMotics::SpheroidSweep;
using cb::Rectangle3D;
using cb::Vector3D;

extern "C" {
  EMSCRIPTEN_KEEPALIVE int camotics_sweep_abi_version() {return 1;}

  EMSCRIPTEN_KEEPALIVE double camotics_conic_depth(
    double length, double topRadius, double bottomRadius,
    double ax, double ay, double az,
    double bx, double by, double bz,
    double px, double py, double pz) {
    return ConicSweep(length, topRadius, bottomRadius).depth(
      Vector3D(ax, ay, az), Vector3D(bx, by, bz), Vector3D(px, py, pz));
  }

  EMSCRIPTEN_KEEPALIVE double camotics_spheroid_depth(
    double radius, double length,
    double ax, double ay, double az,
    double bx, double by, double bz,
    double px, double py, double pz) {
    return SpheroidSweep(radius, length).depth(
      Vector3D(ax, ay, az), Vector3D(bx, by, bz), Vector3D(px, py, pz));
  }

  EMSCRIPTEN_KEEPALIVE int camotics_conic_bbox_count(
    double length, double topRadius, double bottomRadius,
    double ax, double ay, double az,
    double bx, double by, double bz,
    double tolerance) {
    std::vector<Rectangle3D> bounds;
    ConicSweep(length, topRadius, bottomRadius).getBBoxes(
      Vector3D(ax, ay, az), Vector3D(bx, by, bz), bounds, tolerance);
    return bounds.size();
  }
}
