Cleanup: move convexhull_2d to C++

This commit is contained in:
Campbell Barton
2024-02-10 22:40:46 +11:00
parent 28e771372b
commit 727d47c015
2 changed files with 10 additions and 7 deletions

View File

@@ -56,7 +56,7 @@ set(SRC
intern/buffer.c
intern/cache_mutex.cc
intern/compute_context.cc
intern/convexhull_2d.c
intern/convexhull_2d.cc
intern/cpp_type.cc
intern/cpp_types.cc
intern/delaunay_2d.cc

View File

@@ -148,8 +148,8 @@ struct PointRef {
static int pointref_cmp_yx(const void *a_, const void *b_)
{
const struct PointRef *a = a_;
const struct PointRef *b = b_;
const PointRef *a = static_cast<const PointRef *>(a_);
const PointRef *b = static_cast<const PointRef *>(b_);
if (a->pt[1] > b->pt[1]) {
return 1;
@@ -176,8 +176,10 @@ int BLI_convexhull_2d(const float (*points)[2], const int n, int r_points[])
}
return n;
}
struct PointRef *points_ref = MEM_mallocN(sizeof(*points_ref) * (size_t)n, __func__);
float(*points_sort)[2] = MEM_mallocN(sizeof(*points_sort) * (size_t)n, __func__);
PointRef *points_ref = static_cast<PointRef *>(
MEM_mallocN(sizeof(*points_ref) * (size_t)n, __func__));
float(*points_sort)[2] = static_cast<float(*)[2]>(
MEM_mallocN(sizeof(*points_sort) * (size_t)n, __func__));
for (int i = 0; i < n; i++) {
points_ref[i].pt = points[i];
@@ -262,12 +264,13 @@ float BLI_convexhull_aabb_fit_points_2d(const float (*points)[2], int n)
BLI_assert(n >= 0);
float angle = 0.0f;
int *index_map = MEM_mallocN(sizeof(*index_map) * (size_t)n, __func__);
int *index_map = static_cast<int *>(MEM_mallocN(sizeof(*index_map) * (size_t)n, __func__));
int points_hull_num = BLI_convexhull_2d(points, n, index_map);
if (points_hull_num > 1) {
float(*points_hull)[2] = MEM_mallocN(sizeof(*points_hull) * (size_t)points_hull_num, __func__);
float(*points_hull)[2] = static_cast<float(*)[2]>(
MEM_mallocN(sizeof(*points_hull) * (size_t)points_hull_num, __func__));
for (int j = 0; j < points_hull_num; j++) {
copy_v2_v2(points_hull[j], points[index_map[j]]);
}