物理区段的LinkRange的start一定小于end

This commit is contained in:
joylink_zhangsai 2023-11-10 15:26:35 +08:00
parent 1ada6c5fa9
commit 0b7c35dbea
2 changed files with 14 additions and 25 deletions

View File

@ -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
}

View File

@ -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)
}
}