revert: back to freehand

[?]
May 14, 2022, 6:59 PM
KCIM5UTVV4KIL7SNRZFOW6FUQHGWAPOGQO4QTVNIWWBWMVG6GYNQC

Dependencies

  • [2] O2UFJ6G3 switch from freehand to just straight lines
  • [3] EFMLTMZG bugfix: restrict strokes to the drawing they started in
  • [4] G77XIN7M selecting a stroke
  • [5] 3XD6M3CF refactor
  • [6] KVHUFUFV reorg
  • [7] Z2CJVAPV lighter border for figures
  • [8] MNWHXPBL more lightweight; select just the stroke at the mouse
  • [9] T76KKDWZ turn strokes into horizontal and vertical lines
  • [10] WAZVXUV2 simplest possible way to straighten strokes
  • [11] JVRL5TWL store device-independent coordinates inside drawings
  • [12] OTIBCAUJ love2d scaffold
  • [13] U76D4P36 fix a typo
  • [14] XX7G2FFJ intermingle freehand line drawings with text
  • [*] 6LJZN727 handle chords
  • [*] D2GCFTTT clean up repl functionality

Change contents

  • replacement in main.lua at line 60
    [3.849][2.3:41]()
    if on_line(mx,my, shape) then
    [3.849]
    [3.45]
    if on_freehand(mx,my, shape) then
  • replacement in main.lua at line 65
    [3.150][2.42:159]()
    love.graphics.line(pixels(shape.x1)+12,pixels(shape.y1)+line.y, pixels(shape.x2)+12,pixels(shape.y2)+line.y)
    [3.150]
    [3.1043]
    prev = nil
    for _,point in ipairs(shape) do
    if prev then
    love.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)
    end
    prev = point
    end
  • replacement in main.lua at line 73
    [3.1053][2.160:313]()
    if line.pending.x1 then
    love.graphics.line(pixels(line.pending.x1)+12,pixels(line.pending.y1)+line.y, love.mouse.getX(),love.mouse.getY())
    [3.1053]
    [3.1230]
    prev = nil
    for _,point in ipairs(line.pending) do
    if prev then
    love.graphics.line(pixels(prev.x)+12,pixels(prev.y)+line.y, pixels(point.x)+12,pixels(point.y)+line.y)
    end
    prev = point
  • edit in main.lua at line 100
    [3.957]
    [3.1647]
    table.insert(drawing.pending, {x=coord(love.mouse.getX()-12), y=coord(love.mouse.getY()-drawing.y)})
  • edit in main.lua at line 110
    [3.142][2.314:658]()
    end
    function love.mousereleased(x,y, button)
    if lines.current then
    if lines.current.pending then
    lines.current.pending.x2 = coord(x-12)
    lines.current.pending.y2 = coord(y-lines.current.y)
    table.insert(lines.current.shapes, lines.current.pending)
    lines.current.pending = {}
    lines.current = nil
    end
    end
  • edit in main.lua at line 117
    [3.1168][2.659:725]()
    drawing.pending = {x1=coord(x-12), y1=coord(y-drawing.y)}
  • edit in main.lua at line 158
    [3.1128]
    [16.23]
    function love.mousereleased(x,y, button)
    if lines.current then
    if lines.current.pending then
    table.insert(lines.current.shapes, lines.current.pending)
    lines.current.pending = {}
    lines.current = nil
    end
    end
    end
  • edit in main.lua at line 190
    [17.1135]
    [3.11]
    elseif chord == 'C-l' then
    local drawing,i,shape = select_shape_at_mouse()
    if drawing then
    convert_line(drawing,i,shape)
    end
  • replacement in main.lua at line 210
    [3.433][2.726:766]()
    if on_line(mx,my, shape) then
    [3.433]
    [3.507]
    if on_freehand(mx,my, shape) then
  • edit in main.lua at line 217
    [3.607]
    [3.152]
    end
    function convert_line(drawing, i, shape)
    -- Perhaps we should do a more sophisticated "simple linear regression"
    -- here:
    -- https://en.wikipedia.org/wiki/Linear_regression#Simple_and_multiple_linear_regression
    -- But this works well enough for close-to-linear strokes.
    drawing.shapes[i] = {shape[1], shape[#shape]}
  • replacement in main.lua at line 229
    [3.260][2.767:859]()
    if math.abs(shape.x1-shape.x2) > math.abs(shape.y1-shape.y2) then
    shape.y2 = shape.y1
    [3.260]
    [3.445]
    local x1,y1 = shape[1].x, shape[1].y
    local x2,y2 = shape[#shape].x, shape[#shape].y
    if math.abs(x1-x2) > math.abs(y1-y2) then
    drawing.shapes[i] = {{x=x1, y=y1}, {x=x2, y=y1}}
  • replacement in main.lua at line 234
    [3.452][2.860:884]()
    shape.x2 = shape.x1
    [3.452]
    [3.505]
    drawing.shapes[i] = {{x=x1, y=y1}, {x=x1, y=y2}}