From a49b670741285e43d85ea57244fd7eef5f87ffa4 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Tue, 16 Jan 2024 16:24:01 +0100 Subject: [PATCH] remove c++11 --- src/Makevars | 1 - src/Makevars.win | 1 - src/circlePack.cpp | 27 +++++++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) delete mode 100644 src/Makevars delete mode 100644 src/Makevars.win diff --git a/src/Makevars b/src/Makevars deleted file mode 100644 index e66fbbda..00000000 --- a/src/Makevars +++ /dev/null @@ -1 +0,0 @@ -CXX_STD=CXX11 diff --git a/src/Makevars.win b/src/Makevars.win deleted file mode 100644 index e66fbbda..00000000 --- a/src/Makevars.win +++ /dev/null @@ -1 +0,0 @@ -CXX_STD=CXX11 diff --git a/src/circlePack.cpp b/src/circlePack.cpp index 4c689520..e4202e3c 100644 --- a/src/circlePack.cpp +++ b/src/circlePack.cpp @@ -3,9 +3,22 @@ using namespace Rcpp; -inline int randWrapper(const int n) { - return std::floor(float(unif_rand()*n)); -} +struct randWrapper { + using result_type = unsigned int; + + static constexpr result_type min() { + return 0; + } + + static constexpr result_type max() { + return RAND_MAX; + } + + result_type operator()() { + return unif_rand()*RAND_MAX; + } +}; + struct Circle { double x; double y; @@ -291,7 +304,7 @@ class FrontChain { } else if (fc.size() == 2) { enclosure = enclose2(fc[0], fc[1]); } else { - std::random_shuffle(fc.begin(), fc.end(), randWrapper); + std::shuffle(fc.begin(), fc.end(), randWrapper()); std::deque Q; enclosure = encloseN(fc.begin(), fc.end(), Q); } @@ -455,6 +468,7 @@ int findTopNode(std::vector& nodes) { //' //[[Rcpp::export(name = "pack_circles")]] NumericMatrix pack(NumericVector areas) { + GetRNGstate(); NumericVector::iterator itr; std::deque circles; NumericMatrix res(areas.size(), 2); @@ -476,12 +490,13 @@ NumericMatrix pack(NumericVector areas) { res.attr("enclosing_radius") = fc.enclose_radius(); res.attr("front_chain") = wrap(fc.chain_ind()); } - + PutRNGstate(); return res; } //[[Rcpp::export]] NumericMatrix circlePackLayout(IntegerVector parent, NumericVector weight) { + GetRNGstate(); NumericMatrix res(parent.size(), 3); unsigned int i; std::vector nodes = createHierarchy(as< std::vector >(parent), as< std::vector >(weight)); @@ -497,6 +512,6 @@ NumericMatrix circlePackLayout(IntegerVector parent, NumericVector weight) { res(i, 2) = nodes[i]->r; delete nodes[i]; } - + PutRNGstate(); return res; }