区段复制优化
This commit is contained in:
parent
ae2e524059
commit
79f3b05f39
@ -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;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user