From c868e807f00f7e0f4040af099b28cccb5994dea8 Mon Sep 17 00:00:00 2001 From: brchri <126272303+brchri@users.noreply.github.com> Date: Sat, 5 Aug 2023 21:53:53 -0600 Subject: [PATCH] used named return values --- internal/geo/geo.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/geo/geo.go b/internal/geo/geo.go index 09445cf..14b9b24 100644 --- a/internal/geo/geo.go +++ b/internal/geo/geo.go @@ -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 @@ -126,18 +126,16 @@ 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" @@ -145,7 +143,7 @@ func getGeoChangeEventAction(config util.ConfigStruct, car *util.Car) string { car.CurGeofence == car.GarageDoor.TeslamateGeofence.Open.To { action = "open" } - return action + return } // get center of polygon geofence @@ -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 } @@ -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 {