Skip to content

Commit

Permalink
used named return values
Browse files Browse the repository at this point in the history
  • Loading branch information
brchri committed Aug 6, 2023
1 parent cd79d99 commit c868e80
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions internal/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func CheckGeoFence(config util.ConfigStruct, car *util.Car) {
}

// gets action based on if there was a relevant distance change
func getDistanceChangeAction(config util.ConfigStruct, car *util.Car) string {
func getDistanceChangeAction(config util.ConfigStruct, car *util.Car) (action string) {
if car.CurLat == 0 || car.CurLng == 0 {
return "" // need valid lat and lng to check fence
return // need valid lat and lng to check fence
}

// Define a carLocation to check
Expand All @@ -126,26 +126,24 @@ func getDistanceChangeAction(config util.ConfigStruct, car *util.Car) string {
car.CurDistance = distance(carLocation, car.GarageDoor.CircularGeofence.Center)

// check if car has crossed a geofence and set an appropriate action
var action string
if prevDistance <= car.GarageDoor.CircularGeofence.CloseDistance && car.CurDistance > car.GarageDoor.CircularGeofence.CloseDistance { // car was within close geofence, but now beyond it (car left geofence)
action = myq.ActionClose
} else if prevDistance >= car.GarageDoor.CircularGeofence.OpenDistance && car.CurDistance < car.GarageDoor.CircularGeofence.OpenDistance { // car was outside of open geofence, but is now within it (car entered geofence)
action = myq.ActionOpen
}
return action
return
}

// gets action based on if there was a relevant geofence event change
func getGeoChangeEventAction(config util.ConfigStruct, car *util.Car) string {
var action string
func getGeoChangeEventAction(config util.ConfigStruct, car *util.Car) (action string) {
if car.PrevGeofence == car.GarageDoor.TeslamateGeofence.Close.From &&
car.CurGeofence == car.GarageDoor.TeslamateGeofence.Close.To {
action = "close"
} else if car.PrevGeofence == car.GarageDoor.TeslamateGeofence.Open.From &&
car.CurGeofence == car.GarageDoor.TeslamateGeofence.Open.To {
action = "open"
}
return action
return
}

// get center of polygon geofence
Expand All @@ -169,8 +167,7 @@ func SortPointsClockwise(points []util.Point) {

// get action based on whether we had a polygon geofence change event
// uses ray-casting algorithm, assumes a simple geofence (no holes or border cross points)
func getPolygonGeoChangeEventAction(config util.ConfigStruct, car *util.Car) string {
var action string
func getPolygonGeoChangeEventAction(config util.ConfigStruct, car *util.Car) (action string) {
if car.CurLat == 0 || car.CurLng == 0 {
return "" // need valid lat and long to check geofence
}
Expand All @@ -188,7 +185,7 @@ func getPolygonGeoChangeEventAction(config util.ConfigStruct, car *util.Car) str
car.InsideCloseGeo = isInsideCloseGeo
car.InsideOpenGeo = isInsideOpenGeo

return action
return
}

func isInsidePolygonGeo(p util.Point, geofence []util.Point) bool {
Expand Down

0 comments on commit c868e80

Please sign in to comment.