"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const mix = require("../../../../../../../popmotion@11.0.3/node_modules/popmotion/dist/es/utils/mix.js");
const distance = require("../../../../../../../popmotion@11.0.3/node_modules/popmotion/dist/es/utils/distance.js");
function calcLength(axis) {
  return axis.max - axis.min;
}
function isNear(value, target, maxDistance) {
  if (target === void 0) {
    target = 0;
  }
  if (maxDistance === void 0) {
    maxDistance = 0.01;
  }
  return distance.distance(value, target) < maxDistance;
}
function calcAxisDelta(delta, source, target, origin) {
  if (origin === void 0) {
    origin = 0.5;
  }
  delta.origin = origin;
  delta.originPoint = mix.mix(source.min, source.max, delta.origin);
  delta.scale = calcLength(target) / calcLength(source);
  if (isNear(delta.scale, 1, 1e-4) || isNaN(delta.scale))
    delta.scale = 1;
  delta.translate = mix.mix(target.min, target.max, delta.origin) - delta.originPoint;
  if (isNear(delta.translate) || isNaN(delta.translate))
    delta.translate = 0;
}
function calcBoxDelta(delta, source, target, origin) {
  calcAxisDelta(delta.x, source.x, target.x, origin === null || origin === void 0 ? void 0 : origin.originX);
  calcAxisDelta(delta.y, source.y, target.y, origin === null || origin === void 0 ? void 0 : origin.originY);
}
function calcRelativeAxis(target, relative, parent) {
  target.min = parent.min + relative.min;
  target.max = target.min + calcLength(relative);
}
function calcRelativeBox(target, relative, parent) {
  calcRelativeAxis(target.x, relative.x, parent.x);
  calcRelativeAxis(target.y, relative.y, parent.y);
}
function calcRelativeAxisPosition(target, layout, parent) {
  target.min = layout.min - parent.min;
  target.max = target.min + calcLength(layout);
}
function calcRelativePosition(target, layout, parent) {
  calcRelativeAxisPosition(target.x, layout.x, parent.x);
  calcRelativeAxisPosition(target.y, layout.y, parent.y);
}
exports.calcAxisDelta = calcAxisDelta;
exports.calcBoxDelta = calcBoxDelta;
exports.calcLength = calcLength;
exports.calcRelativeAxis = calcRelativeAxis;
exports.calcRelativeAxisPosition = calcRelativeAxisPosition;
exports.calcRelativeBox = calcRelativeBox;
exports.calcRelativePosition = calcRelativePosition;
exports.isNear = isNear;
//# sourceMappingURL=delta-calc.js.map
