From fe8711224a4aab7cb8fe8109283f04b07ac47b73 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 26 Nov 2023 19:00:11 -0800 Subject: [PATCH 1/2] delete some early debug UI code --- 0023-on.keychord_press | 8 +------- 0026-on.draw | 5 +---- 0113-draw_debug_ui1 | 8 -------- 0114-Debug_draw_fn | 1 - 4 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 0113-draw_debug_ui1 delete mode 100644 0114-Debug_draw_fn diff --git a/0023-on.keychord_press b/0023-on.keychord_press index 7e6cd3a..6d6fc6b 100644 --- a/0023-on.keychord_press +++ b/0023-on.keychord_press @@ -88,12 +88,6 @@ on.keychord_press = function(chord, key) elseif chord == 'S-right' then Viewport.x = Viewport.x + App.screen.width/Viewport.zoom B() - elseif chord == 'M-1' then - if Debug_draw_fn ~= draw_debug_ui1 then - Debug_draw_fn = draw_debug_ui1 - else - Debug_draw_fn = nil - end end end -end +end \ No newline at end of file diff --git a/0026-on.draw b/0026-on.draw index 26cd188..5cb5914 100644 --- a/0026-on.draw +++ b/0026-on.draw @@ -34,7 +34,4 @@ on.draw = function() draw_test_failure_indicator() draw_ticks() draw_menu_bar() - if Debug_draw_fn then - Debug_draw_fn() - end -end +end \ No newline at end of file diff --git a/0113-draw_debug_ui1 b/0113-draw_debug_ui1 deleted file mode 100644 index 21b043d..0000000 --- a/0113-draw_debug_ui1 +++ /dev/null @@ -1,8 +0,0 @@ -draw_debug_ui1 = function() - local x, y = App.screen.width/3, App.screen.height/3 - local w, h = App.screen.width/3, App.screen.height/3 - App.color{r=1, g=1, b=1} - love.graphics.rectangle('fill', x,y, w, h) - App.color{r=0, g=0, b=0} - love.graphics.rectangle('line', x+10, y+10, w-20, h-20, 5,5) -end \ No newline at end of file diff --git a/0114-Debug_draw_fn b/0114-Debug_draw_fn deleted file mode 100644 index d484f03..0000000 --- a/0114-Debug_draw_fn +++ /dev/null @@ -1 +0,0 @@ -Debug_draw_fn = nil \ No newline at end of file From 6ae88ace5460f420b9e7673779158a6d44eb54c6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 26 Nov 2023 22:55:54 -0800 Subject: [PATCH 2/2] spawning tries 10 times to avoid overlap --- 0018-on.update | 3 ++- 0023-on.keychord_press | 6 ++++-- 0026-on.draw | 1 + 0116-spawn_point | 18 ++++++++++++++---- 0117-straddles_interval | 3 +++ 0118-overlapping_intervals | 6 ++++++ 0119-overlapping_areas | 5 +++++ 0120-overlaps_any_definition | 9 +++++++++ 0121-draw_debug | 3 +++ 0122-Show_debug | 1 + 0124-draw_debug_definitions | 12 ++++++++++++ 0125-Spawn_candidates | 1 + 0126-test_overlapping_areas | 7 +++++++ 0127-test_straddles_interval | 3 +++ 0128-test_overlapping_intervals | 3 +++ 15 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 0117-straddles_interval create mode 100644 0118-overlapping_intervals create mode 100644 0119-overlapping_areas create mode 100644 0120-overlaps_any_definition create mode 100644 0121-draw_debug create mode 100644 0122-Show_debug create mode 100644 0124-draw_debug_definitions create mode 100644 0125-Spawn_candidates create mode 100644 0126-test_overlapping_areas create mode 100644 0127-test_straddles_interval create mode 100644 0128-test_overlapping_intervals diff --git a/0018-on.update b/0018-on.update index 44f8294..ec139f6 100644 --- a/0018-on.update +++ b/0018-on.update @@ -1,4 +1,5 @@ on.update = function(dt) + refresh_debug_animations() if Animating then animate_next(dt) return @@ -24,4 +25,4 @@ on.update = function(dt) A1(Move.node.key) return end -end \ No newline at end of file +end diff --git a/0023-on.keychord_press b/0023-on.keychord_press index 6d6fc6b..0bac397 100644 --- a/0023-on.keychord_press +++ b/0023-on.keychord_press @@ -5,7 +5,9 @@ on.keychord_press = function(chord, key) if Manifest_navigator.reload then load_manifest() end - if chord == 'C-=' then + if chord == 'f5' then + Show_debug = not Show_debug + elseif chord == 'C-=' then -- zoom in Viewport.zoom = Viewport.zoom+0.1 A() @@ -31,7 +33,7 @@ on.keychord_press = function(chord, key) elseif Manifest_navigator.show then keychord_press_on_manifest_navigator(chord, key) elseif chord == 'C-n' then - new_definition() + animate(new_definition) A() elseif chord == 'C-l' then Manifest_navigator.show = true diff --git a/0026-on.draw b/0026-on.draw index 5cb5914..575fc0e 100644 --- a/0026-on.draw +++ b/0026-on.draw @@ -33,5 +33,6 @@ on.draw = function() draw_run_time_error() draw_test_failure_indicator() draw_ticks() + if Show_debug then draw_debug() end draw_menu_bar() end \ No newline at end of file diff --git a/0116-spawn_point b/0116-spawn_point index f618892..8935b3e 100644 --- a/0116-spawn_point +++ b/0116-spawn_point @@ -1,6 +1,16 @@ spawn_point = function() - return { - x = math.random(Viewport.x, Viewport.x+Viewport.w), - y = math.random(Viewport.y, Viewport.y+Viewport.h), - } + Spawn_candidates = {} + for _=1,10 do + local result = {w=600, h=100} + result.x = math.random(Viewport.x, Viewport.x+Viewport.w) + result.x = round(result.x/100)*100 + result.y = math.random(Viewport.y, Viewport.y+Viewport.h) + if _ == 10 or not overlaps_any_definition(result) then + result.w, result.h = nil + result.x = result.x + 100 + result.y = result.y + 20 + return result + end + table.insert(Spawn_candidates, result) + end end \ No newline at end of file diff --git a/0117-straddles_interval b/0117-straddles_interval new file mode 100644 index 0000000..eb48924 --- /dev/null +++ b/0117-straddles_interval @@ -0,0 +1,3 @@ +straddles_interval = function(lo,hi, border) + return lo <= border and hi >= border +end \ No newline at end of file diff --git a/0118-overlapping_intervals b/0118-overlapping_intervals new file mode 100644 index 0000000..303068a --- /dev/null +++ b/0118-overlapping_intervals @@ -0,0 +1,6 @@ +overlapping_intervals = function(alo,ahi, blo,bhi) + return straddles_interval(alo,ahi, blo) + or straddles_interval(alo,ahi, bhi) + or straddles_interval(blo, bhi, alo) + or straddles_interval(blo, bhi, ahi) +end \ No newline at end of file diff --git a/0119-overlapping_areas b/0119-overlapping_areas new file mode 100644 index 0000000..ca64d71 --- /dev/null +++ b/0119-overlapping_areas @@ -0,0 +1,5 @@ +-- return true if a is less than some distance from b +overlapping_areas = function(a, b) + return overlapping_intervals(a.x, a.x+a.w, b.x-20, b.x+b.w+20) + and overlapping_intervals(a.y, a.y+a.h, b.y-20, b.y+b.h+60) -- leave more space below existing definitions +end \ No newline at end of file diff --git a/0120-overlaps_any_definition b/0120-overlaps_any_definition new file mode 100644 index 0000000..e14d51a --- /dev/null +++ b/0120-overlaps_any_definition @@ -0,0 +1,9 @@ +overlaps_any_definition = function(box) + for k,def in pairs(Definitions) do + if overlapping_areas(box, def) then + print(def.key) + box.name = def.key + return true + end + end +end \ No newline at end of file diff --git a/0121-draw_debug b/0121-draw_debug new file mode 100644 index 0000000..1c96494 --- /dev/null +++ b/0121-draw_debug @@ -0,0 +1,3 @@ +draw_debug = function() + draw_debug_definitions() +end \ No newline at end of file diff --git a/0122-Show_debug b/0122-Show_debug new file mode 100644 index 0000000..78d0d57 --- /dev/null +++ b/0122-Show_debug @@ -0,0 +1 @@ +Show_debug = false \ No newline at end of file diff --git a/0124-draw_debug_definitions b/0124-draw_debug_definitions new file mode 100644 index 0000000..73e37d0 --- /dev/null +++ b/0124-draw_debug_definitions @@ -0,0 +1,12 @@ +draw_debug_definitions = function() + for k,def in pairs(Definitions) do + App.color{r=1, g=0, b=0} +-- love.graphics.rectangle('line', vx(def.x-20), vy(def.y-20), scale(620), scale(30)) + love.graphics.rectangle('line', vx(def.x-20), vy(def.y-20), scale(def.w+20), scale(def.h+60)) + end + for _,cand in ipairs(Spawn_candidates) do + App.color{r=0.4, g=0.8, b=0.4} + love.graphics.rectangle('line', vx(cand.x), vy(cand.y), scale(800), scale(140)) + love.graphics.print(cand.name, vx(cand.x), vy(cand.y)) + end +end \ No newline at end of file diff --git a/0125-Spawn_candidates b/0125-Spawn_candidates new file mode 100644 index 0000000..7e5fd7a --- /dev/null +++ b/0125-Spawn_candidates @@ -0,0 +1 @@ +Spawn_candidates = {} \ No newline at end of file diff --git a/0126-test_overlapping_areas b/0126-test_overlapping_areas new file mode 100644 index 0000000..46157bb --- /dev/null +++ b/0126-test_overlapping_areas @@ -0,0 +1,7 @@ +test_overlapping_areas = function() + check( + overlapping_areas( + {x=0, y=0, w=1, h=1}, + {x=0, y=0, w=1, h=1}), + 'identical') +end \ No newline at end of file diff --git a/0127-test_straddles_interval b/0127-test_straddles_interval new file mode 100644 index 0000000..e257c58 --- /dev/null +++ b/0127-test_straddles_interval @@ -0,0 +1,3 @@ +test_straddles_interval = function() + check(straddles_interval(-20, 21, 0), '1') +end \ No newline at end of file diff --git a/0128-test_overlapping_intervals b/0128-test_overlapping_intervals new file mode 100644 index 0000000..94a655e --- /dev/null +++ b/0128-test_overlapping_intervals @@ -0,0 +1,3 @@ +test_overlapping_intervals = function() + check(overlapping_intervals(0, 1, -20, 21), 'within') +end \ No newline at end of file