#include "location_internal.h"
+//LCOV_EXCL_START
static void __free_position_list(gpointer data)
{
if (data == NULL)
LocationPosition *position = (LocationPosition *) data;
location_position_free(position);
}
+//LCOV_EXCL_STOP
static location_bounds_type_e __convert_bounds_type(LocationBoundaryType type)
{
location_bounds_type_e ret;
switch (type) {
- case LOCATION_BOUNDARY_CIRCLE:
- ret = LOCATION_BOUNDS_CIRCLE;
- break;
- case LOCATION_BOUNDARY_POLYGON:
- ret = LOCATION_BOUNDS_POLYGON;
- break;
- case LOCATION_BOUNDARY_NONE:
- case LOCATION_BOUNDARY_RECT:
- default:
- ret = LOCATION_BOUNDS_RECT;
- break;
+ case LOCATION_BOUNDARY_CIRCLE:
+ ret = LOCATION_BOUNDS_CIRCLE;
+ break;
+ case LOCATION_BOUNDARY_POLYGON:
+ ret = LOCATION_BOUNDS_POLYGON;
+ break;
+ case LOCATION_BOUNDARY_NONE:
+ case LOCATION_BOUNDARY_RECT:
+ default:
+ ret = LOCATION_BOUNDS_RECT;
+ break;
}
return ret;
}
LOCATIONS_CHECK_CONDITION(bottom_right.longitude >= -180 && bottom_right.longitude <= 180, LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER");
if ((bottom_right.longitude - top_left.longitude) < 180 && (bottom_right.longitude - top_left.longitude) > -180) {
- if (bottom_right.longitude <= top_left.longitude || bottom_right.latitude >= top_left.latitude) {
+ if (bottom_right.longitude <= top_left.longitude || bottom_right.latitude >= top_left.latitude)
return LOCATION_BOUNDS_ERROR_INVALID_PARAMETER;
- }
} else {
- if (bottom_right.latitude >= top_left.latitude) {
+ if (bottom_right.latitude >= top_left.latitude)
return LOCATION_BOUNDS_ERROR_INVALID_PARAMETER;
- }
}
LocationPosition *lt = location_position_new(0, top_left.latitude, top_left.longitude, 0, LOCATION_STATUS_2D_FIX);
if (lt == 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);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
LocationPosition *rb = location_position_new(0, bottom_right.latitude, bottom_right.longitude, 0, LOCATION_STATUS_2D_FIX);
if (rb == 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);
location_position_free(lt);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
location_bounds_s *handle = (location_bounds_s *) malloc(sizeof(location_bounds_s));
if (handle == NULL) {
+ //LCOV_EXCL_START
LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
location_position_free(rb);
location_position_free(lt);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
memset(handle, 0, sizeof(location_bounds_s));
location_position_free(rb);
location_position_free(lt);
if (handle->boundary == NULL) {
+ //LCOV_EXCL_START
LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_rect", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
free(handle);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
*bounds = (location_bounds_h) handle;
LocationPosition *ct = location_position_new(0, center.latitude, center.longitude, 0, LOCATION_STATUS_2D_FIX);
if (ct == 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);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
location_bounds_s *handle = (location_bounds_s *) malloc(sizeof(location_bounds_s));
if (handle == NULL) {
+ //LCOV_EXCL_START
LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
location_position_free(ct);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
memset(handle, 0, sizeof(location_bounds_s));
handle->boundary = location_boundary_new_for_circle(ct, radius);
location_position_free(ct);
if (handle->boundary == NULL) {
+ //LCOV_EXCL_START
free(handle);
LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_circle", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
*bounds = (location_bounds_h) handle;
}
if (position_list == 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);
g_list_free_full(position_list, (GDestroyNotify) __free_position_list);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
location_bounds_s *handle = (location_bounds_s *) malloc(sizeof(location_bounds_s));
if (handle == NULL) {
+ //LCOV_EXCL_START
LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
memset(handle, 0, sizeof(location_bounds_s));
handle->is_added = FALSE;
handle->boundary = location_boundary_new_for_polygon(position_list);
if (handle->boundary == NULL) {
+ //LCOV_EXCL_START
free(handle);
LOCATIONS_LOGE("LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to location_boundary_new_for_polygon", LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY);
return LOCATION_BOUNDS_ERROR_OUT_OF_MEMORY;
+ //LCOV_EXCL_STOP
}
*bounds = (location_bounds_h) handle;
EXPORT_API bool location_bounds_contains_coordinates(location_bounds_h bounds, location_coords_s coords)
{
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) {
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 is_inside = location_boundary_if_inside(handle->boundary, pos);
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());