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U7NY55H46ZYG2APH47BUZT3EJ2HAC
6DE7RBZ6RHNEICJ7EUMCTROK43LW4LYINULIF2QEQOKCXWLUYUXAC
XNFTJHC4QSHNSIWNN7K6QZEZ37GTQYKHS4EPNSVPQCUSWREROGIQC
DRFE3B3ZKRG4RY2R5Q3SDFD3LH4EXUX3CZCDFBNAXVI2SLDS57PAC
YCDYGEZUKVVFRLV5TKF2VYPDXWIHDSZD32KINFARWAJX4X3JPSFAC
7OUJM7DLEE7MRPJ6C3RGVSRVCS6SQLTPO3NY7CYIE6FEALW5VHLAC
2MA33THZH2DRPD7TYP7YXIUKR5E6BAH2BF452TPWYKXMS5I5JRUQC
end
function test_draw_polygon()
io.write('\ntest_draw_polygon')
-- 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_polygon/baseline/drawing_mode')
check_eq(#Lines, 2, 'F - test_draw_polygon/baseline/#lines')
check_eq(Lines[1].mode, 'drawing', 'F - test_draw_polygon/baseline/mode')
check_eq(Lines[1].y, Margin_top+Drawing_padding_top, 'F - test_draw_polygon/baseline/y')
check_eq(Lines[1].h, 128, 'F - test_draw_polygon/baseline/y')
check_eq(#Lines[1].shapes, 0, 'F - test_draw_polygon/baseline/#shapes')
-- first point
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
App.run_after_keychord('g') -- polygon mode
-- second point
App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+36)
App.run_after_keychord('p') -- add point
-- final point
App.run_after_mouse_release(Margin_left+35, Margin_top+Drawing_padding_top+26, 1)
local drawing = Lines[1]
check_eq(#drawing.shapes, 1, 'F - test_draw_polygon/#shapes')
check_eq(#drawing.points, 3, 'F - test_draw_polygon/vertices')
local shape = drawing.shapes[1]
check_eq(shape.mode, 'polygon', 'F - test_draw_polygon/shape_mode')
check_eq(#shape.vertices, 3, 'F - test_draw_polygon/vertices')
local p = drawing.points[shape.vertices[1]]
check_eq(p.x, 5, 'F - test_draw_polygon/p1:x')
check_eq(p.y, 6, 'F - test_draw_polygon/p1:y')
local p = drawing.points[shape.vertices[2]]
check_eq(p.x, 65, 'F - test_draw_polygon/p2:x')
check_eq(p.y, 36, 'F - test_draw_polygon/p2:y')
local p = drawing.points[shape.vertices[3]]
check_eq(p.x, 35, 'F - test_draw_polygon/p3:x')
check_eq(p.y, 26, 'F - test_draw_polygon/p3:y')
end
function test_delete_point_from_polygon()
io.write('\ntest_delete_point_from_polygon')
-- create a drawing with two lines connected at a point
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- first point
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
App.run_after_keychord('g') -- polygon mode
-- second point
App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+36)
App.run_after_keychord('p') -- add point
-- third point
App.mouse_move(Margin_left+35, Margin_top+Drawing_padding_top+26)
App.run_after_keychord('p') -- add point
-- fourth point
App.run_after_mouse_release(Margin_left+14, Margin_top+Drawing_padding_top+16, 1)
local drawing = Lines[1]
check_eq(#drawing.shapes, 1, 'F - test_delete_point_from_polygon/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/baseline/mode')
check_eq(#drawing.shapes[1].vertices, 4, 'F - test_delete_point_from_polygon/baseline/vertices')
-- hover on a point and delete
App.mouse_move(Margin_left+35, Margin_top+Drawing_padding_top+26)
App.run_after_keychord('C-d')
-- just the one point is deleted
check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/shape')
check_eq(#drawing.shapes[1].vertices, 3, 'F - test_delete_point_from_polygon/vertices')
end
function test_delete_point_from_polygon()
io.write('\ntest_delete_point_from_polygon')
-- create a drawing with two lines connected at a point
App.screen.init{width=Margin_left+300, height=300}
Lines = load_array{'```lines', '```', ''}
Line_width = 256 -- drawing coordinates 1:1 with pixels
Current_drawing_mode = 'line'
App.draw()
-- first point
App.run_after_mouse_press(Margin_left+5, Margin_top+Drawing_padding_top+6, 1)
App.run_after_keychord('g') -- polygon mode
-- second point
App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+36)
App.run_after_keychord('p') -- add point
-- third point
App.run_after_mouse_release(Margin_left+14, Margin_top+Drawing_padding_top+16, 1)
local drawing = Lines[1]
check_eq(#drawing.shapes, 1, 'F - test_delete_point_from_polygon/baseline/#shapes')
check_eq(drawing.shapes[1].mode, 'polygon', 'F - test_delete_point_from_polygon/baseline/mode')
check_eq(#drawing.shapes[1].vertices, 3, 'F - test_delete_point_from_polygon/baseline/vertices')
-- hover on a point and delete
App.mouse_move(Margin_left+65, Margin_top+Drawing_padding_top+36)
App.run_after_keychord('C-d')
-- there's < 3 points left, so the whole polygon is deleted
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_point_from_polygon')
-- don't close the loop on a pending polygon
local prev = nil
for _,point in ipairs(shape.vertices) do
local curr = drawing.points[point]
if prev then
love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, Drawing.pixels(curr.x)+left,Drawing.pixels(curr.y)+top)
end
prev = curr
end
love.graphics.line(Drawing.pixels(prev.x)+left,Drawing.pixels(prev.y)+top, App.mouse_x(),App.mouse_y())
-- TODO
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
table.insert(drawing.pending.vertices, Drawing.insert_point(drawing.points, mx,my))
table.insert(drawing.shapes, drawing.pending)
end
-- TODO
elseif chord == 'C-g' and not App.mouse_down(1) then
Current_drawing_mode = 'polygon'
elseif App.mouse_down(1) and chord == 'g' then
Current_drawing_mode = 'polygon'
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 == 'rectangle' then
-- reuse existing vertices
elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
drawing.pending.vertices = {drawing.pending.center}
end
drawing.pending.mode = 'polygon'
elseif App.mouse_down(1) and chord == 'p' and Current_drawing_mode == 'polygon' then
local _,drawing = Drawing.current_drawing()
local mx,my = Drawing.coord(App.mouse_x()-Margin_left), Drawing.coord(App.mouse_y()-drawing.y)
local j = Drawing.insert_point(drawing.points, mx,my)
table.insert(drawing.pending.vertices, j)
elseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then
elseif drawing.pending.mode == 'rectangle' then
drawing.pending.p1 = drawing.pending.vertices[1]
elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' then