区段复制优化

This commit is contained in:
joylink_zhaoerwei 2024-01-17 18:02:18 +08:00
parent ae2e524059
commit 79f3b05f39

View File

@ -9,6 +9,7 @@ import {
KeyListener,
calculateDistanceFromPointToLine,
getRectangleCenter,
distance2,
} from 'jl-graphic';
import { TrainState } from './graphics/TrainInteraction';
import {
@ -293,16 +294,26 @@ export function initCommonDrawApp(app: IDrawApp) {
//要移动到目标位的区段
const sections = app.queryStore.queryByType<Section>(Section.Type);
const minDistanceSection = sections.reduce((prev, cur) => {
return calculateDistanceFromPointToLine(
const prevDistance = calculateDistanceFromPointToLine(
prev.localToCanvasPoint(prev.getStartPoint()),
prev.localToCanvasPoint(prev.getEndPoint()),
mousePos
) >
calculateDistanceFromPointToLine(
cur.localToCanvasPoint(cur.getStartPoint()),
cur.localToCanvasPoint(cur.getEndPoint()),
mousePos
)
);
const curDistance = calculateDistanceFromPointToLine(
cur.localToCanvasPoint(cur.getStartPoint()),
cur.localToCanvasPoint(cur.getEndPoint()),
mousePos
);
return prevDistance > curDistance ||
(prevDistance == curDistance &&
distance2(
prev.localToCanvasPoint(prev.getStartPoint()),
mousePos
) >
distance2(
cur.localToCanvasPoint(cur.getStartPoint()),
mousePos
))
? cur
: prev;
});