Skip to content

Instantly share code, notes, and snippets.

@paniq
Last active September 12, 2017 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paniq/316bb7b248a0182e1ac17fb69430a391 to your computer and use it in GitHub Desktop.
Save paniq/316bb7b248a0182e1ac17fb69430a391 to your computer and use it in GitHub Desktop.
1ddistances.n
none
; provided a list of boolean range operations, find the nearest depth
; at which the ray hits a 100% occluding volume
using "none.libc"
"
+++++++++++ (20 30)
--- (19 21)
+++++++++ (2 10)
--- (4 6)
------- (5 11)
----- (1 5)
* * * *
01234567890123456789012345678901234567890123456789012345678901234567890123456789
0 1 2 3 4 5 6 7
"
var ranges
quote
;
+ 20 30
- 19 21
+ 2 10
- 4 6
- 5 11
- 1 5
function print_ranges ()
foreach (op x0 x1) ranges
x0 =
max x0 0
x1 =
max x1 0
print
..
.rep " " x0
.rep op (x1 - x0 + 1)
.format " (%i %i)" x0 x1
function print_measure ()
print
.rep "0123456789" 8
var k ""
loop i (0 7)
k ..=
.format "%i " i
print k
var steps 0
function dist (t)
var d 1e+20
foreach (op x0 x1) ranges
++ steps
x0 -= t
x1 -= t
do-if (x0 <= d)
switch op
"+"
do-if (x1 > 0)
d =
max x0 0
"-"
d =
max d x1
d
print_ranges ;
var t 0
var k
..
.rep " " t
"*"
loop i (0 100)
var d
dist t
;print d
do-if (d <= 0)
break ;
k ..=
..
.rep " " (d - 1)
"*"
t += d
print k
print_measure ;
print steps "tests"
print t
null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment