drop support for squares
[?]
Jun 15, 2022, 3:30 PM
WDMPH4ANFQ4YDIBCKDE5ZSRRNIJFBR5W5CH4VYYFKWS5Q63KHLFACDependencies
- [2]
QW5KQQTDfix a comment - [3]
7OUJM7DLone missing transition between shape modes - [4]
2MA33THZfew more transitions between shapes - [5]
B4YZWV6Sbugfix: checking if a point is on a manhattan line - [6]
2WGRQI5Emissing shape modes in a couple more places - [7]
UN7L3DNNavoid some string concatenations - [8]
LAW2O3NWextract variable Margin_left - [9]
42LVB4DEtest: naming a point - [10]
VVXVV2D2change data model; text can now have metadata - [11]
DRFE3B3Zmouse buttons are integers, not strings - [12]
XXI67EXRdrop non-existent feature from comment - [13]
3RGHOJ25DRY some code - [14]
JCSLDGAHbeginnings of support for multiple shapes - [15]
VHQCNMARseveral more modules - [16]
YCDYGEZUinclude drawing index in a few places - [17]
XNFTJHC4split keyboard handling between Text and Drawing - [18]
2XLZCWZCbugfix: rectangles and squares are now saved - [19]
HYEAFRZ2split mouse_pressed events between Text and Drawing - [20]
BYG5CEMVsupport for naming points - [21]
JFFUF5ALoverride mouse state lookups in tests - [22]
OWK3U6VDtests for drawing polygons - [23]
VDJSUX2Qtypos - [24]
CRYGI3LRmore drawing tests - [25]
WTDKUACNrectangle and square shapes - [26]
QYIFOHW3first test! - [27]
E6TMJY2Tlighter color for in-progress strokes - [28]
NYQ7HD4Dmove - [29]
Y4VYNEGFtest: autosave after name/move/delete of point - [30]
YTSPVDZHfirst successful pagedown test, first bug found by test - [31]
6DE7RBZ6move mouse_released events to Drawing - [32]
SRVDX4I5local var - [33]
WI7R44TDbugfix - [*]
OTIBCAUJlove2d scaffold - [*]
K2X6G75Zstart writing some tests for drawings - [*]
BLWAYPKVextract a module
Change contents
- replacement in main.lua at line 34
-- an array vertices for mode 'polygon', 'rectangle', 'square'-- an array vertices for mode 'rectangle' - edit in main.lua at line 37
-- center, p1, num_vertices for mode 'polygon' - edit in icons.lua at line 50
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
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenelseif shape.mode == 'polygon' or shape.mode == 'rectangle' then - replacement in file.lua at line 60
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenelseif shape.mode == 'polygon' or shape.mode == 'rectangle' then - replacement in file.lua at line 89
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenelseif shape.mode == 'polygon' or shape.mode == 'rectangle' then - replacement in file.lua at line 153
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenelseif shape.mode == 'polygon' or shape.mode == 'rectangle' then - edit in drawing_tests.lua at line 308
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 pixelsApp.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 pointApp.run_after_mouse_press(Margin_left+35, Margin_top+Drawing_padding_top+36, 1)App.run_after_keychord('s') -- square mode-- second point/first edgeApp.mouse_move(Margin_left+42, Margin_top+Drawing_padding_top+45)App.run_after_keychord('p')-- override second point/first edgeApp.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 addedcheck_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
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenelseif 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' thenlocal pmx,pmy = App.mouse_x(), App.mouse_y()local first = drawing.points[shape.vertices[1]]if #shape.vertices == 1 thenlove.graphics.line(Drawing.pixels(first.x)+left,Drawing.pixels(first.y)+top, pmx,pmy)returnendlocal 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
elseif Current_drawing_mode == 'polygon' or Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square' thenelseif 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](∅→∅)
endelseif drawing.pending.mode == 'square' thenassert(#drawing.pending.vertices <= 2)if #drawing.pending.vertices == 2 thenlocal 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 thenlocal 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
elseif drawing.pending.mode == 'square' or drawing.pending.mode == 'rectangle' thenelseif drawing.pending.mode == 'rectangle' then - replacement in drawing.lua at line 361
elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'square' thenelseif 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) thenCurrent_drawing_mode = 'square'elseif App.mouse_down(1) and chord == 's' thenCurrent_drawing_mode = 'square'local _,drawing = Drawing.current_drawing()if drawing.pending.mode == 'freehand' thendrawing.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' thenif drawing.pending.vertices == nil thendrawing.pending.vertices = {drawing.pending.p1}endelseif drawing.pending.mode == 'circle' or drawing.pending.mode == 'arc' thendrawing.pending.vertices = {drawing.pending.center}elseif drawing.pending.mode == 'rectangle' then-- reuse existing (1-2) verticeselseif drawing.pending.mode == 'polygon' thenwhile #drawing.pending.vertices > 2 dotable.remove(drawing.pending.vertices)endenddrawing.pending.mode = 'square' - replacement in drawing.lua at line 370
elseif App.mouse_down(1) and chord == 'p' and (Current_drawing_mode == 'rectangle' or Current_drawing_mode == 'square') thenelseif App.mouse_down(1) and chord == 'p' and Current_drawing_mode == 'rectangle' then - replacement in drawing.lua at line 395
elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thenelseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' then - replacement in drawing.lua at line 406
elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thenelseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' then - replacement in drawing.lua at line 419
elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' thenelseif 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,fourthyendfunction 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 onlocal deltax = secondx-firstxlocal deltay = secondy-firstylocal thirdx = secondx+deltaylocal thirdy = secondy-deltaxif not geom.same_side(firstx,firsty, secondx,secondy, thirdx,thirdy, x,y) thendeltax = -deltaxdeltay = -deltaythirdx = secondx+deltaythirdy = secondy-deltaxendlocal fourthx = firstx+deltaylocal fourthy = firsty-deltax - replacement in drawing.lua at line 580
elseif shape.mode == 'polygon' or shape.mode == 'rectangle' or shape.mode == 'square' thenelseif shape.mode == 'polygon' or shape.mode == 'rectangle' then