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.
17 #include "maps_object.h"
18 #include "maps_address.h"
19 #include "maps_error.h"
22 bool __equal_double(const double &d1, const double &d2)
24 static double delta = 0.0000001;
25 if (d1 >= (d2 + delta))
27 if (d1 <= (d2 - delta))
32 /*----------------------------------------------------------------------------*/
33 /* Simple type library, helpful for operating with Maps Objects */
36 maps::coordinates::coordinates():object(NULL)
40 maps::coordinates::coordinates(const double &lat, const double &lon):object(NULL)
42 maps_coordinates_create(lat, lon, &handle);
45 maps::coordinates::coordinates(const maps_coordinates_s & c):object(NULL)
47 maps_coordinates_create(c.latitude, c.longitude, &handle);
50 maps::coordinates::coordinates(const coordinates & c):object(NULL)
55 maps::coordinates & maps::coordinates::operator=(const coordinates & c)
58 maps_coordinates_destroy(handle);
59 maps_coordinates_clone(c.handle, &handle);
64 maps::coordinates::~coordinates()
68 bool maps::coordinates::operator==(const coordinates & c) const
72 if (!__equal_double(get_latitude(), c.get_latitude()))
74 if (!__equal_double(get_longitude(), c.get_longitude()))
79 bool maps::coordinates::operator!=(const coordinates & c) const
84 double maps::coordinates::get_latitude() const
88 maps_coordinates_get_latitude(handle, &lat);
92 double maps::coordinates::get_longitude() const
96 maps_coordinates_get_longitude(handle, &lon);
101 maps::area::area():object(NULL)
109 maps::area::area(const coordinates & lt, const coordinates & rb):object(NULL)
111 maps_area_create_rectangle(lt, rb, &handle);
114 maps::area::area(const double &l, const double &t, const double &r,
115 const double &b):object(NULL)
117 maps_area_create_rectangle(coordinates(l, t), coordinates(r, b),
121 maps::area::area(const coordinates & c, const double &r):object(NULL)
123 maps_area_create_circle(c, r, &handle);
126 maps::area::area(const double &x, const double &y, const double &r):object(NULL)
128 maps_area_create_circle(coordinates(x, y), r, &handle);
131 maps::area::area(const area & a):object(NULL)
136 maps::area & maps::area::operator=(const area & a)
139 maps_area_destroy(handle);
140 maps_area_clone(a.handle, &handle);
145 maps_area_type_e maps::area::get_type() const
148 return MAPS_AREA_NONE;
149 maps_area_s* a = (maps_area_s*) handle;
153 maps::coordinates maps::area::get_top_left() const
156 return coordinates(.0, .0);
157 maps_area_s* a = (maps_area_s*) handle;
158 return coordinates(a->rect.top_left);
161 maps::coordinates maps::area::get_bottom_right() const
164 return coordinates(.0, .0);
165 maps_area_s* a = (maps_area_s*) handle;
166 return coordinates(a->rect.bottom_right);
169 maps::coordinates maps::area::get_center() const
172 return coordinates(.0, .0);
173 maps_area_s* a = (maps_area_s*) handle;
174 return coordinates(a->circle.center);
177 double maps::area::get_radius() const
181 maps_area_s* a = (maps_area_s*) handle;
182 return a->circle.radius;
185 bool maps::area::operator==(const area & a) const
189 if (get_type() != a.get_type())
191 switch (get_type()) {
192 case MAPS_AREA_RECTANGLE:
193 if (get_top_left() != a.get_top_left())
195 if (get_bottom_right() != a.get_bottom_right())
198 case MAPS_AREA_CIRCLE:
199 if (get_center() != a.get_center())
201 if (!__equal_double(get_radius(), a.get_radius()))
211 bool maps::area::operator!=(const area & a) const
213 return !(*this == a);
216 /*----------------------------------------------------------------------------*/
218 maps::string_holder::~string_holder()