Allow start point to be within 500m of bounding box of its nearest neighbour

This commit is contained in:
Ray Miller 2020-12-14 09:49:28 +00:00
parent 617b12ff64
commit af15ee6707
3 changed files with 59 additions and 1 deletions

View file

@ -29,6 +29,16 @@ func (b *NamedBoundary) Bounds() *rtreego.Rect {
return r
}
func (b *NamedBoundary) NearEnough(p rtreego.Point, margin float64) bool {
if len(p) != 2 {
panic("Expected a 2-dimensional point")
}
return p[0] >= b.Xmin-margin &&
p[0] <= b.Xmax+margin &&
p[1] >= b.Ymin-margin &&
p[1] <= b.Ymax+margin
}
func (b *NamedBoundary) Contains(p rtreego.Point) bool {
if len(p) != 2 {
panic("Expected a 2-dimensional point")

View file

@ -125,7 +125,7 @@ func (gs *GPXSummarizer) SummarizeTrack(r io.Reader, stops *rtreego.Rtree) (*Tra
thisPoint := rtreego.Point{ngCoord.Easting, ngCoord.Northing}
nn, _ := gs.poi.NearestNeighbor(thisPoint).(*NamedBoundary)
if init {
if !nn.Contains(thisPoint) {
if !nn.NearEnough(thisPoint, 500.0) {
return nil, fmt.Errorf("start point out of range")
}
start = thisPoint