amosproj / amos2021ws01-geo-data-search

Natural language and buzzword search on routing and places
MIT License
3 stars 1 forks source link

Algorithm for route lengths #176

Closed oliviadargel closed 2 years ago

oliviadargel commented 2 years ago

User story

  1. As a user
  2. I want to search for routes with a minimal or maximal length
  3. So that I can plan test drives

Acceptance criteria

Definition of done

chrisjherm commented 2 years ago

`

   request := {MIN_DISTANCE, MAX_DISTANCE}

   requestedDistance := {1,2,3,4...}

   Route giveMeMyRoute(request, requestedDistance){

          // 1km difference in Coordinates
          const ONE_KM_DIFF = 0.015060
          requestDistanceInCoordinates = ONE_KM_DIFF x requestedDistance

          Direction[] capitalDir = {North,East,South,West}
          Coordinates userPos = getCurrentUserCoordinates() // or other defined starting point
          Route[] potentialRoutes

          for(Direction dir: capitalDir){
                 // calculates new coordinate from our starting point in the current direction with the given distance
                 Coordinate potentialDestination = (tryToFindNewLocationFromHere(userPos, requestDistanceInCoordinates, dir))
                 if(hereApi.checkIfRoutingIsPossible(potentialDestination)){
                        Route potentialRoute = hereApi.calculatePotentialRoute(userPos, potentialDestination)
                        potentialRoutes.add(potentialRoute)
                 }
          }

          if(request.equals(MIN_DISTANCE)){
                 for(Route current: potentialRoutes){
                        if(checkIfDistanceIsAtLeast(current, requestedDistance)){
                               return current
                        }
                 }
                 return giveMeMyRoute(request, requestedDistance + 1)
          }else if(request.equals(MAX_DISTANCE)){
                 for(Route current: potentialRoutes){
                        if(checkIfDistanceIsAtMost(current, requestedDistance)){
                               return current
                        }
                 }
                 return giveMeMyRoute(request, requestedDistance - 1)
          }else{
                 throw Error(unknown request)
          }
   }

`

chrisjherm commented 2 years ago

Alternative: Direction[] capitalDir = {N,NE,E,SE,S,SW,W,NW}