Skip to content

Commit 6e97993

Browse files
committed
use vector insted of array
1 parent e64c607 commit 6e97993

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

include/delaunator.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ inline bool in_circle(
149149
constexpr double EPSILON = std::numeric_limits<double>::epsilon();
150150
constexpr std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();
151151

152-
//@see https://stackoverflow.com/questions/30208196/maximum-recursive-function-calls-in-c-c-before-stack-is-full-and-gives-a-segme
153-
constexpr std::size_t EDGE_STACK_SIZE = 1024;
154-
155152
inline bool check_pts_equal(double x1, double y1, double x2, double y2) {
156153
return std::fabs(x1 - x2) <= EPSILON &&
157154
std::fabs(y1 - y2) <= EPSILON;
@@ -193,7 +190,7 @@ class Delaunator {
193190
double m_center_x;
194191
double m_center_y;
195192
std::size_t m_hash_size;
196-
std::size_t m_edge_stack[EDGE_STACK_SIZE];
193+
std::vector<std::size_t> m_edge_stack;
197194

198195
std::size_t legalize(std::size_t a);
199196
std::size_t hash_key(double x, double y) const;
@@ -443,6 +440,7 @@ double Delaunator::get_hull_area() {
443440
std::size_t Delaunator::legalize(std::size_t a) {
444441
std::size_t i = 0;
445442
std::size_t ar = 0;
443+
m_edge_stack.clear();
446444

447445
// recursion eliminated with a fixed-size stack
448446
while (true) {
@@ -518,9 +516,13 @@ std::size_t Delaunator::legalize(std::size_t a) {
518516
link(ar, bl);
519517
std::size_t br = b0 + (b + 1) % 3;
520518

521-
if (i + 1 < EDGE_STACK_SIZE) {
522-
m_edge_stack[i++] = br;
519+
if (i < m_edge_stack.size()) {
520+
m_edge_stack[i] = br;
521+
} else {
522+
m_edge_stack.push_back(br);
523523
}
524+
i++;
525+
524526
} else {
525527
if (i > 0) {
526528
i--;

0 commit comments

Comments
 (0)