#include "convex_hull.h"
#include "core/error/error_macros.h"
#include "core/math/aabb.h"
#include "core/math/math_defs.h"
#include "core/os/memory.h"
#include "core/templates/oa_hash_map.h"
#include "core/templates/paged_allocator.h"
#include <string.h>
#ifdef DEBUG_ENABLED
#define CHULL_ASSERT(m_cond) …
#else
#define CHULL_ASSERT …
#endif
#if defined(DEBUG_CONVEX_HULL) || defined(SHOW_ITERATIONS)
#include <stdio.h>
#endif
class ConvexHullInternal { … };
ConvexHullInternal::Int128 ConvexHullInternal::Int128::operator*(int64_t b) const { … }
ConvexHullInternal::Int128 ConvexHullInternal::Int128::mul(int64_t a, int64_t b) { … }
ConvexHullInternal::Int128 ConvexHullInternal::Int128::mul(uint64_t a, uint64_t b) { … }
int32_t ConvexHullInternal::Rational64::compare(const Rational64 &b) const { … }
int32_t ConvexHullInternal::Rational128::compare(const Rational128 &b) const { … }
int32_t ConvexHullInternal::Rational128::compare(int64_t b) const { … }
ConvexHullInternal::Edge *ConvexHullInternal::new_edge_pair(Vertex *p_from, Vertex *p_to) { … }
bool ConvexHullInternal::merge_projection(IntermediateHull &r_h0, IntermediateHull &r_h1, Vertex *&r_c0, Vertex *&r_c1) { … }
void ConvexHullInternal::compute_internal(int32_t p_start, int32_t p_end, IntermediateHull &r_result) { … }
#ifdef DEBUG_CONVEX_HULL
void ConvexHullInternal::IntermediateHull::print() {
printf(" Hull\n");
for (Vertex *v = min_xy; v;) {
printf(" ");
v->print();
if (v == max_xy) {
printf(" max_xy");
}
if (v == min_yx) {
printf(" min_yx");
}
if (v == max_yx) {
printf(" max_yx");
}
if (v->next->prev != v) {
printf(" Inconsistency");
}
printf("\n");
v = v->next;
if (v == min_xy) {
break;
}
}
if (min_xy) {
min_xy->copy = (min_xy->copy == -1) ? -2 : -1;
min_xy->print_graph();
}
}
void ConvexHullInternal::Vertex::print_graph() {
print();
printf("\nEdges\n");
Edge *e = edges;
if (e) {
do {
e->print();
printf("\n");
e = e->next;
} while (e != edges);
do {
Vertex *v = e->target;
if (v->copy != copy) {
v->copy = copy;
v->print_graph();
}
e = e->next;
} while (e != edges);
}
}
#endif
ConvexHullInternal::Orientation ConvexHullInternal::get_orientation(const Edge *p_prev, const Edge *p_next, const Point32 &p_s, const Point32 &p_t) { … }
ConvexHullInternal::Edge *ConvexHullInternal::find_max_angle(bool p_ccw, const Vertex *p_start, const Point32 &p_s, const Point64 &p_rxs, const Point64 &p_sxrxs, Rational64 &p_min_cot) { … }
void ConvexHullInternal::find_edge_for_coplanar_faces(Vertex *p_c0, Vertex *p_c1, Edge *&p_e0, Edge *&p_e1, const Vertex *p_stop0, const Vertex *p_stop1) { … }
void ConvexHullInternal::merge(IntermediateHull &p_h0, IntermediateHull &p_h1) { … }
struct PointComparator { … };
void ConvexHullInternal::compute(const Vector3 *p_coords, int32_t p_count) { … }
Vector3 ConvexHullInternal::to_gd_vector(const Point32 &p_v) { … }
Vector3 ConvexHullInternal::get_gd_normal(Face *p_face) { … }
Vector3 ConvexHullInternal::get_coordinates(const Vertex *p_v) { … }
real_t ConvexHullInternal::shrink(real_t p_amount, real_t p_clamp_amount) { … }
bool ConvexHullInternal::shift_face(Face *p_face, real_t p_amount, LocalVector<Vertex *> &p_stack) { … }
static int32_t get_vertex_copy(ConvexHullInternal::Vertex *p_vertex, LocalVector<ConvexHullInternal::Vertex *> &p_vertices) { … }
real_t ConvexHullComputer::compute(const Vector3 *p_coords, int32_t p_count, real_t p_shrink, real_t p_shrink_clamp) { … }
Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_mesh) { … }