|
@@ -1,16 +1,15 @@
|
|
|
/**
|
|
|
- ******************************************************************************
|
|
|
- * @file : studio_geo_algo_c.c
|
|
|
- * @author : wangyingjie
|
|
|
- * @brief : None
|
|
|
- * @attention : None
|
|
|
- * @date : 2025/5/11
|
|
|
- ******************************************************************************
|
|
|
- */
|
|
|
+ ******************************************************************************
|
|
|
+ * @file : studio_geo_algo_c.c
|
|
|
+ * @author : wangyingjie
|
|
|
+ * @brief : None
|
|
|
+ * @attention : None
|
|
|
+ * @date : 2025/5/11
|
|
|
+ ******************************************************************************
|
|
|
+ */
|
|
|
|
|
|
#include "studio_geo_algo_c.h"
|
|
|
|
|
|
-
|
|
|
double point_line_dist_square_c(const studio_point_c *p, const studio_point_c *start, const studio_point_c *end)
|
|
|
{
|
|
|
double A = p->x - start->x;
|
|
@@ -84,33 +83,53 @@ void douglas_peucker_c(const studio_line_c *points, size_t start, size_t end, do
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void remove_duplicates(unsigned int **indices, unsigned int *size) {
|
|
|
- if (*size == 0) return;
|
|
|
- // 临时数组用于存储去重后的数据
|
|
|
+
|
|
|
+unsigned int hash(unsigned int value, unsigned int size)
|
|
|
+{
|
|
|
+ return value % size;
|
|
|
+}
|
|
|
+
|
|
|
+void remove_duplicates(unsigned int **indices, unsigned int *size)
|
|
|
+{
|
|
|
+ if (*size == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
unsigned int *unique_indices = (unsigned int *)malloc(*size * sizeof(unsigned int));
|
|
|
unsigned int unique_count = 0;
|
|
|
- for (unsigned int i = 0; i < *size; i++) {
|
|
|
- unsigned int is_duplicate = 0;
|
|
|
- // 检查当前元素是否已经在 unique_indices 中
|
|
|
- for (unsigned int j = 0; j < unique_count; j++) {
|
|
|
- if ((*indices)[i] == unique_indices[j]) {
|
|
|
- is_duplicate = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- // 如果没有重复,添加到 unique_indices
|
|
|
- if (!is_duplicate) {
|
|
|
- unique_indices[unique_count] = (*indices)[i];
|
|
|
- unique_count++;
|
|
|
+
|
|
|
+ // 创建一个哈希表
|
|
|
+ unsigned int hash_table_size = *size * 4; // 哈希表大小可以稍微增大以减少冲突 这个可能有问题
|
|
|
+ bool *hash_table = (bool *)malloc(hash_table_size * sizeof(bool));
|
|
|
+ for (unsigned int i = 0; i < hash_table_size; i++)
|
|
|
+ {
|
|
|
+ hash_table[i] = false; // 初始化哈希表
|
|
|
+ }
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < *size; i++)
|
|
|
+ {
|
|
|
+ unsigned int current_value = (*indices)[i];
|
|
|
+ unsigned int hash_index = hash(current_value, hash_table_size);
|
|
|
+
|
|
|
+ // 检查该元素是否已经在哈希表中
|
|
|
+ if (!hash_table[hash_index])
|
|
|
+ {
|
|
|
+ hash_table[hash_index] = true;
|
|
|
+ unique_indices[unique_count++] = current_value;
|
|
|
}
|
|
|
}
|
|
|
- // 释放原有的 indices
|
|
|
+
|
|
|
+ // 释放原有的 indices 和哈希表
|
|
|
free(*indices);
|
|
|
+ free(hash_table);
|
|
|
+
|
|
|
// 更新 indices 指针和大小
|
|
|
*indices = unique_indices;
|
|
|
*size = unique_count;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
bool line_vacuate_c(const studio_line_c *line, const int max_points, const double epsilon, studio_line_c *vacuate_line)
|
|
|
{
|
|
|
// 初始化状态变量
|