2024-07-04 20:16:10 +08:00
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
2024-07-10 18:09:16 +08:00
|
|
|
|
// 公里标
|
|
|
|
|
// 类似地铁线路一般正线都是双线,公里标一般以类似YDK/ZDK开头,
|
|
|
|
|
// 虽然从信号布置图上看,YDK/ZDK相近位置的值似乎是一样的,以为他们是同一个坐标系,
|
|
|
|
|
// 但这种情况的原因其实是因为两条线的起始点很接近,他们依然是两个独立的坐标系。
|
|
|
|
|
// 左线和右线中间有渡线可以相互切换,但公里标如何转换暂时不清楚,
|
|
|
|
|
// 暂时考虑先通过添加转换配置来实现(比如转换可以配置0或根据道岔处勾股定理大概估算,虽然不同道岔处可能不一样,但暂时不考虑复杂情况)。
|
2024-07-04 20:16:10 +08:00
|
|
|
|
type KilometerMark struct {
|
|
|
|
|
// 公里标坐标系
|
|
|
|
|
coordinate string
|
|
|
|
|
// 公里标值
|
|
|
|
|
value int64
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 18:09:16 +08:00
|
|
|
|
func NewKilometerMark(coordinate string, value int64) *KilometerMark {
|
2024-07-04 20:16:10 +08:00
|
|
|
|
return &KilometerMark{
|
|
|
|
|
coordinate: coordinate,
|
|
|
|
|
value: value,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (km *KilometerMark) Coordinate() string {
|
|
|
|
|
return km.coordinate
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 19:47:30 +08:00
|
|
|
|
func (km *KilometerMark) Value() int64 {
|
|
|
|
|
return km.value
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 20:16:10 +08:00
|
|
|
|
// 是否为同一坐标系
|
|
|
|
|
func (km *KilometerMark) IsCoordinateEqual(coordinate string) bool {
|
|
|
|
|
return km.coordinate == coordinate
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 公里标转换配置
|
|
|
|
|
type KilometerMarkConverter struct {
|
2024-07-10 18:09:16 +08:00
|
|
|
|
km1 *KilometerMark
|
|
|
|
|
km2 *KilometerMark
|
2024-07-04 20:16:10 +08:00
|
|
|
|
// 趋势是否相同
|
|
|
|
|
trendSame bool
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 18:09:16 +08:00
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 20:16:10 +08:00
|
|
|
|
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
|
|
|
|
|
}
|