2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FLoc_MathUtils.cpp
20 * @brief This is the implementation file for _MathUtils class.
22 * This file contains implementation of _MathUtils class.
26 #include <FBaseSysLog.h>
27 #include <FBaseUtilMath.h>
28 #include <FLocLocation.h>
29 #include "FLoc_MathUtils.h"
30 #include "FLoc_RegionInfo.h"
32 using namespace Tizen::Base::Utility;
35 namespace Tizen { namespace Locations
38 const double _MathUtils::PI = M_PI;
39 const double _MathUtils::PI2 = 2.0 * _MathUtils::PI;
40 const double _MathUtils::DEG2RAD = _MathUtils::PI / 180.0;
41 const double _MathUtils::RAD2DEG = 180.0 / _MathUtils::PI;
42 const double _MathUtils::HALFPI = 1.5707963267948966;
43 const double _MathUtils::CENTRE_LATITUDE = 0.0;
46 _MathUtils::CalculateOverlapRegion(const _RegionInfo& region, const Location& location)
48 double overlapArea = 0;
49 double distanceBtwCenters = region.GetCoordinate().GetDistanceTo(location.GetCoordinates());
50 double regionRadius = region.GetRadius();
51 double locationRadius = location.GetHorizontalAccuracy();
53 double distanceBtwCentersSqr = distanceBtwCenters * distanceBtwCenters;
54 double regionRadiusSqr = regionRadius * regionRadius;
55 double locationRadiusSqr = locationRadius * locationRadius;
57 // The circles are overlapping
58 if (distanceBtwCenters <= Math::Abs(regionRadius - locationRadius))
60 overlapArea = locationRadius > regionRadius ? Math::GetPi() * regionRadiusSqr : Math::GetPi() * locationRadiusSqr;
64 double theta = Math::Acos((regionRadiusSqr + distanceBtwCentersSqr - locationRadiusSqr) / (2 * regionRadius * distanceBtwCenters));
65 double phi = Math::Acos((locationRadiusSqr + distanceBtwCentersSqr - regionRadiusSqr) / (2 * locationRadius * distanceBtwCenters));
67 overlapArea = regionRadiusSqr * (theta - Math::Sin(theta) * Math::Cos(theta)) + locationRadiusSqr * (phi - Math::Sin(phi) * Math::Cos(phi));
73 } } // Tizen::Locations