Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
ba6cc387
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ba6cc387
编写于
8月 06, 2015
作者:
Y
yuqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add GEO function get_line_distance_km
上级
c623a6c9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
61 addition
and
1 deletion
+61
-1
HISTORY
HISTORY
+3
-0
libfastcommon.spec
libfastcommon.spec
+1
-1
php-fastcommon/fastcommon.c
php-fastcommon/fastcommon.c
+34
-0
php-fastcommon/fastcommon.h
php-fastcommon/fastcommon.h
+1
-0
src/shared_func.c
src/shared_func.c
+19
-0
src/shared_func.h
src/shared_func.h
+3
-0
未找到文件。
HISTORY
浏览文件 @
ba6cc387
Version 1.20 2015-08-06
* add GEO function get_line_distance_km
Version 1.19 2015-07-24
* correct logger rotate time near 0 clock
...
...
libfastcommon.spec
浏览文件 @
ba6cc387
...
...
@@ -2,7 +2,7 @@
%define LibFastcommonDevel libfastcommon-devel
Name: libfastcommon
Version: 1.0.
19
Version: 1.0.
20
Release: 1%{?dist}
Summary: c common functions library extracted from my open source projects FastDFS
License: GPL
...
...
php-fastcommon/fastcommon.c
浏览文件 @
ba6cc387
...
...
@@ -21,6 +21,7 @@
#include "logger.h"
#include "hash.h"
#include "sockopt.h"
#include "shared_func.h"
#include "fastcommon.h"
#define MAJOR_VERSION 1
...
...
@@ -40,6 +41,7 @@ const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, N
ZEND_FE
(
fastcommon_gethostaddrs
,
NULL
)
ZEND_FE
(
fastcommon_time33_hash
,
NULL
)
ZEND_FE
(
fastcommon_simple_hash
,
NULL
)
ZEND_FE
(
fastcommon_get_line_distance_km
,
NULL
)
{
NULL
,
NULL
,
NULL
}
/* Must be the last line */
};
...
...
@@ -240,3 +242,35 @@ ZEND_FUNCTION(fastcommon_simple_hash)
RETURN_LONG
(
simple_hash
(
str
,
str_len
)
&
0x7FFFFFFF
);
}
/*
double fastcommon_get_line_distance_km(double lat1, double lon1,
double lat2, double lon2)
return line distance in KM
*/
ZEND_FUNCTION
(
fastcommon_get_line_distance_km
)
{
int
argc
;
double
lat1
;
double
lon1
;
double
lat2
;
double
lon2
;
argc
=
ZEND_NUM_ARGS
();
if
(
argc
!=
4
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"fastcommon_get_line_distance_km parameters count: %d is invalid"
,
__LINE__
,
argc
);
RETURN_BOOL
(
false
);
}
if
(
zend_parse_parameters
(
argc
TSRMLS_CC
,
"dddd"
,
&
lat1
,
&
lon1
,
&
lat2
,
&
lon2
)
==
FAILURE
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"zend_parse_parameters fail!"
,
__LINE__
);
RETURN_BOOL
(
false
);
}
RETURN_DOUBLE
(
get_line_distance_km
(
lat1
,
lon1
,
lat2
,
lon2
));
}
php-fastcommon/fastcommon.h
浏览文件 @
ba6cc387
...
...
@@ -21,6 +21,7 @@ ZEND_FUNCTION(fastcommon_version);
ZEND_FUNCTION
(
fastcommon_gethostaddrs
);
ZEND_FUNCTION
(
fastcommon_time33_hash
);
ZEND_FUNCTION
(
fastcommon_simple_hash
);
ZEND_FUNCTION
(
fastcommon_get_line_distance_km
);
#ifdef __cplusplus
}
...
...
src/shared_func.c
浏览文件 @
ba6cc387
...
...
@@ -23,6 +23,7 @@
#include <dirent.h>
#include <grp.h>
#include <pwd.h>
#include <math.h>
#include "shared_func.h"
#include "logger.h"
#include "sockopt.h"
...
...
@@ -2092,3 +2093,21 @@ int ignore_signal_pipe()
return
0
;
}
double
get_line_distance_km
(
const
double
lat1
,
const
double
lon1
,
const
double
lat2
,
const
double
lon2
)
{
#define FAST_ABS(v) ((v) >= 0 ? (v) : -1 * (v))
#define DISTANCE_PER_LATITUDE 111.111
double
lat_value
;
double
lng_distance
;
double
lat_distance
;
lat_value
=
FAST_ABS
(
lat1
)
<
FAST_ABS
(
lat2
)
?
lat1
:
lat2
;
lat_distance
=
FAST_ABS
(
lat1
-
lat2
)
*
DISTANCE_PER_LATITUDE
;
lng_distance
=
FAST_ABS
(
lon1
-
lon2
)
*
DISTANCE_PER_LATITUDE
*
cos
(
lat_value
*
3
.
1415926
/
180
.
0
);
return
sqrt
(
lat_distance
*
lat_distance
+
lng_distance
*
lng_distance
);
}
src/shared_func.h
浏览文件 @
ba6cc387
...
...
@@ -512,6 +512,9 @@ int set_file_utimes(const char *filename, const time_t new_time);
*/
int
ignore_signal_pipe
();
double
get_line_distance_km
(
const
double
lat1
,
const
double
lon1
,
const
double
lat2
,
const
double
lon2
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录