
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/


/**
 * AUTO-GENERATED FILE. DO NOT MODIFY.
 */

function findIntersectionPoint(A, B, rectangle, bias) {
  if (bias === void 0) {
    bias = 'start';
  }
  var xA = A[0],
    yA = A[1];
  var xB = B[0],
    yB = B[1];
  var left = rectangle.left,
    top = rectangle.top,
    right = rectangle.right,
    bottom = rectangle.bottom;
  if (yA.toFixed(3) === yB.toFixed(3)) {
    if (xA === xB) {
      var isEndBias = bias === 'end';
      return [isEndBias ? right : left, yA];
    }
    return [xA > xB ? right : left, yA];
  } else if (xA.toFixed(3) === xB.toFixed(3)) {
    if (yA === yB) {
      var isEndBias = bias === 'end';
      return [xA, isEndBias ? top : bottom];
    }
    return [xA, yA > yB ? top : bottom];
  }
  // 计算射线的方向向量
  var direction = [xB - xA, yB - yA];
  // 计算参数 t
  var t = Math.min((left - xA) / direction[0], (right - xA) / direction[0], (top - yA) / direction[1], (bottom - yA) / direction[1]);
  // 计算相交点坐标
  var intersectionPoint = [xA + t * direction[0], yA + t * direction[1]];
  return intersectionPoint;
}
function getArrowPoints(fromX, fromY, toX, toY, arrowAngle) {
  if (arrowAngle === void 0) {
    arrowAngle = Math.PI / 4;
  }
  // 计算方向向量
  var dx = toX - fromX;
  var dy = toY - fromY;
  // 计算方向向量的长度（线段长度）
  var length = Math.sqrt(dx * dx + dy * dy);
  // 如果起点和终点相同，则返回一个点构成的箭头（实际上就是不绘制箭头）
  if (length <= 20) {
    return;
  }
  var arrowLength = Math.min(Math.floor(length / 3), 10);
  // 计算单位方向向量
  var normalizedDirectionX = dx / length;
  var normalizedDirectionY = dy / length;
  // 计算垂直于单位方向向量的单位向量
  var perpendicularX = -normalizedDirectionY; // 旋转90度
  var perpendicularY = normalizedDirectionX; // 旋转90度
  // 计算箭头翼尖的坐标
  var point1X = toX - arrowLength * (normalizedDirectionX * Math.cos(arrowAngle) - perpendicularX * Math.sin(arrowAngle));
  var point1Y = toY - arrowLength * (normalizedDirectionY * Math.cos(arrowAngle) - perpendicularY * Math.sin(arrowAngle));
  var point2X = toX - arrowLength * (normalizedDirectionX * Math.cos(-arrowAngle) - perpendicularX * Math.sin(-arrowAngle));
  var point2Y = toY - arrowLength * (normalizedDirectionY * Math.cos(-arrowAngle) - perpendicularY * Math.sin(-arrowAngle));
  // 返回箭头的三个顶点
  return [point1X, point1Y, toX, toY, point2X, point2Y];
}
function getDrawLine(params) {
  var extend = params.extend,
    height = params.height,
    width = params.width,
    startPoint = params.startPoint,
    endPoint = params.endPoint;
  var rect = {
    left: 0,
    bottom: 0,
    top: height,
    right: width
  };
  switch (extend) {
    case 'left':
      {
        var pointC = findIntersectionPoint(startPoint, endPoint, rect);
        return [pointC, endPoint];
      }
    case 'right':
      {
        var pointB = findIntersectionPoint(endPoint, startPoint, rect, 'end');
        return [startPoint, pointB];
      }
    case 'both':
      {
        var pointC = findIntersectionPoint(startPoint, endPoint, rect);
        var pointB = findIntersectionPoint(endPoint, startPoint, rect, 'end');
        return [pointC, pointB];
      }
    default:
      return [startPoint, endPoint];
  }
}
export { findIntersectionPoint, getArrowPoints, getDrawLine };