Skip to content

Commit

Permalink
upd: multi in socket line selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 9, 2023
1 parent f391515 commit c5343c6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/visual-flow/src/components/socket/MultiInSocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Point } from "../..";
import { Direction, Point } from "../..";
import { Line, Socket } from "../../model";
import { socketCtors } from "../../recorder";

Expand Down Expand Up @@ -47,10 +47,25 @@ export class MultiInSocket extends Socket {
let nearestLineDeltaTheta = Infinity;
let nearestLine = this.connectedLines[0];
for (const line of this.connectedLines) {
const { x: lineDx, y: lineDy } = Point.minus(
let { x: lineDx, y: lineDy } = Point.minus(
line.a.boardPos,
this.boardPos,
);
switch (this.direction) {
case Direction.LEFT:
lineDx = -Math.abs(lineDx);
break;
case Direction.RIGHT:
lineDx = Math.abs(lineDx);
break;
case Direction.TOP:
lineDy = -Math.abs(lineDy);
break;
case Direction.BOTTOM:
lineDy = Math.abs(lineDy);
break;
}

const theta = Math.atan2(lineDy, lineDx);
const deltaTheta = Math.abs(theta - theta0);
if (deltaTheta < nearestLineDeltaTheta) {
Expand Down

0 comments on commit c5343c6

Please sign in to comment.