From 160d2e67ac8de27583f47338b060edaf5d5fd200 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 3 Jul 2022 10:37:23 +0800 Subject: [PATCH] refactor --- src/pp/_impl/_pp_poisson2.scad | 17 +++++++++++------ src/pp/_impl/_pp_poisson3.scad | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/pp/_impl/_pp_poisson2.scad b/src/pp/_impl/_pp_poisson2.scad index d77ff5e9..fd50c0b4 100644 --- a/src/pp/_impl/_pp_poisson2.scad +++ b/src/pp/_impl/_pp_poisson2.scad @@ -29,14 +29,19 @@ function sampling_inRow(s, y) = y > -1 && y < sampling_rows(s); function sampling_inGrid(s, x, y) = sampling_inRow(s, y) && x > -1 && x < sampling_columns(s); +NBRS = [ + [-1, -1], [0, -1], [1, -1], + [-1, 0], [0, 0], [1, 0], + [-1, 1], [0, 1], [1, 1] +]; + function sampling_noAdjacentNeighbor(s, sample, x, y) = + let(me = [x, y]) every( - [ - [x - 1, y - 1], [x, y - 1], [x + 1, y - 1], - [x - 1, y], [x, y], [x + 1, y], - [x - 1, y + 1], [x, y + 1], [x + 1, y + 1] - ], - function(nbr) !sampling_inRow(s, nbr.y) || + NBRS, + function(NBR) + let(nbr = me + NBR) + !sampling_inRow(s, nbr.y) || (let(p = sampling_grid(s)[nbr.y][nbr.x]) is_undef(p) || norm(sample - p) >= sampling_r(s)) diff --git a/src/pp/_impl/_pp_poisson3.scad b/src/pp/_impl/_pp_poisson3.scad index f63b1068..e4b3ff66 100644 --- a/src/pp/_impl/_pp_poisson3.scad +++ b/src/pp/_impl/_pp_poisson3.scad @@ -71,7 +71,7 @@ function sampling_noAdjacentNeighbor(s, sample, x, y, z) = function sampling_randomSample(s, pos, seed) = let( r = sampling_r(s), - theta = rands(0, 360, 1, seed)[0] - 180, + theta = rands(-180, 180, 1, seed)[0], phi = rands(0, 180, 1, seed + 1)[0], sin_phi = sin(phi) )