"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.tool = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _component = _interopRequireDefault(require("./component"));

var _debug = _interopRequireDefault(require("debug"));

var _utils = require("../../utils");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

var log = (0, _debug["default"])('pie-lib:graphing:parabola');

var tool = function tool() {
  return {
    type: 'parabola',
    Component: _component["default"],
    complete: function complete(data, mark) {
      return _objectSpread(_objectSpread({}, mark), {}, {
        building: false,
        closed: true
      });
    },
    addPoint: function addPoint(point, mark) {
      log('add point to parabola model: ', point, 'mark: ', mark);

      if (mark && ((0, _utils.equalPoints)(mark.root, point) || (0, _utils.sameAxes)(mark.root, point))) {
        return mark;
      }

      if (!mark) {
        return {
          type: 'parabola',
          root: point,
          edge: undefined,
          closed: false,
          building: true
        };
      } else if (mark && !mark.root) {
        throw new Error('no root - should never happen');
      } else {
        return _objectSpread(_objectSpread({}, mark), {}, {
          edge: point,
          closed: true,
          building: false
        });
      }
    }
  };
};

exports.tool = tool;
//# sourceMappingURL=index.js.map