1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "maps_error.h"
19 #include "maps_area.h"
20 #include "maps_util.h"
21 #include "maps_condition.h"
23 extern bool maps_coordinates_is_valid(const maps_coordinates_h coordinates);
25 EXPORT_API int maps_area_create_rectangle(const maps_coordinates_h top_left,
26 const maps_coordinates_h bottom_right,
29 if (!maps_condition_check_maps_feature())
30 return MAPS_ERROR_NOT_SUPPORTED;
32 if (!top_left || !bottom_right || !area)
33 return MAPS_ERROR_INVALID_PARAMETER;
35 if (!maps_coordinates_is_valid(top_left) ||
36 !maps_coordinates_is_valid(bottom_right))
37 return MAPS_ERROR_INVALID_PARAMETER;
39 maps_area_s *bound = g_new0(maps_area_s, 1);
43 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
44 return MAPS_ERROR_OUT_OF_MEMORY;
48 bound->type = MAPS_AREA_RECTANGLE;
50 bound->rect.top_left = *((maps_coordinates_s *) top_left);
51 bound->rect.bottom_right = *((maps_coordinates_s *) bottom_right);
53 *area = (maps_area_h) bound;
55 return MAPS_ERROR_NONE;
58 EXPORT_API int maps_area_create_circle(const maps_coordinates_h center,
59 const double radius, maps_area_h *area)
61 if (!maps_condition_check_maps_feature())
62 return MAPS_ERROR_NOT_SUPPORTED;
64 if (!center || !area || radius <= 0)
65 return MAPS_ERROR_INVALID_PARAMETER;
67 if (!maps_coordinates_is_valid(center))
68 return MAPS_ERROR_INVALID_PARAMETER;
70 maps_area_s *bound = g_new0(maps_area_s, 1);
74 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
75 return MAPS_ERROR_OUT_OF_MEMORY;
79 bound->type = MAPS_AREA_CIRCLE;
80 bound->circle.center = *((maps_coordinates_s *) center);
81 bound->circle.radius = radius;
82 *area = (maps_area_h) bound;
84 return MAPS_ERROR_NONE;
87 EXPORT_API int maps_area_destroy(maps_area_h area)
89 if (!maps_condition_check_maps_feature())
90 return MAPS_ERROR_NOT_SUPPORTED;
92 return MAPS_ERROR_INVALID_PARAMETER;
94 maps_area_s *handle = (maps_area_s *) area;
96 return MAPS_ERROR_NONE;
99 EXPORT_API int maps_area_clone(const maps_area_h origin, maps_area_h *cloned)
101 if (!maps_condition_check_maps_feature())
102 return MAPS_ERROR_NOT_SUPPORTED;
103 if (!cloned || !origin)
104 return MAPS_ERROR_INVALID_PARAMETER;
106 maps_area_s * origin_handle = (maps_area_s *) origin;
107 if (origin_handle->type == MAPS_AREA_RECTANGLE) {
108 maps_area_h new_rect = NULL;
109 maps_area_rectangle_s rect = origin_handle->rect;
110 maps_coordinates_s rec_tl = rect.top_left;
111 maps_coordinates_s rec_br = rect.bottom_right;
112 maps_area_create_rectangle((maps_coordinates_h) & rec_tl,
113 (maps_coordinates_h) & rec_br, &new_rect);
117 return MAPS_ERROR_INVALID_PARAMETER;
119 } else if (origin_handle->type == MAPS_AREA_CIRCLE) {
120 maps_area_h new_circle = NULL;
121 maps_area_circle_s cir = origin_handle->circle;
122 maps_coordinates_s center = cir.center;
123 double radius = cir.radius;
124 maps_area_create_circle((maps_coordinates_h)¢er, radius, &new_circle);
126 *cloned = new_circle;
128 return MAPS_ERROR_INVALID_PARAMETER;
132 return MAPS_ERROR_NONE;
135 bool maps_area_is_valid(const maps_area_h area)
137 if (!maps_condition_check_maps_feature())
138 return MAPS_ERROR_NOT_SUPPORTED;
139 if (!area) return false;
142 maps_area_s *handle = (maps_area_s *) area;
145 if (handle->type == MAPS_AREA_RECTANGLE) {
146 maps_area_rectangle_s rect = handle->rect;
148 if (!maps_coordinates_is_valid(&rect.top_left) ||
149 !maps_coordinates_is_valid(&rect.bottom_right)) {
153 } else if (handle->type == MAPS_AREA_CIRCLE) {
154 maps_area_circle_s cir = handle->circle;
155 maps_coordinates_s center = cir.center;
157 if (cir.radius <= 0) {
161 if (!maps_coordinates_is_valid(¢er)) {