Addition of API location_bounds_contains_coordinates_on_edge 03/238903/1 submit/tizen_5.5/20200720.062215
authorchakradhar pogiri <v.pogiri@samsung.com>
Mon, 20 Jul 2020 06:13:08 +0000 (11:43 +0530)
committerchakradhar pogiri <v.pogiri@samsung.com>
Mon, 20 Jul 2020 06:13:08 +0000 (11:43 +0530)
Change-Id: I807b8f4e99daef61ca3d12f9c4ebe87f150101a1

include/location_bounds.h
src/location_bounds.c
src/locations.c

index 254f7156deddf4a66f1aae9803c6baa2c7e5567b..d2326a8b93ffbee17c847ac63b441e7125c782da 100644 (file)
@@ -187,6 +187,22 @@ int location_bounds_create_polygon(location_coords_s *coords_list, int length, l
  */
 bool location_bounds_contains_coordinates(location_bounds_h bounds, location_coords_s coords);
 
+/**
+ * @brief Checks whether the edges of the bounds contain the specified coordinates within tolerance.
+ * @param[in] bounds The location bounds handle
+ * @param[in] coords The coordinates
+ * @param[in] tolerance tolerance in metres
+ * @return @c true if the edges of the bounds contain the specified coordinates within tolerance,
+ *         otherwise else @c false
+ * @exception #LOCATION_BOUNDS_ERROR_NONE Successful
+ * @exception #LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY Out of memory
+ * @exception #LOCATION_BOUNDS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception #LOCATION_BOUNDS_ERROR_NOT_SUPPORTED Not supported
+ * @see location_bounds_create_rect()
+ * @see location_bounds_create_circle()
+ * @see location_bounds_create_polygon()
+ */
+bool location_bounds_contains_coordinates_on_edge(location_bounds_h bounds, location_coords_s coords, double tolerance);
 
 /**
  * @brief Gets the type of location bounds.
index 3106db01f6c42079607e390079c3b1356f252fa1..b4c0433ee2cfe28a997c8491b507a21330bbe40c 100644 (file)
@@ -252,6 +252,47 @@ EXPORT_API bool location_bounds_contains_coordinates(location_bounds_h bounds, l
        return result;
 }
 
+EXPORT_API bool location_bounds_contains_coordinates_on_edge(location_bounds_h bounds, location_coords_s coords, double tolerance)
+{
+       if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
+               //LCOV_EXCL_START
+               set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
+               return FALSE;
+               //LCOV_EXCL_STOP
+       }
+
+       if (!bounds) {
+               set_last_result(LOCATION_BOUNDS_ERROR_INVALID_PARAMETER);
+               return FALSE;
+       }
+
+       if (coords.latitude < -90 || coords.latitude > 90 || coords.longitude < -180 || coords.longitude > 180) {
+               set_last_result(LOCATION_BOUNDS_ERROR_INVALID_PARAMETER);
+               return FALSE;
+       }
+
+       if (tolerance < 0.0) {
+               set_last_result(LOCATION_BOUNDS_ERROR_INVALID_PARAMETER);
+               return FALSE;
+       }
+
+       LocationPosition *pos = location_position_new(0, coords.latitude, coords.longitude, 0, LOCATION_STATUS_2D_FIX);
+       if (pos == NULL) {
+               //LCOV_EXCL_START
+               LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_position_new", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+               set_last_result(LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
+               return FALSE;
+               //LCOV_EXCL_STOP
+       }
+       location_bounds_s *handle = (location_bounds_s *) bounds;
+       gboolean on_path = location_boundary_on_path(handle->boundary, pos, tolerance);
+       location_position_free(pos);
+       bool result = on_path ? TRUE : FALSE;
+
+       set_last_result(LOCATION_BOUNDS_ERROR_NONE);
+       return result;
+}
+
 EXPORT_API int location_bounds_get_type(location_bounds_h bounds, location_bounds_type_e *type)
 {
        LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
index 942f4c1b8a3f6394a59f4512a4786564598798de..18d86e711bc1edef429ffddaa74ca691bf18a97d 100755 (executable)
@@ -1239,7 +1239,7 @@ EXPORT_API int location_manager_get_distance(double start_latitude, double start
        LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
 
        int ret = LOCATION_ERROR_NONE;
-       ulong u_distance;
+       double u_distance;
 
        LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
        LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
@@ -1250,7 +1250,7 @@ EXPORT_API int location_manager_get_distance(double start_latitude, double start
        if (ret != LOCATION_ERROR_NONE)
                return __convert_error_code(ret);       //LCOV_EXCL_LINE
 
-       *distance = (double)u_distance;
+       *distance = u_distance;
 
        return LOCATIONS_ERROR_NONE;
 }