Skip to content

Commit

Permalink
Use GeomCache interface instead of direct access (#350)
Browse files Browse the repository at this point in the history
* Use GeomCache interface instead of direct access
  • Loading branch information
irees committed Jul 16, 2024
1 parent 61217a2 commit 268c6b1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion copier/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/interline-io/transitland-lib/tl/causes"
"github.com/interline-io/transitland-lib/tl/tt"
"github.com/interline-io/transitland-lib/tlcsv"
"github.com/interline-io/transitland-lib/tlxy"
"github.com/rs/zerolog"
"github.com/twpayne/go-geom/xy"
)
Expand Down Expand Up @@ -68,7 +69,7 @@ type errorWithContext interface {
}

type canShareGeomCache interface {
SetGeomCache(*geomcache.GeomCache)
SetGeomCache(tlxy.GeomCache)
}

type hasLine interface {
Expand Down
4 changes: 2 additions & 2 deletions rt/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Validator struct {
tripInfo map[string]tripInfo
routeInfo map[string]routeInfo
stopInfo map[string]stopInfo
geomCache *geomcache.GeomCache // shared with copier
geomCache tlxy.GeomCache // shared with copier
sched *sched.ScheduleChecker
}

Expand All @@ -61,7 +61,7 @@ func NewValidator() *Validator {
}

// SetGeomCache sets a shared geometry cache.
func (fi *Validator) SetGeomCache(g *geomcache.GeomCache) {
func (fi *Validator) SetGeomCache(g tlxy.GeomCache) {
fi.geomCache = g
}

Expand Down
9 changes: 4 additions & 5 deletions rules/fast_travel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rules
import (
"fmt"

"github.com/interline-io/transitland-lib/internal/geomcache"
"github.com/interline-io/transitland-lib/tl"
"github.com/interline-io/transitland-lib/tlxy"
)
Expand Down Expand Up @@ -62,13 +61,13 @@ var maxSpeeds = map[int]float64{

// StopTimeFastTravelCheck checks for FastTravelErrors.
type StopTimeFastTravelCheck struct {
routeTypes map[string]int // keep track of route_types
stopDist map[string]float64 // cache stop-to-stop distances
geomCache *geomcache.GeomCache // share with copier
routeTypes map[string]int // keep track of route_types
stopDist map[string]float64 // cache stop-to-stop distances
geomCache tlxy.GeomCache // share with copier
}

// SetGeomCache sets a shared geometry cache.
func (e *StopTimeFastTravelCheck) SetGeomCache(g *geomcache.GeomCache) {
func (e *StopTimeFastTravelCheck) SetGeomCache(g tlxy.GeomCache) {
e.geomCache = g
}

Expand Down
5 changes: 2 additions & 3 deletions rules/too_far_from_shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rules
import (
"fmt"

"github.com/interline-io/transitland-lib/internal/geomcache"
"github.com/interline-io/transitland-lib/tl"
"github.com/interline-io/transitland-lib/tlxy"
)
Expand All @@ -24,12 +23,12 @@ func (e *StopTooFarFromShapeError) Error() string {
// StopTooFarFromShapeCheck checks for StopTooFarFromShapeErrors.
type StopTooFarFromShapeCheck struct {
maxdist float64
geomCache *geomcache.GeomCache // share stop/shape geometry cache with copier
geomCache tlxy.GeomCache // share stop/shape geometry cache with copier
checked map[string]map[string]bool
}

// SetGeomCache sets a shared geometry cache.
func (e *StopTooFarFromShapeCheck) SetGeomCache(g *geomcache.GeomCache) {
func (e *StopTooFarFromShapeCheck) SetGeomCache(g tlxy.GeomCache) {
e.geomCache = g
}

Expand Down
7 changes: 7 additions & 0 deletions tlxy/xy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import (
"math"
)

type GeomCache interface {
GetStop(string) Point
GetShape(eid string) []Point
}

// Simple XY geometry helper functions.

const latMeter = 111195.0662709627
const epsilon = 1e-6
const earthRadiusMetres float64 = 6371008
Expand Down

0 comments on commit 268c6b1

Please sign in to comment.