@ 260528.1

231103.1 · 7f4a9ed91bbecb84e39f4bc8030247ce5116ddf8

Reorganize examples into categorized folders (#341)

* refactor: create directory structure to organize exmaples
* test: update test_all to work with new directory structure
* fix: bug in test_all if no package.json scripts
* test: cleanup output of test_all
* fix: remove default test script that throws from thread_safe_function_with_object_wrap
* fix: remove build_with_cmake from .gitignore
* fix: swith to ' from " and remove subdir from getAllTests call
* test: add extra test cases for npm start and just running the pkgJson.main with node
* refactor: move all examples to src directory
* refactor: add numbers to categories so they are ordered in the src folder
* refactor: simplify getAllExamples in test_all.js
* docs: add directory structure to README.md
* docs: update directory structure to README.md
* docs: update directory structure to README.md
* docs: update directory structure to README.md
* docs: update directory structure example in readme
* add back build_with_cmake --------- Co-authored-by: legendecas <legendecas@gmail.com>

reading declarations

Changes to src/5-async-work/async_pi_estimate/node-addon-api/pi_est.cc. All files

src/5-async-work/async_pi_estimate/node-addon-api/pi_est.cc

new file mode 100755@@ -0,0 +1,54 @@+#include "pi_est.h"  // NOLINT(build/include)+#include <cstdlib>++/*+Estimate the value of π by using a Monte Carlo method.+Take `points` samples of random x and y values on a+[0,1][0,1] plane. Calculating the length of the diagonal+tells us whether the point lies inside, or outside a+quarter circle running from 0,1 to 1,0. The ratio of the+number of points inside to outside gives us an+approximation of π/4.++See https://en.wikipedia.org/wiki/File:Pi_30K.gif+for a visualization of how this works.+*/++inline int randall(unsigned int* p_seed) {+// windows has thread safe rand()+#ifdef _WIN32+  return rand();  // NOLINT(runtime/threadsafe_fn)+#else+  return rand_r(p_seed);+#endif+}++double Estimate(int points) {+  int i = points;+  int inside = 0;+  unsigned int randseed = 1;++#ifdef _WIN32+  srand(randseed);+#endif++  // unique seed for each run, for threaded use+  unsigned int seed = randall(&randseed);++#ifdef _WIN32+  srand(seed);+#endif++  while (i-- > 0) {+    double x = randall(&seed) / static_cast<double>(RAND_MAX);+    double y = randall(&seed) / static_cast<double>(RAND_MAX);++    // x & y and now values between 0 and 1+    // now do a pythagorean diagonal calculation+    // `1` represents our 1/4 circle+    if ((x * x) + (y * y) <= 1) inside++;+  }++  // calculate ratio and multiply by 4 for π+  return (inside / static_cast<double>(points)) * 4;+}