| | |
| | | } |
| | | |
| | | /** |
| | | * 环穿:把 getPositionAfterMove 等返回的 position 压到轨带中线;非环穿或无效 position 原样返回。 |
| | | * @param {{ type: string }} trackInfo |
| | | * @param {{ x: number, y: number, path?: object }|null|undefined} position |
| | | * @returns {typeof position} |
| | | */ |
| | | function applyAnnulusBandCenterToPosition(trackInfo, position) { |
| | | if (!position || !trackInfo || trackInfo.type !== 'annulus') { |
| | | return position; |
| | | } |
| | | var c = centerAnnulusBandPoint(trackInfo, position.x, position.y, position.path); |
| | | return Object.assign({}, position, { x: c.x, y: c.y }); |
| | | } |
| | | |
| | | /** |
| | | * 沿 pathList 移动后再对环穿做轨带中线修正(与 getPositionAfterMove + applyAnnulusBandCenterToPosition 等价)。 |
| | | * @param {{ type: string }} trackInfo |
| | | * @param {{ x: number, y: number }} point 起点;环穿上应在外圈 path 上 |
| | | * @param {object[]} pathList |
| | | * @param {object} path |
| | | * @param {number} deltaDistance |
| | | * @param {number} [angle] |
| | | * @returns {{ x: number, y: number, path: object, angle?: number }} 与 getPositionAfterMove 返回形态一致 |
| | | */ |
| | | function computeFinalPosition(trackInfo, point, pathList, path, deltaDistance, angle) { |
| | | var position = getPositionAfterMove({ |
| | | point: point, |
| | | pathList: pathList, |
| | | path: path, |
| | | deltaDistance: deltaDistance, |
| | | angle: angle |
| | | }); |
| | | return applyAnnulusBandCenterToPosition(trackInfo, position); |
| | | } |
| | | |
| | | /** |
| | | * 将坐标压回环穿外圈 path(直线段投影、圆弧段落到半径上)。 |
| | | * sprite 已做 centerAnnulusBandPoint 时不能直接作为 getPositionAfterMove 的起点,否则会沿「点→段终点」斜移漂移。 |
| | | * @param {number} x |
| | |
| | | * @param {{ type: string, startX?: number, startY?: number, x?: number, y?: number, radius?: number }|null|undefined} path |
| | | * @returns {{ x: number, y: number }} |
| | | */ |
| | | function snapToAnnulusOuterPath(x, y, path) { |
| | | if (!path) { |
| | | function snapToAnnulusOuterPath(trackInfo, x, y, path) { |
| | | if (!path || trackInfo.type !== 'annulus') { |
| | | return { x: x, y: y }; |
| | | } |
| | | if (path.type === 'line') { |
| | |
| | | snapToAnnulusOuterPath: snapToAnnulusOuterPath, |
| | | startDrawSmoothedPath: startDrawSmoothedPath, |
| | | getRotate: getRotate, |
| | | computeFinalPosition:computeFinalPosition, |
| | | applyAnnulusBandCenterToPosition:applyAnnulusBandCenterToPosition, |
| | | drawCrnDeviceGraphics: drawCrnDeviceGraphics, |
| | | drawRgvDeviceGraphics: drawRgvDeviceGraphics |
| | | }; |