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AC
BLWAYPKV3MLDZ4ALXLUJ25AIR6PCIL4RFYNRYLB26GFVC2KQBYBAC
JFFUF5ALUWPDM7IEDEZVAYG2SVXO334STONRGKVB3QKY2TT5QGBQC
HYEAFRZ2UEKDYTAE2GDQLHEJBPQASP2NDLMXB7F6MTVK2BKOXKEAC
SRVDX4I5QKWAH3Y5DX25PG34U7NY55H46ZYG2APH47BUZT3EJ2HAC
XNFTJHC4QSHNSIWNN7K6QZEZ37GTQYKHS4EPNSVPQCUSWREROGIQC
DRFE3B3ZKRG4RY2R5Q3SDFD3LH4EXUX3CZCDFBNAXVI2SLDS57PAC
YCDYGEZUKVVFRLV5TKF2VYPDXWIHDSZD32KINFARWAJX4X3JPSFAC
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
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)
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
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'
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