drop support for squares

[?]
Jun 15, 2022, 3:30 PM
WDMPH4ANFQ4YDIBCKDE5ZSRRNIJFBR5W5CH4VYYFKWS5Q63KHLFAC

Dependencies

  • [2] QW5KQQTD fix a comment
  • [3] 7OUJM7DL one missing transition between shape modes
  • [4] 2MA33THZ few more transitions between shapes
  • [5] B4YZWV6S bugfix: checking if a point is on a manhattan line
  • [6] 2WGRQI5E missing shape modes in a couple more places
  • [7] UN7L3DNN avoid some string concatenations
  • [8] LAW2O3NW extract variable Margin_left
  • [9] 42LVB4DE test: naming a point
  • [10] VVXVV2D2 change data model; text can now have metadata
  • [11] DRFE3B3Z mouse buttons are integers, not strings
  • [12] XXI67EXR drop non-existent feature from comment
  • [13] 3RGHOJ25 DRY some code
  • [14] JCSLDGAH beginnings of support for multiple shapes
  • [15] VHQCNMAR several more modules
  • [16] YCDYGEZU include drawing index in a few places
  • [17] XNFTJHC4 split keyboard handling between Text and Drawing
  • [18] 2XLZCWZC bugfix: rectangles and squares are now saved
  • [19] HYEAFRZ2 split mouse_pressed events between Text and Drawing
  • [20] BYG5CEMV support for naming points
  • [21] JFFUF5AL override mouse state lookups in tests
  • [22] OWK3U6VD tests for drawing polygons
  • [23] VDJSUX2Q typos
  • [24] CRYGI3LR more drawing tests
  • [25] WTDKUACN rectangle and square shapes
  • [26] QYIFOHW3 first test!
  • [27] E6TMJY2T lighter color for in-progress strokes
  • [28] NYQ7HD4D move
  • [29] Y4VYNEGF test: autosave after name/move/delete of point
  • [30] YTSPVDZH first successful pagedown test, first bug found by test
  • [31] 6DE7RBZ6 move mouse_released events to Drawing
  • [32] SRVDX4I5 local var
  • [33] WI7R44TD bugfix
  • [*] OTIBCAUJ love2d scaffold
  • [*] K2X6G75Z start writing some tests for drawings
  • [*] BLWAYPKV extract a module

Change contents

  • replacement in main.lua at line 34
    [10.405][10.405:471]()
    -- an array vertices for mode 'polygon', 'rectangle', 'square'
    [10.405]
    [10.471]
    -- an array vertices for mode 'rectangle'
  • edit in main.lua at line 37
    [2.41]
    [2.41]
    -- center, p1, num_vertices for mode 'polygon'
  • edit in icons.lua at line 50
    [10.6510][10.206:402]()
    function icon.square(x, y)
    love.graphics.line(x+6,y+6, x+6,y+16)
    love.graphics.line(x+6,y+16, x+16,y+16)
    love.graphics.line(x+16,y+16, x+16,y+6)
    love.graphics.line(x+16,y+6, x+6,y+6)
    end
  • replacement in geom.lua at line 28
    [5.518][10.1041:1134](),[10.11923][10.1041:1134]()
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    [5.518]
    [10.11961]
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' then
  • replacement in file.lua at line 60
    [10.1350][10.139:234](),[10.16742][10.139:234]()
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    [10.1350]
    [10.16782]
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' then
  • replacement in file.lua at line 89
    [7.131][10.289:384](),[10.17539][10.289:384]()
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    [7.131]
    [10.17579]
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' then
  • replacement in file.lua at line 153
    [10.2610][10.2610:2705]()
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    [10.2610]
    [10.2705]
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' then
  • edit in drawing_tests.lua at line 308
    [10.7101][10.7101:9419](),[10.9419][9.148:149]()
    function test_draw_square()
    io.write('\ntest_draw_square')
    -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
    App.screen.init{width=Margin_left+300, height=300}
    Lines = load_array{'```lines', '```', ''}
    Line_width = 256 -- drawing coordinates 1:1 with pixels
    App.draw()
    check_eq(Current_drawing_mode, 'line', 'F - test_draw_square/baseline/drawing_mode')
    check_eq(#Lines, 2, 'F - test_draw_square/baseline/#lines')
    check_eq(Lines[1].mode, 'drawing', 'F - test_draw_square/baseline/mode')
    check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_square/baseline/y')
    check_eq(Lines[1].h, 128, 'F - test_draw_square/baseline/y')
    check_eq(#Lines[1].shapes, 0, 'F - test_draw_square/baseline/#shapes')
    -- first point
    App.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)
    App.run_after_keychord('s') -- square mode
    -- second point/first edge
    App.mouse_move(Margin_left+42, Margin_top+Drawing_padding_top+45)
    App.run_after_keychord('p')
    -- override second point/first edge
    App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+66)
    App.run_after_keychord('p')
    -- release (decides which side of first edge to draw square on)
    App.run_after_mouse_release(Margin_left+15, Margin_top+Drawing_padding_top+26, 1)
    local drawing = Lines[1]
    check_eq(#drawing.shapes, 1, 'F - test_draw_square/#shapes')
    check_eq(#drawing.points, 5, 'F - test_draw_square/#points') -- currently includes every point added
    check_eq(drawing.shapes[1].mode, 'square', 'F - test_draw_square/shape_mode')
    check_eq(#drawing.shapes[1].vertices, 4, 'F - test_draw_square/vertices')
    local p = drawing.points[drawing.shapes[1].vertices[1]]
    check_eq(p.x, 35, 'F - test_draw_square/p1:x')
    check_eq(p.y, 36, 'F - test_draw_square/p1:y')
    local p = drawing.points[drawing.shapes[1].vertices[2]]
    check_eq(p.x, 65, 'F - test_draw_square/p2:x')
    check_eq(p.y, 66, 'F - test_draw_square/p2:y')
    local p = drawing.points[drawing.shapes[1].vertices[3]]
    check_eq(p.x, 35, 'F - test_draw_square/p3:x')
    check_eq(p.y, 96, 'F - test_draw_square/p3:y')
    local p = drawing.points[drawing.shapes[1].vertices[4]]
    check_eq(p.x, 5, 'F - test_draw_square/p4:x')
    check_eq(p.y, 66, 'F - test_draw_square/p4:y')
    end
  • replacement in drawing.lua at line 87
    [10.636][10.1653:1746]()
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    [10.636]
    [10.674]
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' then
  • edit in drawing.lua at line 163
    [10.2936][10.2936:2973](),[10.2973][10.1977:2026](),[10.2026][10.3030:4013](),[10.3030][10.3030:4013]()
    elseif shape.mode == 'square' then
    local pmx,pmy = App.mouse_x(), App.mouse_y()
    local first = drawing.points[shape.vertices[1]]
    if #shape.vertices == 1 then
    love.graphics.line(Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top, pmx,pmy)
    return
    end
    local second = drawing.points[shape.vertices[2]]
    local mx,my = Drawing.coord(pmx-left), Drawing.coord(pmy-top)
    local thirdx,thirdy, fourthx,fourthy = Drawing.complete_square(first.x,first.y, second.x,second.y, mx,my)
    love.graphics.line(Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top, Drawing.pixels(second.x)+left,Drawing.pixels(second.y)+top)
    love.graphics.line(Drawing.pixels(second.x)+left,Drawing.pixels(second.y)+top, Drawing.pixels(thirdx)+left,Drawing.pixels(thirdy)+top)
    love.graphics.line(Drawing.pixels(thirdx)+left,Drawing.pixels(thirdy)+top, Drawing.pixels(fourthx)+left,Drawing.pixels(fourthy)+top)
    love.graphics.line(Drawing.pixels(fourthx)+left,Drawing.pixels(fourthy)+top, Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top)
  • replacement in drawing.lua at line 202
    [10.1252][10.4062:4185]()
    elseif Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square' then
    [10.1252]
    [8.3709]
    elseif Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' then
  • edit in drawing.lua at line 301
    [10.5388][10.5388:5400](),[10.5400][10.2221:2366](),[10.2366][8.4635:4716](),[8.4716][10.2438:2649](),[10.2438][10.2438:2649](),[10.2649][10.5882:6000](),[10.5882][10.5882:6000](),[10.6000][10.2650:2918](),[10.2918][10.6304:6318](),[10.6304][10.6304:6318]()
    end
    elseif drawing.pending.mode == 'square' then
    assert(#drawing.pending.vertices <= 2)
    if #drawing.pending.vertices == 2 then
    local mx,my = Drawing.coord(x-Margin_left), Drawing.coord(y-drawing.y)
    if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
    local first = drawing.points[drawing.pending.vertices[1]]
    local second = drawing.points[drawing.pending.vertices[2]]
    local thirdx,thirdy, fourthx,fourthy = Drawing.complete_square(first.x,first.y, second.x,second.y, mx,my)
    table.insert(drawing.pending.vertices, Drawing.insert_point(drawing.points, thirdx,thirdy))
    table.insert(drawing.pending.vertices, Drawing.insert_point(drawing.points, fourthx,fourthy))
    table.insert(drawing.shapes, drawing.pending)
    end
  • replacement in drawing.lua at line 342
    [10.6467][3.10:98]()
    elseif drawing.pending.mode == 'square' or drawing.pending.mode == 'rectangle' then
    [10.6467]
    [3.98]
    elseif drawing.pending.mode == 'rectangle' then
  • replacement in drawing.lua at line 361
    [10.7160][4.11:97]()
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'square' then
    [10.7160]
    [4.97]
    elseif drawing.pending.mode == 'polygon' then
  • edit in drawing.lua at line 365
    [10.7207][10.1878:1933](),[10.1933][10.7267:7303](),[10.2903][10.7267:7303](),[10.7267][10.7267:7303](),[10.7303][10.1934:1983](),[10.1983][10.7357:7393](),[10.2955][10.7357:7393](),[10.7357][10.7357:7393](),[10.7393][10.114:162](),[10.162][10.7439:7954](),[10.7439][10.7439:7954](),[10.7954][4.137:380](),[4.380][10.7954:7998](),[10.7954][10.7954:7998]()
    elseif chord == 'C-s' and not App.mouse_down(1) then
    Current_drawing_mode = 'square'
    elseif App.mouse_down(1) and chord == 's' then
    Current_drawing_mode = 'square'
    local _,drawing = Drawing.current_drawing()
    if drawing.pending.mode == 'freehand' then
    drawing.pending.vertices = {Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)}
    elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
    if drawing.pending.vertices == nil then
    drawing.pending.vertices = {drawing.pending.p1}
    end
    elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
    drawing.pending.vertices = {drawing.pending.center}
    elseif drawing.pending.mode == 'rectangle' then
    -- reuse existing (1-2) vertices
    elseif drawing.pending.mode == 'polygon' then
    while #drawing.pending.vertices > 2 do
    table.remove(drawing.pending.vertices)
    end
    end
    drawing.pending.mode = 'square'
  • replacement in drawing.lua at line 370
    [10.9759][10.9759:9886]()
    elseif App.mouse_down(1) and chord == 'p' and (Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square') then
    [10.9759]
    [10.163]
    elseif App.mouse_down(1) and chord == 'p' and Current_drawing_mode == 'rectangle' then
  • replacement in drawing.lua at line 395
    [10.8053][4.381:506]()
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    [10.8053]
    [10.8103]
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' then
  • replacement in drawing.lua at line 406
    [10.8641][3.132:257]()
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    [10.8641]
    [10.8691]
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' then
  • replacement in drawing.lua at line 419
    [10.9357][4.507:632]()
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
    [10.9357]
    [10.9407]
    elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' then
  • edit in drawing.lua at line 515
    [10.10081][10.10081:10586](),[10.10586][10.11786:11792](),[10.11786][10.11786:11792](),[10.11792][10.10587:10651]()
    return thirdx,thirdy, fourthx,fourthy
    end
    function Drawing.complete_square(firstx,firsty, secondx,secondy, x,y)
    -- use x,y only to decide which side of the first edge to complete the square on
    local deltax = secondx-firstx
    local deltay = secondy-firsty
    local thirdx = secondx+deltay
    local thirdy = secondy-deltax
    if not geom.same_side(firstx,firsty, secondx,secondy, thirdx,thirdy, x,y) then
    deltax = -deltax
    deltay = -deltay
    thirdx = secondx+deltay
    thirdy = secondy-deltax
    end
    local fourthx = firstx+deltay
    local fourthy = firsty-deltax
  • replacement in drawing.lua at line 580
    [10.21152][6.11:104]()
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' then
    [10.21152]
    [10.21190]
    elseif shape.mode == 'polygon' or shape.mode == 'rectangle' then