Make lua selection line create a new selection
... instead of modifying the one given as a parameter. Also add some tests for it.
This commit is contained in:
+8
-11
@@ -29,26 +29,23 @@ if math.random(0,99) < 75 then
|
|||||||
local tidx = math.random(1, #terrains);
|
local tidx = math.random(1, #terrains);
|
||||||
local choice = math.random(0, 4);
|
local choice = math.random(0, 4);
|
||||||
if choice == 0 then
|
if choice == 0 then
|
||||||
|
-- one horizontal line
|
||||||
des.terrain(selection.line(10,8, 65,8), terrains[tidx]);
|
des.terrain(selection.line(10,8, 65,8), terrains[tidx]);
|
||||||
elseif choice == 1 then
|
elseif choice == 1 then
|
||||||
local sel = selection.new();
|
-- two vertical lines
|
||||||
sel:line(15,4, 15, 13);
|
local sel = selection.line(15,4, 15, 13) | selection.line(59,4, 59, 13);
|
||||||
sel:line(59,4, 59, 13);
|
|
||||||
des.terrain(sel, terrains[tidx]);
|
des.terrain(sel, terrains[tidx]);
|
||||||
elseif choice == 2 then
|
elseif choice == 2 then
|
||||||
local sel = selection.new();
|
-- plus sign
|
||||||
sel:line(10,8, 38, 8);
|
local sel = selection.line(10,8, 64, 8) | selection.line(37,3, 37, 14);
|
||||||
sel:line(37,8, 65, 8);
|
|
||||||
sel:line(37,3, 37, 8);
|
|
||||||
sel:line(37,8, 37,14);
|
|
||||||
des.terrain(sel, terrains[tidx]);
|
des.terrain(sel, terrains[tidx]);
|
||||||
elseif choice == 3 then
|
elseif choice == 3 then
|
||||||
|
-- brackets: [ ]
|
||||||
des.terrain(selection.rect(4,4, 70,13), terrains[tidx]);
|
des.terrain(selection.rect(4,4, 70,13), terrains[tidx]);
|
||||||
local sel = selection.new();
|
local sel = selection.line(25,4, 50,4) | selection.line(25,13, 50,13);
|
||||||
sel:line(25,4, 50,4);
|
|
||||||
sel:line(25,13, 50,13);
|
|
||||||
des.terrain(sel, '.');
|
des.terrain(sel, '.');
|
||||||
else
|
else
|
||||||
|
-- nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -334,6 +334,10 @@ lua_State *L;
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* internal function to get a selection and 4 integer values from lua stack.
|
||||||
|
removes the integers from the stack.
|
||||||
|
returns TRUE if params are good.
|
||||||
|
*/
|
||||||
/* function(selection, x1,y1, x2,y2) */
|
/* function(selection, x1,y1, x2,y2) */
|
||||||
/* selection:function(x1,y1, x2,y2) */
|
/* selection:function(x1,y1, x2,y2) */
|
||||||
static boolean
|
static boolean
|
||||||
@@ -362,6 +366,7 @@ schar *x1, *y1, *x2, *y2;
|
|||||||
*y1 = (schar) luaL_checkinteger(L, 3);
|
*y1 = (schar) luaL_checkinteger(L, 3);
|
||||||
*x2 = (schar) luaL_checkinteger(L, 4);
|
*x2 = (schar) luaL_checkinteger(L, 4);
|
||||||
*y2 = (schar) luaL_checkinteger(L, 5);
|
*y2 = (schar) luaL_checkinteger(L, 5);
|
||||||
|
lua_pop(L, 4);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -387,8 +392,10 @@ lua_State *L;
|
|||||||
get_location_coord(&x1, &y1, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x1,y1));
|
get_location_coord(&x1, &y1, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x1,y1));
|
||||||
get_location_coord(&x2, &y2, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x2,y2));
|
get_location_coord(&x2, &y2, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x2,y2));
|
||||||
|
|
||||||
selection_do_line(x1,y1,x2,y2, sel);
|
|
||||||
lua_settop(L, 1);
|
lua_settop(L, 1);
|
||||||
|
(void) l_selection_clone(L);
|
||||||
|
sel = l_selection_check(L, 1);
|
||||||
|
selection_do_line(x1,y1,x2,y2, sel);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -227,9 +227,27 @@ function test_sel_filter_percent()
|
|||||||
-- TODO: Need a predictable rn2 to test for percentage(50)
|
-- TODO: Need a predictable rn2 to test for percentage(50)
|
||||||
end -- test_sel_filter_percent
|
end -- test_sel_filter_percent
|
||||||
|
|
||||||
|
function test_sel_line()
|
||||||
|
local __func__ = "test_sel_line";
|
||||||
|
local sela = selection.new();
|
||||||
|
local sela_clone = sela:clone();
|
||||||
|
|
||||||
|
local selb = sela:line(1,1, 5,5);
|
||||||
|
sel_are_equal(sela, sela_clone, __func__);
|
||||||
|
sel_has_n_points(selb, 5, __func__);
|
||||||
|
for x = 1, 5 do
|
||||||
|
sel_pt_ne(selb, x,x, 1, __func__);
|
||||||
|
end
|
||||||
|
|
||||||
|
local selc = selb:line(10,1, 10,5);
|
||||||
|
sel_has_n_points(selc, 10, __func__);
|
||||||
|
|
||||||
|
end -- test_sel_line
|
||||||
|
|
||||||
test_selection_params();
|
test_selection_params();
|
||||||
test_sel_negate();
|
test_sel_negate();
|
||||||
test_sel_logical_and();
|
test_sel_logical_and();
|
||||||
test_sel_logical_or();
|
test_sel_logical_or();
|
||||||
test_sel_logical_xor();
|
test_sel_logical_xor();
|
||||||
test_sel_filter_percent();
|
test_sel_filter_percent();
|
||||||
|
test_sel_line();
|
||||||
|
|||||||
Reference in New Issue
Block a user