[新增]区段、Link、运营方向/位置之间互相转换的函数

This commit is contained in:
thesai 2024-05-16 21:19:53 +08:00
parent 149678b3f0
commit 59520435d2
5 changed files with 107 additions and 6 deletions

@ -1 +1 @@
Subproject commit 90003ec9429c7db26c43dd381277800d0dfd35fa
Subproject commit a613ac109bd53528c867975d5fc6493c00d99fc2

@ -1 +1 @@
Subproject commit e4c55ea4b6f9f5f875d59fc5bba51fc21bc8ef97
Subproject commit 6d3ff5644ebaad3ed1e7e6c03fcfb0f9a3427af0

View File

@ -0,0 +1,101 @@
package memory
import (
"errors"
"fmt"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/util/number"
)
// LinkRadialToSectionRadialAndOperationDir Link射线转区段射线+运营方向
func LinkRadialToSectionRadialAndOperationDir(repo *repository.Repository, linkPosition *repository.LinkPosition, toBig bool) (sr *SectionRadial, up bool, err error) {
link := linkPosition.Link()
offset := linkPosition.Offset()
if offset > link.Length() {
return nil, false, errors.New(fmt.Sprintf("%d超出%s范围", offset, linkPosition.String()))
}
for _, section := range link.GetAllPhysicalSection() {
for _, linkRange := range section.LinkRanges() {
if linkRange.Link() != link {
continue
}
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,
}
break
}
}
}
if sr == nil {
return nil, false, errors.New(fmt.Sprintf("%s未找到对应的区段", linkPosition.String()))
}
aKm := convertRepoBaseKm(repo, sr.Section.AKilometer())
bKm := convertRepoBaseKm(repo, sr.Section.BKilometer())
up = sr.ToB && bKm.Value > aKm.Value
err = nil
return
}
// SectionRadialToLinkRadial 区段射线转Link射线
func SectionRadialToLinkRadial(sectionRadial *SectionRadial) (linkPosition *repository.LinkPosition, toBig bool) {
toBig = SectionDirToLinkDir(sectionRadial.Section, sectionRadial.ToB)
var offset int64
if sectionRadial.ToB == toBig { //section与link偏移变化趋势相同
offset = sectionRadial.Section.ALinkPosition().Offset() + sectionRadial.Offset
} else {
offset = sectionRadial.Section.BLinkPosition().Offset() - sectionRadial.Offset
}
linkPosition = repository.NewLinkPosition(sectionRadial.Section.ALinkPosition().Link(), offset)
return
}
// OperationRadialToLinkRadial 运营射线转Link射线
func OperationRadialToLinkRadial(repo *repository.Repository, section *repository.PhysicalSection, offset int64, up bool) (linkPosition *repository.LinkPosition, toBig bool) {
toB := OperationDirToSectionDir(repo, section, up)
return SectionRadialToLinkRadial(&SectionRadial{
Section: section,
Offset: offset,
ToB: toB,
})
}
// SectionDirToLinkDir 区段方向转Link方向
func SectionDirToLinkDir(section *repository.PhysicalSection, toB bool) (toBig bool) {
aOffset := section.ALinkPosition().Offset()
bOffset := section.BLinkPosition().Offset()
toBig = toB && bOffset > aOffset
return
}
// SectionDirToOperationDir 区段方向转运营方向
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
}
// 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
}
// OperationDirToLinkDir 运营方向转Link方向
func OperationDirToLinkDir(repo *repository.Repository, section *repository.PhysicalSection, up bool) (toBig bool) {
toB := OperationDirToSectionDir(repo, section, up)
return SectionDirToLinkDir(section, toB)
}
// SectionRadial 区段射线。包含一个区段位置+方向
// 加这个结构体只是因为上面函数返回值过多
type SectionRadial struct {
Section *repository.PhysicalSection
Offset int64
ToB bool
}

View File

@ -243,7 +243,7 @@ func findCalcLinkIdAndOffset(sim *VerifySimulation, link *repository.Link, offse
}
// 没有找到连接信息,说明已经到尽头找不到位置
if nextLink == nil {
err = sys_error.New(fmt.Sprintf("未找到对应的link信息, linkId=%s, offset=%d", link.Id(), offset))
err = sys_error.New(fmt.Sprintf("未找到对应的link信息, linkId=%s, Offset=%d", link.Id(), offset))
return
}
// 下个link偏移
@ -297,7 +297,7 @@ func getTurnoutNextPort(sim *VerifySimulation, turnoutId string, port string) (n
return
}
// 计算link offset 在道岔上的位置
// 计算link Offset 在道岔上的位置
// 入参仿真Repository、link、是否从A端开始、link偏移量、link运行方向
// 输出设备Id、设备所在端口、设备偏移量、公里标信息地图主坐标系
func calcTurnoutOffset(repo *repository.Repository, link *repository.Link, isA bool, offset int64, up bool) (
@ -328,7 +328,7 @@ func calcTurnoutOffset(repo *repository.Repository, link *repository.Link, isA b
return
}
// 计算link offset 在区段上的位置
// 计算link Offset 在区段上的位置
// 入参仿真Repository、link、link偏移量、link运行方向
// 输出设备Id、设备所在端口、设备偏移量、公里标信息地图主坐标系
func calcSectionOffset(repo *repository.Repository, link *repository.Link, offset int64, up bool) (

View File

@ -301,7 +301,7 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
panic(sys_error.New("动力学传输数据:列车车头位置计算出错", e1))
}
runDirection, pointTo := QueryDirectionAndABByDevice(vs.Repo, id, port, info.Up)
//slog.Debug("处理动力学转换后的消息", "number", info.Number, "Link", info.Link, "车头位置", id, "偏移", offset, "是否上行", runDirection, "是否ab", pointTo)
//slog.Debug("处理动力学转换后的消息", "number", info.Number, "Link", info.Link, "车头位置", id, "偏移", Offset, "是否上行", runDirection, "是否ab", pointTo)
// 车尾相对车头link的偏移量
calctailOffset := calcTrailTailOffset(outLinkOffset, int64(info.Len), info.Up)
tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailOffset, _, e2 := CalcInitializeLink(vs, outLinkId, calctailOffset, !info.Up)