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);
42 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
43 return MAPS_ERROR_OUT_OF_MEMORY;
46 bound->type = MAPS_AREA_RECTANGLE;
48 bound->rect.top_left = *((maps_coordinates_s *) top_left);
49 bound->rect.bottom_right = *((maps_coordinates_s *) bottom_right);
51 *area = (maps_area_h) bound;
53 return MAPS_ERROR_NONE;
56 EXPORT_API int maps_area_create_circle(const maps_coordinates_h center,
57 const double radius, maps_area_h *area)
59 if (!maps_condition_check_maps_feature())
60 return MAPS_ERROR_NOT_SUPPORTED;
62 if (!center || !area || radius <= 0)
63 return MAPS_ERROR_INVALID_PARAMETER;
65 if (!maps_coordinates_is_valid(center))
66 return MAPS_ERROR_INVALID_PARAMETER;
68 maps_area_s *bound = g_new0(maps_area_s, 1);
71 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
72 return MAPS_ERROR_OUT_OF_MEMORY;
75 bound->type = MAPS_AREA_CIRCLE;
76 bound->circle.center = *((maps_coordinates_s *) center);
77 bound->circle.radius = radius;
78 *area = (maps_area_h) bound;
80 return MAPS_ERROR_NONE;
83 EXPORT_API int maps_area_destroy(maps_area_h area)
85 if (!maps_condition_check_maps_feature())
86 return MAPS_ERROR_NOT_SUPPORTED;
88 return MAPS_ERROR_INVALID_PARAMETER;
90 maps_area_s *handle = (maps_area_s *) area;
92 return MAPS_ERROR_NONE;
95 EXPORT_API int maps_area_clone(const maps_area_h origin, maps_area_h *cloned)
97 if (!maps_condition_check_maps_feature())
98 return MAPS_ERROR_NOT_SUPPORTED;
99 if (!cloned || !origin)
100 return MAPS_ERROR_INVALID_PARAMETER;
102 maps_area_s * origin_handle = (maps_area_s *) origin;
103 if (origin_handle->type == MAPS_AREA_RECTANGLE) {
104 maps_area_h new_rect = NULL;
105 maps_area_rectangle_s rect = origin_handle->rect;
106 maps_coordinates_s rec_tl = rect.top_left;
107 maps_coordinates_s rec_br = rect.bottom_right;
108 maps_area_create_rectangle((maps_coordinates_h) & rec_tl,
109 (maps_coordinates_h) & rec_br, &new_rect);
113 return MAPS_ERROR_INVALID_PARAMETER;
115 } else if (origin_handle->type == MAPS_AREA_CIRCLE) {
116 maps_area_h new_circle = NULL;
117 maps_area_circle_s cir = origin_handle->circle;
118 maps_coordinates_s center = cir.center;
119 double radius = cir.radius;
120 maps_area_create_circle((maps_coordinates_h)¢er, radius, &new_circle);
122 *cloned = new_circle;
124 return MAPS_ERROR_INVALID_PARAMETER;
128 return MAPS_ERROR_NONE;
131 bool maps_area_is_valid(const maps_area_h area)
133 if (!maps_condition_check_maps_feature())
134 return MAPS_ERROR_NOT_SUPPORTED;
135 if (!area) return false;
138 maps_area_s *handle = (maps_area_s *) area;
141 if (handle->type == MAPS_AREA_RECTANGLE) {
142 maps_area_rectangle_s rect = handle->rect;
144 if (!maps_coordinates_is_valid(&rect.top_left) ||
145 !maps_coordinates_is_valid(&rect.bottom_right)) {
149 } else if (handle->type == MAPS_AREA_CIRCLE) {
150 maps_area_circle_s cir = handle->circle;
151 maps_coordinates_s center = cir.center;
153 if (cir.radius <= 0) {
157 if (!maps_coordinates_is_valid(¢er)) {