From af105926166604b069e53ac2b94f750b4e1a841a Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 31 Mar 2020 20:06:18 +0200 Subject: [PATCH] moved binsearch to hyper.h --- hyper.h | 12 ++++++++++++ reg3.cpp | 9 --------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hyper.h b/hyper.h index fe53f168..e8bc9907 100644 --- a/hyper.h +++ b/hyper.h @@ -772,6 +772,18 @@ template void texture_order(const T& f) { } } +/** find the smallest value of x in range [dmin..dmax] such that f(x) returns true */ + +template ld binsearch(ld dmin, ld dmax, const T& f) { + for(int i=0; i<200; i++) { + ld d = (dmin + dmax) / 2; + if(dmin == d || dmax == d) break; + if(f(d)) dmax = d; + else dmin = d; + } + return dmin; + } + static const color_t NOCOLOR = 0; static const int max_vec = (1<<14); diff --git a/reg3.cpp b/reg3.cpp index 66b856af..0e2c033f 100644 --- a/reg3.cpp +++ b/reg3.cpp @@ -44,15 +44,6 @@ EX namespace reg3 { /** \brief for adjacent directions a,b, next_dir[a][b] is the next direction adjacent to a, in (counter?)clockwise order from b */ EX int next_dir[16][16]; - template ld binsearch(ld dmin, ld dmax, const T& f) { - for(int i=0; i<200; i++) { - ld d = (dmin + dmax) / 2; - if(f(d)) dmax = d; - else dmin = d; - } - return dmin; - } - EX void generate() { if(S7 == 4) face = 3;