/**
 * 区域判断函数模块
 * 用于判断点是否在特定区域内
 */

import type { ChartOptions, UChartsConfig } from '../data-processing/index';

/**
 * 判断是否在图例区域内
 * @param currentPoints 当前触摸点坐标
 * @param area 图例区域
 * @returns 是否在图例区域内
 */
export function isInExactLegendArea(
  currentPoints: { x: number; y: number },
  area: { start: { x: number; y: number }; end: { x: number; y: number } }
): boolean {
  return (
    currentPoints.x > area.start.x &&
    currentPoints.x < area.end.x &&
    currentPoints.y > area.start.y &&
    currentPoints.y < area.end.y
  );
}

/**
 * 判断是否在图表区域内
 * @param currentPoints 当前触摸点坐标
 * @param opts 图表配置选项
 * @param config 图表配置
 * @returns 是否在图表区域内
 */
export function isInExactChartArea(
  currentPoints: { x: number; y: number },
  opts: ChartOptions,
  config: UChartsConfig
): boolean {
  return (
    currentPoints.x <= opts.width - opts.area[1] + 10 &&
    currentPoints.x >= opts.area[3] - 10 &&
    currentPoints.y >= opts.area[0] &&
    currentPoints.y <= opts.height - opts.area[2]
  );
}

/**
 * 判断是否在饼图区域内
 * @param currentPoints 当前触摸点坐标
 * @param center 饼图中心点
 * @param radius 饼图半径
 * @returns 是否在饼图区域内
 */
export function isInExactPieChartArea(
  currentPoints: { x: number; y: number },
  center: { x: number; y: number },
  radius: number
): boolean {
  return (
    Math.pow(currentPoints.x - center.x, 2) +
      Math.pow(currentPoints.y - center.y, 2) <=
    Math.pow(radius, 2)
  );
}
