X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=Operations.lua;h=db9b9a7574644bc332c5b7f4f0486859d1f34ad3;hb=13e125dc80612c40964a06888ac750095752dbac;hp=617916d90c9d1682ecf9eeb2d95de50d78d2ea36;hpb=46c0ad2326b3d4edae71c00b6f4fcecb5eff4e07;p=raymarcher.git diff --git a/Operations.lua b/Operations.lua index 617916d..db9b9a7 100644 --- a/Operations.lua +++ b/Operations.lua @@ -1,25 +1,32 @@ -- Package of geometric operations on SDF objects -local function union(s1, s2) +local function union(sdfs) return function (location) - local p1 = s1(location) - local p2 = s2(location) + local p = sdfs[1](location) + local pp = nil - if p1.dist < p2.dist then - return {dist = p1.dist, texture = p1.texture} - else - return {dist = p2.dist, texture = p2.texture} + for i=2,#sdfs do + pp = sdfs[i](location) + if pp.dist < p.dist then + p = pp + end end + + return p end end -local function diff(s1, s2) +local function diff(sdfs) return function (location) - local p1 = s1(location) - local p2 = s2(location) + local p = sdfs[1](location) + local pp = nil - return {dist = math.max(p1.dist, -p2.dist), - texture = p1.texture} + for i=2,#sdfs do + pp = sdfs[i](location) + p.dist = math.max(p.dist, -pp.dist) + end + + return p end end