Make lua selection grow create a new selection
This commit is contained in:
@@ -515,11 +515,18 @@ static int
|
|||||||
l_selection_grow(L)
|
l_selection_grow(L)
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
{
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
const char *const growdirs[] = { "all", "random", "north", "west", "east", "south", NULL };
|
const char *const growdirs[] = { "all", "random", "north", "west", "east", "south", NULL };
|
||||||
const int growdirs2i[] = { W_ANY, -1, W_NORTH, W_WEST, W_EAST, W_SOUTH, 0 };
|
const int growdirs2i[] = { W_ANY, -1, W_NORTH, W_WEST, W_EAST, W_SOUTH, 0 };
|
||||||
|
|
||||||
struct selectionvar *sel = l_selection_check(L, 1);
|
struct selectionvar *sel = l_selection_check(L, 1);
|
||||||
int dir = growdirs2i[luaL_checkoption(L, 2, "all", growdirs)];
|
int dir = growdirs2i[luaL_checkoption(L, 2, "all", growdirs)];
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
lua_pop(L, 1); /* get rid of growdir */
|
||||||
|
|
||||||
|
(void) l_selection_clone(L);
|
||||||
|
sel = l_selection_check(L, 1);
|
||||||
selection_do_grow(sel, dir);
|
selection_do_grow(sel, dir);
|
||||||
lua_settop(L, 1);
|
lua_settop(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -292,6 +292,36 @@ function test_sel_randline()
|
|||||||
end
|
end
|
||||||
end -- test_sel_randline
|
end -- test_sel_randline
|
||||||
|
|
||||||
|
function test_sel_grow()
|
||||||
|
local __func__ = "test_sel_grow";
|
||||||
|
local sela = selection.new();
|
||||||
|
|
||||||
|
sela:set(5,5);
|
||||||
|
|
||||||
|
local sela_clone = sela:clone();
|
||||||
|
|
||||||
|
local selb = sela:grow();
|
||||||
|
sel_are_equal(sela, sela_clone, __func__);
|
||||||
|
sel_has_n_points(selb, 9, __func__);
|
||||||
|
for x = 4,6 do
|
||||||
|
for y = 4,6 do
|
||||||
|
sel_pt_ne(selb, x,y, 1, __func__);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local selc = sela:grow("north");
|
||||||
|
sel_has_n_points(selc, 2, __func__);
|
||||||
|
sel_pt_ne(selc, 5,5, 1, __func__);
|
||||||
|
sel_pt_ne(selc, 5,4, 1, __func__);
|
||||||
|
|
||||||
|
local seld = selc:grow("east");
|
||||||
|
sel_has_n_points(seld, 4, __func__);
|
||||||
|
sel_pt_ne(seld, 5,5, 1, __func__);
|
||||||
|
sel_pt_ne(seld, 5,4, 1, __func__);
|
||||||
|
sel_pt_ne(seld, 6,5, 1, __func__);
|
||||||
|
sel_pt_ne(seld, 6,4, 1, __func__);
|
||||||
|
end -- test_sel_grow
|
||||||
|
|
||||||
test_selection_params();
|
test_selection_params();
|
||||||
test_sel_negate();
|
test_sel_negate();
|
||||||
test_sel_logical_and();
|
test_sel_logical_and();
|
||||||
@@ -302,3 +332,4 @@ test_sel_line();
|
|||||||
test_sel_rect();
|
test_sel_rect();
|
||||||
test_sel_fillrect();
|
test_sel_fillrect();
|
||||||
test_sel_randline();
|
test_sel_randline();
|
||||||
|
test_sel_grow();
|
||||||
|
|||||||
Reference in New Issue
Block a user