From 0b7c35dbead8a32de99439f55b03548419850c0a Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Fri, 10 Nov 2023 15:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E7=90=86=E5=8C=BA=E6=AE=B5=E7=9A=84Li?= =?UTF-8?q?nkRange=E7=9A=84start=E4=B8=80=E5=AE=9A=E5=B0=8F=E4=BA=8Eend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/physical_section.go | 15 ++++++++++----- repository/repository_manager.go | 24 ++++-------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/repository/physical_section.go b/repository/physical_section.go index f9a19c1..8244e06 100644 --- a/repository/physical_section.go +++ b/repository/physical_section.go @@ -3,8 +3,8 @@ package repository import ( "errors" "fmt" - "joylink.club/rtsssimulation/repository/model/proto" + "joylink.club/rtsssimulation/util/number" ) // 物理区段 @@ -30,10 +30,7 @@ type PhysicalSection struct { //aKm/bKm对应的LinkPosition aLinkPosition *LinkPosition bLinkPosition *LinkPosition - ////在Link上的区间(根据aKm和bKm计算出的,start的offset一定小于end的offset) - //startLinkPosition *LinkPosition - //endLinkPosition *LinkPosition - //在Link上的区间 + //在Link上的区间(start小于end) linkRanges []*LinkRange //物理区段所属集中站 @@ -46,6 +43,14 @@ func NewPhysicalSection(id string) *PhysicalSection { } } +func (p *PhysicalSection) bindLinkRange(link *Link, one int64, two int64) { + p.linkRanges = append(p.linkRanges, &LinkRange{ + link: link, + start: number.Min(one, two), + end: number.Max(one, two), + }) +} + func (s *PhysicalSection) PortNum() int { return 2 } diff --git a/repository/repository_manager.go b/repository/repository_manager.go index 0163bf9..731fc68 100644 --- a/repository/repository_manager.go +++ b/repository/repository_manager.go @@ -686,11 +686,7 @@ func relatePhysicalSectionAndLink(repo *Repository, section *PhysicalSection, li link: link, offset: bOffset, } - section.linkRanges = append(section.linkRanges, &LinkRange{ - link: link, - start: aOffset, - end: bOffset, - }) + section.bindLinkRange(link, aOffset, bOffset) } func getATurnoutPort(turnouts []*Turnout, visitedTurnoutMap map[string]bool) *TurnoutPort { @@ -764,31 +760,19 @@ func buildLinkRangeOfTurnoutPhysicalSection(link *Link) { //解决[两道岔的道岔物理区段,两道岔间的Link会产生两个LinkRange]的问题 if link.aRelation != nil && link.bRelation != nil && link.aRelation.turnout.section == link.bRelation.turnout.section { section := link.aRelation.turnout.section - section.linkRanges = append(section.linkRanges, &LinkRange{ - link: link, - start: 0, - end: link.length, - }) + section.bindLinkRange(link, 0, link.length) return } if link.aRelation != nil { aSection := link.aRelation.turnout.section //Link A端的关联的道岔物理区段 aLinkPosition := link.aRelation.turnout.FindLinkPositionByPort(link.aRelation.port) //Link A端道岔端点在Link上的位置 - aSection.linkRanges = append(aSection.linkRanges, &LinkRange{ - link: link, - start: 0, - end: aLinkPosition.offset, - }) + aSection.bindLinkRange(link, 0, aLinkPosition.offset) } if link.bRelation != nil { bSection := link.bRelation.turnout.section //Link A端的关联的道岔物理区段 bLinkPosition := link.bRelation.turnout.FindLinkPositionByPort(link.bRelation.port) //Link A端道岔端点在Link上的位置 - bSection.linkRanges = append(bSection.linkRanges, &LinkRange{ - link: link, - start: link.length, - end: bLinkPosition.offset, - }) + bSection.bindLinkRange(link, bLinkPosition.offset, link.length) } }