@@ -9,6 +9,7 @@ import { Settings } from "@/core/service/Settings";
99import { ConnectableEntity } from "@/core/stage/stageObject/abstract/ConnectableEntity" ;
1010import { ConnectPoint } from "@/core/stage/stageObject/entity/ConnectPoint" ;
1111import { ImageNode } from "@/core/stage/stageObject/entity/ImageNode" ;
12+ import { Section } from "@/core/stage/stageObject/entity/Section" ;
1213import { CursorNameEnum } from "@/types/cursors" ;
1314import { Direction } from "@/types/directions" ;
1415import { isMac } from "@/utils/platform" ;
@@ -446,21 +447,24 @@ export class ControllerNodeConnectionClass extends ControllerClass {
446447 for ( const line of lines ) {
447448 // 寻找源头端点位置
448449 for ( const fromEntity of this . connectFromEntities ) {
449- if ( fromEntity . collisionBox . isContainsPoint ( line . start ) && ! fromEntity . collisionBox . isContainsPoint ( line . end ) ) {
450+ const fromRect = fromEntity . collisionBox
451+ . getRectangle ( )
452+ . expandFromCenter ( fromEntity instanceof Section ? 15 : 0 ) ;
453+ // 起点在矩形内、且线段与矩形边界有交点(即从内部穿出)
454+ if ( fromRect . isPointIn ( line . start ) && fromRect . isCollideWithLine ( line ) ) {
450455 // 找到了出去的一小段线段
451- const rect = fromEntity . collisionBox . getRectangle ( ) ;
452- const intersectionPoint = rect . getLineIntersectionPoint ( line ) ;
456+ const intersectionPoint = fromRect . getLineIntersectionPoint ( line ) ;
453457 // 找到交点,判断交点在哪个方位上
454- if ( intersectionPoint . y === rect . top ) {
458+ if ( intersectionPoint . y === fromRect . top ) {
455459 // 从顶部发出
456460 sourceDirection = Direction . Up ;
457- } else if ( intersectionPoint . y === rect . bottom ) {
461+ } else if ( intersectionPoint . y === fromRect . bottom ) {
458462 // 从底部发出
459463 sourceDirection = Direction . Down ;
460- } else if ( intersectionPoint . x === rect . left ) {
464+ } else if ( intersectionPoint . x === fromRect . left ) {
461465 // 从左侧发出
462466 sourceDirection = Direction . Left ;
463- } else if ( intersectionPoint . x === rect . right ) {
467+ } else if ( intersectionPoint . x === fromRect . right ) {
464468 // 从右侧发出
465469 sourceDirection = Direction . Right ;
466470 }
@@ -479,41 +483,42 @@ export class ControllerNodeConnectionClass extends ControllerClass {
479483 }
480484 }
481485 // 寻找目标端点位置
482- if (
483- this . connectToEntity &&
484- this . connectToEntity . collisionBox . isContainsPoint ( line . end ) &&
485- ! this . connectToEntity . collisionBox . isContainsPoint ( line . start )
486- ) {
487- // 找到了入来的一小段线段
488- const rect = this . connectToEntity . collisionBox . getRectangle ( ) ;
489- const intersectionPoint = rect . getLineIntersectionPoint ( line ) ;
490- // 找到交点,判断交点在哪个方位上
491- if ( intersectionPoint . y === rect . top ) {
492- // 到达顶部
493- targetDirection = Direction . Up ;
494- } else if ( intersectionPoint . y === rect . bottom ) {
495- // 到达底部
496- targetDirection = Direction . Down ;
497- } else if ( intersectionPoint . x === rect . left ) {
498- // 到达左侧
499- targetDirection = Direction . Left ;
500- } else if ( intersectionPoint . x === rect . right ) {
501- // 到达右侧
502- targetDirection = Direction . Right ;
503- }
504- // 触发火花特效 - 划入目标节点
505- if ( targetDirection !== null && ! this . _hasTargetSparkTriggered ) {
506- this . _hasTargetSparkTriggered = true ;
507- // 划入时的方向与划出时相反
508- const sparkDirection = this . getOppositeDirection ( targetDirection ) ;
509- this . project . effects . addEffect (
510- new SparkBurstEffect (
511- new ProgressNumber ( 0 , 40 ) ,
512- intersectionPoint . clone ( ) ,
513- sparkDirection ,
514- this . project . stageStyleManager . currentStyle . StageObjectBorder . clone ( ) ,
515- ) ,
516- ) ;
486+ if ( this . connectToEntity ) {
487+ const toRect = this . connectToEntity . collisionBox
488+ . getRectangle ( )
489+ . expandFromCenter ( this . connectToEntity instanceof Section ? 15 : 0 ) ;
490+ // 起点不在矩形内、且线段与矩形边界有交点(即从外部穿入,包括终点刚好在边框上的情况)
491+ if ( ! toRect . isPointIn ( line . start ) && toRect . isCollideWithLine ( line ) ) {
492+ // 找到了入来的一小段线段
493+ const intersectionPoint = toRect . getLineIntersectionPoint ( line ) ;
494+ // 找到交点,判断交点在哪个方位上
495+ if ( intersectionPoint . y === toRect . top ) {
496+ // 到达顶部
497+ targetDirection = Direction . Up ;
498+ } else if ( intersectionPoint . y === toRect . bottom ) {
499+ // 到达底部
500+ targetDirection = Direction . Down ;
501+ } else if ( intersectionPoint . x === toRect . left ) {
502+ // 到达左侧
503+ targetDirection = Direction . Left ;
504+ } else if ( intersectionPoint . x === toRect . right ) {
505+ // 到达右侧
506+ targetDirection = Direction . Right ;
507+ }
508+ // 触发火花特效 - 划入目标节点
509+ if ( targetDirection !== null && ! this . _hasTargetSparkTriggered ) {
510+ this . _hasTargetSparkTriggered = true ;
511+ // 划入时的方向与划出时相反
512+ const sparkDirection = this . getOppositeDirection ( targetDirection ) ;
513+ this . project . effects . addEffect (
514+ new SparkBurstEffect (
515+ new ProgressNumber ( 0 , 40 ) ,
516+ intersectionPoint . clone ( ) ,
517+ sparkDirection ,
518+ this . project . stageStyleManager . currentStyle . StageObjectBorder . clone ( ) ,
519+ ) ,
520+ ) ;
521+ }
517522 }
518523 }
519524 }
0 commit comments