From 7b06dee5be47e8d63517a40f3113ec5f576cf890 Mon Sep 17 00:00:00 2001 From: joylink_fanyuhong <18706759286@163.com> Date: Mon, 23 Sep 2024 13:55:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=85=B3=E8=81=94=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphics/section/Section.ts | 11 +++-- src/graphics/turnout/Turnout.ts | 88 +++++++++++++++++---------------- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/graphics/section/Section.ts b/src/graphics/section/Section.ts index d1e7ab3..a2586d4 100644 --- a/src/graphics/section/Section.ts +++ b/src/graphics/section/Section.ts @@ -8,7 +8,6 @@ import { distance2, splitLineEvenly, ILineGraphic, - epsilon, Vector2, } from 'jl-graphic'; import { @@ -29,6 +28,8 @@ export enum SectionPort { B = 'B', } +const sectionEpsilon = 0.1; + export interface ISectionData extends GraphicData { get code(): string; // 编号 set code(v: string); @@ -244,7 +245,7 @@ export class Section extends JlGraphic implements ILineGraphic { distance2( this.localToCanvasPoint(this.getStartPoint()), section.localToCanvasPoint(section.getStartPoint()) - ) <= epsilon + ) <= sectionEpsilon ) { param = [SectionPort.A, SectionPort.A]; } @@ -252,7 +253,7 @@ export class Section extends JlGraphic implements ILineGraphic { distance2( this.localToCanvasPoint(this.getEndPoint()), section.localToCanvasPoint(section.getStartPoint()) - ) <= epsilon + ) <= sectionEpsilon ) { param = [SectionPort.B, SectionPort.A]; } @@ -260,7 +261,7 @@ export class Section extends JlGraphic implements ILineGraphic { distance2( this.localToCanvasPoint(this.getStartPoint()), section.localToCanvasPoint(section.getEndPoint()) - ) <= epsilon + ) <= sectionEpsilon ) { param = [SectionPort.A, SectionPort.B]; } @@ -268,7 +269,7 @@ export class Section extends JlGraphic implements ILineGraphic { distance2( this.localToCanvasPoint(this.getEndPoint()), section.localToCanvasPoint(section.getEndPoint()) - ) <= epsilon + ) <= sectionEpsilon ) { param = [SectionPort.B, SectionPort.B]; } diff --git a/src/graphics/turnout/Turnout.ts b/src/graphics/turnout/Turnout.ts index 3075798..ef06875 100644 --- a/src/graphics/turnout/Turnout.ts +++ b/src/graphics/turnout/Turnout.ts @@ -10,7 +10,6 @@ import { angleOfIncludedAngle, distance2, getParallelOfPolyline, - epsilon, Vector2, } from 'jl-graphic'; import { Section, SectionPort, SectionType } from '../section/Section'; @@ -22,6 +21,7 @@ import { import { KilometerSystem } from '../signal/Signal'; import { Station } from '../station/Station'; +const turnoutEpsilon = 0.1; export interface ITurnoutData extends GraphicData { get code(): string; set code(code: string); @@ -541,47 +541,45 @@ export class Turnout extends JlGraphic { buildRelation(): void { this.relationManage.deleteRelationOfGraphic(this); - /** 道岔和区段 */ - this.queryStore.queryByType
(Section.Type) - .forEach((section) => { - if (section.datas.sectionType === SectionType.TurnoutPhysical) { - if (section.datas.children.includes(this.datas.id)) { - this.relationManage.addRelation(this, section) - } - return + this.queryStore.queryByType
(Section.Type).forEach((section) => { + if (section.datas.sectionType === SectionType.TurnoutPhysical) { + if (section.datas.children.includes(this.datas.id)) { + this.relationManage.addRelation(this, section); + } + return; + } + this.getPortPoints().forEach((port, i) => { + if ( + distance2( + section.localToCanvasPoint(section.getStartPoint()), + this.localToCanvasPoint(port[port.length - 1]) + ) <= turnoutEpsilon + ) { + this.relationManage.addRelation( + new GraphicRelationParam( + this, + [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] + ), + new GraphicRelationParam(section, SectionPort.A) + ); + } + if ( + distance2( + section.localToCanvasPoint(section.getEndPoint()), + this.localToCanvasPoint(port[port.length - 1]) + ) <= turnoutEpsilon + ) { + this.relationManage.addRelation( + new GraphicRelationParam( + this, + [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] + ), + new GraphicRelationParam(section, SectionPort.B) + ); } - this.getPortPoints().forEach((port, i) => { - if ( - distance2( - section.localToCanvasPoint(section.getStartPoint()), - this.localToCanvasPoint(port[port.length - 1]) - ) <= epsilon - ) { - this.relationManage.addRelation( - new GraphicRelationParam( - this, - [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] - ), - new GraphicRelationParam(section, SectionPort.A) - ); - } - if ( - distance2( - section.localToCanvasPoint(section.getEndPoint()), - this.localToCanvasPoint(port[port.length - 1]) - ) <= epsilon - ) { - this.relationManage.addRelation( - new GraphicRelationParam( - this, - [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] - ), - new GraphicRelationParam(section, SectionPort.B) - ); - } - }); }); + }); /** 道岔和道岔 */ this.getPortPoints().forEach((thisPort, i) => { @@ -594,7 +592,7 @@ export class Turnout extends JlGraphic { distance2( this.localToCanvasPoint(thisPort[thisPort.length - 1]), turnout.localToCanvasPoint(otherPort[otherPort.length - 1]) - ) <= epsilon + ) <= turnoutEpsilon ) { const angle = angleOfIncludedAngle( this.localToCanvasPoint(thisPort[thisPort.length - 1]) /* 交点 */, @@ -668,9 +666,13 @@ export class Turnout extends JlGraphic { const pcRelation = this.relationManage .getRelationsOfGraphic(this) .find( - (relation) => relation.getRelationParam(this).param === TurnoutPort.C - && (!(relation.getOtherGraphic(this) instanceof Section - && relation.getOtherGraphic
(this).datas.sectionType !== SectionType.TurnoutPhysical)) + (relation) => + relation.getRelationParam(this).param === TurnoutPort.C && + !( + relation.getOtherGraphic(this) instanceof Section && + relation.getOtherGraphic
(this).datas.sectionType !== + SectionType.TurnoutPhysical + ) ); const pcDevice = pcRelation?.getOtherGraphic
(this); if (pcDevice) {