📄 gps_jpeg_sort.c
字号:
#include "gps_jpeg_private.h"
/*
本文件对gps jpeg链表中的item进行查找、匹配等操作
*/
// 地图缩放时允许地图切换
#define gps_jpeg_mode_multi_map 0x1
typedef struct gps_mapping_pos { /* 坐标映射数据*/
int longitude; // 经度,正数代表东经,负数代表西经
int latitude; // 纬度,正数代表南纬,负数代表北纬
int x_pixel; // 对应的水平象素点,可能为负数
int y_pixel; // 垂直象素点,可能为负数
} gps_mapping_pos_t;
typedef struct gps_mapping_info { /* 坐标映射数据*/
uint n_general_mapping; // 来自MAP地图文件的采样点数;可能为0
uint n_custom_mapping; // 来自DAT坐标文件的采样点数;可能为0
uint scale; // 内部比例尺;scale不能为0,0有特殊用途
BOOL is_custom_map; // 1 表示对应的为用户MAP地图文件
gps_mapping_pos_t *map; // 顺序保存全部的采样点,把MAP的点放在前面
} gps_mapping_info_t;
/* 检查有没有比例尺重复,重复者减一*/
static void map_sort_check_equ(int num, struct list_head *head, struct list_head *pos)
{
int i;//中文字符
uint val_s = list_entry(pos, gps_map_info_t, node_all)->mapping_info.scale;
for(i=0; i<num; i++) {
uint val_d;
head = head->next;
val_d = list_entry(head, gps_map_info_t, node_all)->mapping_info.scale;
if (val_s == val_d) {
list_entry(head, gps_map_info_t, node_all)->mapping_info.scale = val_d - 1;
}
}
}
/* 找到最大的item */
static struct list_head *map_sort_get_max(int num, struct list_head *head)
{
int i;
struct list_head * max_item = head->next;
uint max_val = 0;
for(i=0; i<num; i++) {
uint val;
head = head->next;
val = list_entry(head, gps_map_info_t, node_all)->mapping_info.scale;
if (max_val < val) {
max_item = head;
max_val = val;
}
}
return max_item;
}
/* 一行中共有num个item,
把最大的item挂到head上,
本且检查有没有重复*/
static inline void map_sort_sub(int num, struct list_head *head)
{
struct list_head *pos;
pos = map_sort_get_max(num, head);
list_del(pos);
map_sort_check_equ(num-1, head, pos);
list_add(pos, head);
}
/* 对链表中的地图进行排序,
比例尺由大到小,
并且保证比例尺不重复
冒泡算法
假定为0的比例尺已经全部挂到链表末尾*/
void gps_jpeg_map_scale_sort(void)
{
struct list_head *pos, *head;
int len = 0;
int index;
list_for_each(pos, (&gps_map_gloabl_entry)) {
uint val = list_entry(pos, gps_map_info_t, node_all)->mapping_info.scale;
if (val == 0) {
break;
}
len++;
}
head = &gps_map_gloabl_entry;
for(index=len; index>1; index--) {
map_sort_sub(index, head);
head = head->next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -