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C,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IACtC,IAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAEtC,OAAO,WAAI,CAAC,SAAS,CAAC,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,KAAK,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;AACrG,CAAC;AARD,8CAQC","sourcesContent":["import { Coordinate } from '../dependents';\nimport { Point } from '../interface';\nimport { getSectorPath } from './graphics';\nimport { isBetween } from './helper';\nimport { BBox } from './bbox';\n\n/**\n * @ignore\n * Gets x dimension length\n * @param coordinate\n * @returns x dimension length\n */\nexport function getXDimensionLength(coordinate): number {\n if (coordinate.isPolar && !coordinate.isTransposed) {\n // 极坐标系下 width 为弧长\n return (coordinate.endAngle - coordinate.startAngle) * coordinate.getRadius();\n }\n\n // 直角坐标系\n const start = coordinate.convert({ x: 0, y: 0 });\n const end = coordinate.convert({ x: 1, y: 0 });\n // 坐标系有可能发生 transpose 等变换,所有通过两点之间的距离进行计算\n return Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));\n}\n\n/**\n * @ignore\n * Determines whether full circle is\n * @param coordinate\n * @returns true if full circle\n */\nexport function isFullCircle(coordinate: Coordinate): boolean {\n if (coordinate.isPolar) {\n const { startAngle, endAngle } = coordinate;\n return endAngle - startAngle === Math.PI * 2;\n }\n return false;\n}\n\n/**\n * @ignore\n * 获取当前点到坐标系圆心的距离\n * @param coordinate 坐标系\n * @param point 当前点\n * @returns distance to center\n */\nexport function getDistanceToCenter(coordinate: Coordinate, point: Point): number {\n const center = coordinate.getCenter() as Point;\n return Math.sqrt((point.x - center.x) ** 2 + (point.y - center.y) ** 2);\n}\n\n/**\n * @ignore\n * 坐标点是否在坐标系中\n * @param coordinate\n * @param point\n */\nexport function isPointInCoordinate(coordinate: Coordinate, point: Point) {\n let result = false;\n\n if (coordinate) {\n if (coordinate.type === 'theta') {\n const { start, end } = coordinate;\n result = isBetween(point.x, start.x, end.x) && isBetween(point.y, start.y, end.y);\n } else {\n const invertPoint = coordinate.invert(point);\n\n result = isBetween(invertPoint.x, 0, 1) && isBetween(invertPoint.y, 0, 1);\n }\n }\n\n return result;\n}\n\n/**\n * @ignore\n * 获取点到圆心的连线与水平方向的夹角\n */\nexport function getAngleByPoint(coordinate: Coordinate, point: Point): number {\n const center = coordinate.getCenter();\n return Math.atan2(point.y - center.y, point.x - center.x);\n}\n\n/**\n * @ignore\n * 获取同坐标系范围相同的剪切区域\n * @param coordinate\n * @returns\n */\nexport function getCoordinateClipCfg(coordinate: Coordinate, margin: number = 0) {\n const { start, end } = coordinate;\n const width = coordinate.getWidth();\n const height = coordinate.getHeight();\n\n if (coordinate.isPolar) {\n const { startAngle, endAngle } = coordinate;\n const center = coordinate.getCenter();\n const radius = coordinate.getRadius();\n\n return {\n type: 'path',\n startState: {\n path: getSectorPath(center.x, center.y, radius + margin, startAngle, startAngle),\n },\n endState: (ratio) => {\n const diff = (endAngle - startAngle) * ratio + startAngle;\n const path = getSectorPath(center.x, center.y, radius + margin, startAngle, diff);\n return {\n path,\n };\n },\n attrs: {\n path: getSectorPath(center.x, center.y, radius + margin, startAngle, endAngle),\n },\n };\n }\n\n let endState;\n if (coordinate.isTransposed) {\n endState = {\n height: height + margin * 2,\n };\n } else {\n endState = {\n width: width + margin * 2,\n };\n }\n\n return {\n type: 'rect',\n startState: {\n x: start.x - margin,\n y: end.y - margin,\n width: coordinate.isTransposed ? width + margin * 2 : 0,\n height: coordinate.isTransposed ? 0 : height + margin * 2,\n },\n endState,\n attrs: {\n x: start.x - margin,\n y: end.y - margin,\n width: width + margin * 2,\n height: height + margin * 2,\n },\n };\n}\n\n/**\n * 获取坐标系范围的 BBox\n * @param coordinate\n * @param margin\n */\nexport function getCoordinateBBox(coordinate: Coordinate, margin = 0) {\n const { start, end } = coordinate;\n const width = coordinate.getWidth();\n const height = coordinate.getHeight();\n const minX = Math.min(start.x, end.x);\n const minY = Math.min(start.y, end.y);\n\n return BBox.fromRange(minX - margin, minY - margin, minX + width + margin, minY + height + margin);\n}\n"]}
\No newline at end of file