[修改]区段、Link、运营方向/位置之间互相转换的函数的bug
This commit is contained in:
parent
59520435d2
commit
b3270c5921
@ -1 +1 @@
|
||||
Subproject commit a613ac109bd53528c867975d5fc6493c00d99fc2
|
||||
Subproject commit 468cc7896408951a5627777aa862a58716642317
|
@ -7,36 +7,52 @@ import (
|
||||
"joylink.club/rtsssimulation/util/number"
|
||||
)
|
||||
|
||||
// LinkRadialToSectionRadialAndOperationDir Link射线转区段射线+运营方向
|
||||
func LinkRadialToSectionRadialAndOperationDir(repo *repository.Repository, linkPosition *repository.LinkPosition, toBig bool) (sr *SectionRadial, up bool, err error) {
|
||||
// LinkRadialToDeviceRadial Link射线转设备(道岔/区段)射线
|
||||
func LinkRadialToDeviceRadial(repo *repository.Repository, linkPosition *repository.LinkPosition, toBig bool) (sr *DeviceRadial, err error) {
|
||||
link := linkPosition.Link()
|
||||
offset := linkPosition.Offset()
|
||||
if offset > link.Length() {
|
||||
return nil, false, errors.New(fmt.Sprintf("%d超出%s范围", offset, linkPosition.String()))
|
||||
return nil, errors.New(fmt.Sprintf("%d超出%s范围", offset, linkPosition.String()))
|
||||
}
|
||||
for _, section := range link.GetAllPhysicalSection() {
|
||||
//先遍历所有的非道岔计轴区段
|
||||
for _, section := range link.PhysicalSections() {
|
||||
for _, linkRange := range section.LinkRanges() {
|
||||
if linkRange.Link() != link {
|
||||
continue
|
||||
}
|
||||
if linkRange.Start() < offset && offset < linkRange.End() {
|
||||
if linkRange.Start() <= offset && offset <= linkRange.End() {
|
||||
sectionOffset := number.Abs(offset - section.ALinkPosition().Offset())
|
||||
toB := toBig && section.BLinkPosition().Offset() > section.ALinkPosition().Offset()
|
||||
sr = &SectionRadial{
|
||||
Section: section,
|
||||
Offset: sectionOffset,
|
||||
ToB: toB,
|
||||
aKm := convertRepoBaseKm(repo, section.AKilometer())
|
||||
bKm := convertRepoBaseKm(repo, section.BKilometer())
|
||||
runDirection := toB == (bKm.Value > aKm.Value)
|
||||
sr = &DeviceRadial{
|
||||
DeviceId: section.Id(),
|
||||
Offset: sectionOffset,
|
||||
PointTo: toB,
|
||||
RunDirection: runDirection,
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if sr == nil {
|
||||
return nil, false, errors.New(fmt.Sprintf("%s未找到对应的区段", linkPosition.String()))
|
||||
if sr != nil {
|
||||
return sr, nil
|
||||
}
|
||||
//Link位置不在非道岔计轴区段上
|
||||
aLinkPosition := link.ARelation().Turnout().FindLinkPositionByPort(link.ARelation().Port())
|
||||
if aLinkPosition.Offset() >= offset { //LinkPosition在A端道岔范围内
|
||||
pointTo := !toBig
|
||||
portKm := convertRepoBaseKm(repo, link.ARelation().Turnout().GetTurnoutKm(link.ARelation().Port()))
|
||||
km := convertRepoBaseKm(repo, link.ARelation().Turnout().Km())
|
||||
runDir := pointTo == (km.Value > portKm.Value)
|
||||
sr = &DeviceRadial{
|
||||
DeviceId: link.ARelation().Turnout().Id(),
|
||||
Offset: offset,
|
||||
PointTo: !toBig,
|
||||
RunDirection: runDir,
|
||||
}
|
||||
}
|
||||
aKm := convertRepoBaseKm(repo, sr.Section.AKilometer())
|
||||
bKm := convertRepoBaseKm(repo, sr.Section.BKilometer())
|
||||
up = sr.ToB && bKm.Value > aKm.Value
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
@ -68,7 +84,7 @@ func OperationRadialToLinkRadial(repo *repository.Repository, section *repositor
|
||||
func SectionDirToLinkDir(section *repository.PhysicalSection, toB bool) (toBig bool) {
|
||||
aOffset := section.ALinkPosition().Offset()
|
||||
bOffset := section.BLinkPosition().Offset()
|
||||
toBig = toB && bOffset > aOffset
|
||||
toBig = toB == (bOffset > aOffset)
|
||||
return
|
||||
}
|
||||
|
||||
@ -76,14 +92,14 @@ func SectionDirToLinkDir(section *repository.PhysicalSection, toB bool) (toBig b
|
||||
func SectionDirToOperationDir(repo *repository.Repository, section *repository.PhysicalSection, toB bool) (up bool) {
|
||||
aKm := convertRepoBaseKm(repo, section.AKilometer())
|
||||
bKm := convertRepoBaseKm(repo, section.BKilometer())
|
||||
return toB && bKm.Value > aKm.Value
|
||||
return toB == (bKm.Value > aKm.Value)
|
||||
}
|
||||
|
||||
// OperationDirToSectionDir 运营方向转区段方向
|
||||
func OperationDirToSectionDir(repo *repository.Repository, section *repository.PhysicalSection, up bool) (toB bool) {
|
||||
aKm := convertRepoBaseKm(repo, section.AKilometer())
|
||||
bKm := convertRepoBaseKm(repo, section.BKilometer())
|
||||
return up && bKm.Value > aKm.Value
|
||||
return up == (bKm.Value > aKm.Value)
|
||||
}
|
||||
|
||||
// OperationDirToLinkDir 运营方向转Link方向
|
||||
@ -99,3 +115,11 @@ type SectionRadial struct {
|
||||
Offset int64
|
||||
ToB bool
|
||||
}
|
||||
|
||||
// DeviceRadial 设备射线,包含一个设备位置+方向
|
||||
type DeviceRadial struct {
|
||||
DeviceId string //区段或道岔
|
||||
Offset int64 //在设备上的偏移量
|
||||
PointTo bool //与TrainState结构体中同义。区段:A->B,道岔:->岔心
|
||||
RunDirection bool //与TrainState结构体中同义。公里标 上行:小 -> 大,下行:大 -> 小
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user