add a level of indirection to vertices of shapes

[?]
May 14, 2022, 11:00 PM
IFGAJAF7UWM236QV4NWP2C67TJPQGXNBC2RTZCOWPJUJYYC2MMXAC

Dependencies

  • [2] 4NDYV4WD fix 2 bugs in line selection
  • [3] GP56QHRH bugfix
  • [4] ZD63LJ2T bugfix: keep the click to create a new drawing from creating a new shape in the drawing
  • [5] 6F6DF5T3 .
  • [6] O2UFJ6G3 switch from freehand to just straight lines
  • [7] D2GCFTTT clean up repl functionality
  • [8] R3WSFYGY spacing
  • [9] G77XIN7M selecting a stroke
  • [10] Z2CJVAPV lighter border for figures
  • [11] T76KKDWZ turn strokes into horizontal and vertical lines
  • [12] H7OEU6WP experimental approach to combining keyboard and mouse while drawing
  • [13] 6LJZN727 handle chords
  • [14] EFMLTMZG bugfix: restrict strokes to the drawing they started in
  • [15] OTIBCAUJ love2d scaffold
  • [16] MNWHXPBL more lightweight; select just the stroke at the mouse
  • [17] 3XD6M3CF refactor
  • [18] JVRL5TWL store device-independent coordinates inside drawings
  • [19] XX7G2FFJ intermingle freehand line drawings with text
  • [20] JCSLDGAH beginnings of support for multiple shapes
  • [21] KCIM5UTV revert: back to freehand

Change contents

  • replacement in main.lua at line 78
    [6.500][5.3:86]()
    table.insert(lines, i, {y=y, h=256/2, shapes={}, pending={}})
    [6.500]
    [6.588]
    table.insert(lines, i, {y=y, h=256/2, points={}, shapes={}, pending={}})
  • replacement in main.lua at line 90
    [6.849][6.1268:1307]()
    if on_shape(mx,my, shape) then
    [6.849]
    [6.45]
    if on_shape(mx,my, line, shape) then
  • replacement in main.lua at line 95
    [6.292][4.160:197]()
    draw_shape(16,line.y, shape)
    [6.292]
    [6.1043]
    draw_shape(16,line.y, line, shape)
    end
    for _,p in ipairs(line.points) do
    if p.x == mx and p.y == my then
    love.graphics.setColor(1,0,0)
    else
    love.graphics.setColor(0,0,0)
    end
    love.graphics.circle('line', pixels(p.x)+16,pixels(p.y)+line.y, 4)
  • replacement in main.lua at line 105
    [6.1053][4.198:248]()
    draw_pending_shape(16,line.y, line.pending)
    [6.1053]
    [6.1240]
    draw_pending_shape(16,line.y, line)
  • replacement in main.lua at line 146
    [6.1855][4.472:519](),[4.519][6.1902:1962](),[6.1902][6.1902:1962]()
    lines.current.pending.x2 = coord(x-16)
    lines.current.pending.y2 = coord(y-lines.current.y)
    [6.1855]
    [6.1962]
    local j = insert_point(lines.current.points, coord(x-16), coord(y-lines.current.y))
    lines.current.pending.p2 = j
  • replacement in main.lua at line 164
    [6.2293][4.713:794]()
    drawing.pending = {mode='line', x1=coord(x-16), y1=coord(y-drawing.y)}
    [6.2293]
    [6.2374]
    local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y))
    drawing.pending = {mode='line', p1=j}
  • replacement in main.lua at line 173
    [6.469][6.2387:2424]()
    function draw_shape(left,top, shape)
    [6.469]
    [6.2424]
    function insert_point(points, x,y)
    for i,point in ipairs(points) do
    if point.x == x and point.y == y then
    return i
    end
    end
    table.insert(points, {x=x, y=y})
    return #points
    end
    function draw_shape(left,top, drawing, shape)
  • replacement in main.lua at line 193
    [6.2723][6.2723:2834]()
    love.graphics.line(pixels(shape.x1)+left,pixels(shape.y1)+top, pixels(shape.x2)+left,pixels(shape.y2)+top)
    [6.2723]
    [6.2834]
    local p1 = drawing.points[shape.p1]
    local p2 = drawing.points[shape.p2]
    love.graphics.line(pixels(p1.x)+left,pixels(p1.y)+top, pixels(p2.x)+left,pixels(p2.y)+top)
  • replacement in main.lua at line 199
    [6.2845][6.2845:2890]()
    function draw_pending_shape(left,top, shape)
    [6.2845]
    [6.2890]
    function draw_pending_shape(left,top, drawing)
    local shape = drawing.pending
  • replacement in main.lua at line 202
    [6.2925][6.2925:2957]()
    draw_shape(left,top, shape)
    [6.2925]
    [6.2957]
    draw_shape(left,top, drawing, shape)
  • replacement in main.lua at line 204
    [6.2992][3.3:107]()
    love.graphics.line(pixels(shape.x1)+left,pixels(shape.y1)+top, love.mouse.getX(),love.mouse.getY())
    [6.2992]
    [6.3110]
    local p1 = drawing.points[shape.p1]
    love.graphics.line(pixels(p1.x)+left,pixels(p1.y)+top, love.mouse.getX(),love.mouse.getY())
  • replacement in main.lua at line 209
    [6.3121][6.3121:3151]()
    function on_shape(x,y, shape)
    [6.3121]
    [6.3151]
    function on_shape(x,y, drawing, shape)
  • replacement in main.lua at line 211
    [6.3186][6.3186:3221]()
    return on_freehand(x,y, shape)
    [6.3186]
    [6.3221]
    return on_freehand(x,y, drawing, shape)
  • replacement in main.lua at line 213
    [6.3256][6.3256:3287]()
    return on_line(x,y, shape)
    [6.3256]
    [6.3287]
    return on_line(x,y, drawing, shape)
  • replacement in main.lua at line 219
    [6.3323][6.409:442](),[6.469][6.409:442]()
    function on_freehand(x,y, shape)
    [6.3323]
    [6.442]
    function on_freehand(x,y, drawing, shape)
  • replacement in main.lua at line 223
    [6.502][6.502:567]()
    if on_line(x,y, {x1=prev.x,y1=prev.y, x2=p.x,y2=p.y}) then
    [6.502]
    [6.567]
    if on_line(x,y, drawing, {p1=prev, p2=p}) then
  • replacement in main.lua at line 232
    [6.644][6.644:704](),[6.704][2.37:74]()
    function on_line(x,y, shape)
    if shape.x1 == shape.x2 then
    if math.abs(shape.x1-x) > 5 then
    [6.644]
    [2.74]
    function on_line(x,y, drawing, shape)
    local p1,p2
    if type(shape.p1) == 'number' then
    p1 = drawing.points[shape.p1]
    p2 = drawing.points[shape.p2]
    else
    p1 = shape.p1
    p2 = shape.p2
    end
    if p1.x == p2.x then
    if math.abs(p1.x-x) > 5 then
  • replacement in main.lua at line 245
    [2.101][6.704:740](),[6.704][6.704:740]()
    local y1,y2 = shape.y1,shape.y2
    [2.101]
    [6.740]
    local y1,y2 = p1.y,p2.y
  • replacement in main.lua at line 252
    [6.864][6.864:961]()
    local m = (shape.y2 - shape.y1) / (shape.x2 - shape.x1)
    local yp = shape.y1 + m*(x-shape.x1)
    [6.864]
    [6.961]
    local m = (p2.y - p1.y) / (p2.x - p1.x)
    local yp = p1.y + m*(x-p1.x)
  • replacement in main.lua at line 258
    [6.1044][6.1044:1091]()
    local k = (x-shape.x1) / (shape.x2-shape.x1)
    [6.1044]
    [6.1091]
    local k = (x-p1.x) / (p2.x-p1.x)
  • replacement in main.lua at line 293
    [6.340][6.340:446]()
    drawing.pending.x1 = drawing.pending.points[1].x
    drawing.pending.y1 = drawing.pending.points[1].y
    [6.340]
    [6.877]
    drawing.pending.p1 = insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
  • replacement in main.lua at line 298
    [6.978][6.3362:3388]()
    convert_line(shape)
    [6.978]
    [6.1014]
    convert_line(drawing, shape)
  • replacement in main.lua at line 303
    [6.112][6.3389:3418]()
    convert_horvert(shape)
    [6.112]
    [6.111]
    convert_horvert(drawing, shape)
  • replacement in main.lua at line 353
    [6.1073][6.3461:3490]()
    function convert_line(shape)
    [6.1073]
    [6.1114]
    function convert_line(drawing, shape)
  • replacement in main.lua at line 360
    [6.3548][6.3548:3696]()
    shape.x1 = shape.points[1].x
    shape.y1 = shape.points[1].y
    shape.x2 = shape.points[#shape.points].x
    shape.y2 = shape.points[#shape.points].y
    [6.3548]
    [6.152]
    shape.p1 = insert_point(drawing.points, shape.points[1].x, shape.points[1].y)
    local n = #shape.points
    shape.p2 = insert_point(drawing.points, shape.points[n].x, shape.points[n].y)
  • replacement in main.lua at line 366
    [6.3742][6.3742:3774]()
    function convert_horvert(shape)
    [6.3742]
    [6.3774]
    function convert_horvert(drawing, shape)
  • replacement in main.lua at line 371
    [6.3870][6.3870:3962]()
    if math.abs(shape.x1-shape.x2) > math.abs(shape.y1-shape.y2) then
    shape.y2 = shape.y1
    [6.3870]
    [6.445]
    local p1 = drawing.points[shape.p1]
    local p2 = drawing.points[shape.p2]
    if math.abs(p1.x-p2.x) > math.abs(p1.y-p2.y) then
    p2.y = p1.y
  • replacement in main.lua at line 376
    [6.452][6.3963:3987]()
    shape.x2 = shape.x1
    [6.452]
    [6.505]
    p2.x = p1.x