Skip to content

Commit

Permalink
remove c++11
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Jan 16, 2024
1 parent 74d1057 commit a49b670
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/Makevars

This file was deleted.

1 change: 0 additions & 1 deletion src/Makevars.win

This file was deleted.

27 changes: 21 additions & 6 deletions src/circlePack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Circle*> Q;
enclosure = encloseN(fc.begin(), fc.end(), Q);
}
Expand Down Expand Up @@ -455,6 +468,7 @@ int findTopNode(std::vector<NodePack*>& nodes) {
//'
//[[Rcpp::export(name = "pack_circles")]]
NumericMatrix pack(NumericVector areas) {
GetRNGstate();
NumericVector::iterator itr;
std::deque<Circle> circles;
NumericMatrix res(areas.size(), 2);
Expand All @@ -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<NodePack*> nodes = createHierarchy(as< std::vector<int> >(parent), as< std::vector<double> >(weight));
Expand All @@ -497,6 +512,6 @@ NumericMatrix circlePackLayout(IntegerVector parent, NumericVector weight) {
res(i, 2) = nodes[i]->r;
delete nodes[i];
}

PutRNGstate();
return res;
}

0 comments on commit a49b670

Please sign in to comment.