import { LOOP_SCALE, getSelfLoopControlPoints } from '../../rendering/canvas/selfRelationLoop';
export var getBezierCenter = function (x1, y1, x2, y2, cx1, cy1, cx2, cy2) {
    var t = 0.5;
    var Bt = (1 - t) * (1 - t) * (1 - t);
    var Ct = 3 * ((1 - t) * (1 - t)) * t;
    var Dt = 3 * (1 - t) * (t * t);
    var Et = t * t * t;
    var x = Bt * x1 + Ct * cx1 + Dt * cx2 + Et * x2;
    var y = Bt * y1 + Ct * cy1 + Dt * cy2 + Et * y2;
    return { x: x, y: y };
};
export var getEdgeCenter = function (edgeId, sourceId, targetId, sigma) {
    var edgeDisplayData = sigma.getEdgeDisplayData(edgeId);
    var sourceDisplayData = sigma.getNodeDisplayData(sourceId);
    var targetDisplayData = sigma.getNodeDisplayData(targetId);
    var sourceCenter = sigma.framedGraphToViewport({
        x: sourceDisplayData.x,
        y: sourceDisplayData.y
    });
    var targetCenter = sigma.framedGraphToViewport({
        x: targetDisplayData.x,
        y: targetDisplayData.y
    });
    var getLoopCenter = function () {
        var _a = getSelfLoopControlPoints(sourceCenter.x, sourceCenter.y, sigma.scaleSize(sourceDisplayData.size) * LOOP_SCALE), x1 = _a.x1, y1 = _a.y1, x2 = _a.x2, y2 = _a.y2;
        return getBezierCenter(sourceCenter.x, sourceCenter.y, sourceCenter.x, sourceCenter.y, x1, y1, x2, y2);
    };
    var loopCenter = edgeDisplayData.loop && getLoopCenter();
    var getEdgeCenter = function (coord) { return sourceCenter[coord] + (targetCenter[coord] - sourceCenter[coord]) / 2; };
    var x = edgeDisplayData.loop ? loopCenter.x : getEdgeCenter('x');
    var y = edgeDisplayData.loop ? loopCenter.y : getEdgeCenter('y');
    return { x: x, y: y };
};
