From 0b23e5666a9230b076e089341c0b66c19271b59c Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Wed, 6 Apr 2022 15:56:28 +0800 Subject: [PATCH] Szudzik function --- src/__comm__/_pt3_hash.scad | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/__comm__/_pt3_hash.scad b/src/__comm__/_pt3_hash.scad index aed42b89..f2b0b12a 100644 --- a/src/__comm__/_pt3_hash.scad +++ b/src/__comm__/_pt3_hash.scad @@ -1 +1,11 @@ -function _pt3_hash(p) = floor(abs(p * [73856093, 19349669, 83492791])); \ No newline at end of file +function _pt3_hash(p) = + let( + x = p.x >= 0 ? 2 * p.x : -2 * p.x - 1, + y = p.y >= 0 ? 2 * p.y : -2 * p.y - 1, + z = p.z >= 0 ? 2 * p.z : -2 * p.z - 1, + mx = max(x, y, z), + hash = mx ^ 3 + (2 * mx * z) + z + ) + mx == z ? hash + max(x, y) ^ 2 : + y >= x ? hash + x + y : + hash + y; \ No newline at end of file