rtss-core/model/kilometer_mark.go
soul-walker 1a610c01ba 调整公里标概念,添加注释说明
完善道岔区段与道岔关系构建检查
添加Link位置和link范围工具类
完善example道岔区段关系构建
2024-07-10 18:09:16 +08:00

88 lines
2.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"fmt"
"strconv"
)
// 公里标
// 类似地铁线路一般正线都是双线公里标一般以类似YDK/ZDK开头
// 虽然从信号布置图上看YDK/ZDK相近位置的值似乎是一样的以为他们是同一个坐标系
// 但这种情况的原因其实是因为两条线的起始点很接近,他们依然是两个独立的坐标系。
// 左线和右线中间有渡线可以相互切换,但公里标如何转换暂时不清楚,
// 暂时考虑先通过添加转换配置来实现比如转换可以配置0或根据道岔处勾股定理大概估算虽然不同道岔处可能不一样但暂时不考虑复杂情况
type KilometerMark struct {
// 公里标坐标系
coordinate string
// 公里标值
value int64
}
func NewKilometerMark(coordinate string, value int64) *KilometerMark {
return &KilometerMark{
coordinate: coordinate,
value: value,
}
}
func (km *KilometerMark) Coordinate() string {
return km.coordinate
}
func (km *KilometerMark) Value() int64 {
return km.value
}
// 是否为同一坐标系
func (km *KilometerMark) IsCoordinateEqual(coordinate string) bool {
return km.coordinate == coordinate
}
// 公里标转换配置
type KilometerMarkConverter struct {
km1 *KilometerMark
km2 *KilometerMark
// 趋势是否相同
trendSame bool
}
func NewKilometerMarkConverter(km1, km2 *KilometerMark, trendSame bool) *KilometerMarkConverter {
if km1 == nil || km2 == nil {
panic("km1 or km2 is nil")
}
return &KilometerMarkConverter{
km1: km1,
km2: km2,
trendSame: trendSame,
}
}
func (kmc *KilometerMarkConverter) Debug() string {
return fmt.Sprintf("{%s<->%s(%s)}", kmc.km1.coordinate, kmc.km2.coordinate, strconv.FormatBool(kmc.trendSame))
}
func (kmc *KilometerMarkConverter) IsMatch(km *KilometerMark, coordinate2 string) bool {
coordinate1 := km.coordinate
return kmc.km1.coordinate == coordinate1 && kmc.km2.coordinate == coordinate2 ||
kmc.km1.coordinate == coordinate2 && kmc.km2.coordinate == coordinate1
}
// 将源公里标km转换为目标坐标系targetCoordinate的公里标值
func (kmc *KilometerMarkConverter) Convert(km *KilometerMark, targetCoordinate string) int64 {
var tvalue int64 = 0
if kmc.km1.IsCoordinateEqual(km.coordinate) {
if kmc.trendSame {
tvalue = km.value - kmc.km1.value + kmc.km2.value
} else {
tvalue = kmc.km1.value - km.value + kmc.km2.value
}
} else {
if kmc.trendSame {
tvalue = km.value - kmc.km2.value + kmc.km1.value
} else {
tvalue = kmc.km2.value - km.value + kmc.km1.value
}
}
return tvalue
}