Lua: diagonals for selection floodfill
This commit is contained in:
@@ -809,11 +809,13 @@ Example:
|
|||||||
|
|
||||||
Select locations by starting floodfill at (x,y),
|
Select locations by starting floodfill at (x,y),
|
||||||
matching the same map terrain in cardinal directions.
|
matching the same map terrain in cardinal directions.
|
||||||
|
If the optional third parameter is true, also checks diagonals.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
local s = selection.floodfill(sel, x, y);
|
local s = selection.floodfill(sel, x, y);
|
||||||
local s = selection.floodfill(x,y);
|
local s = selection.floodfill(x,y);
|
||||||
|
local s = selection.floodfill(x,y, true);
|
||||||
|
|
||||||
=== get
|
=== get
|
||||||
|
|
||||||
|
|||||||
10
src/nhlsel.c
10
src/nhlsel.c
@@ -570,17 +570,21 @@ l_selection_match(lua_State *L)
|
|||||||
|
|
||||||
|
|
||||||
/* local s = selection.floodfill(x,y); */
|
/* local s = selection.floodfill(x,y); */
|
||||||
|
/* local s = selection.floodfill(x,y, diagonals); */
|
||||||
static int
|
static int
|
||||||
l_selection_flood(lua_State *L)
|
l_selection_flood(lua_State *L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
struct selectionvar *sel = (struct selectionvar *) 0;
|
struct selectionvar *sel = (struct selectionvar *) 0;
|
||||||
xchar x = 0, y = 0;
|
xchar x = 0, y = 0;
|
||||||
|
boolean diagonals = FALSE;
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2 || argc == 3) {
|
||||||
x = (xchar) luaL_checkinteger(L, 1);
|
x = (xchar) luaL_checkinteger(L, 1);
|
||||||
y = (xchar) luaL_checkinteger(L, 2);
|
y = (xchar) luaL_checkinteger(L, 2);
|
||||||
lua_pop(L, 2);
|
if (argc == 3)
|
||||||
|
diagonals = lua_toboolean(L, 3);
|
||||||
|
lua_pop(L, argc);
|
||||||
(void) l_selection_new(L);
|
(void) l_selection_new(L);
|
||||||
sel = l_selection_check(L, 1);
|
sel = l_selection_check(L, 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -593,7 +597,7 @@ l_selection_flood(lua_State *L)
|
|||||||
|
|
||||||
if (isok(x, y)) {
|
if (isok(x, y)) {
|
||||||
set_floodfillchk_match_under(levl[x][y].typ);
|
set_floodfillchk_match_under(levl[x][y].typ);
|
||||||
selection_floodfill(sel, x, y, FALSE);
|
selection_floodfill(sel, x, y, diagonals);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ function test_selection_params()
|
|||||||
selection.fillrect(1,2, 7,8);
|
selection.fillrect(1,2, 7,8);
|
||||||
selection.area(1,2, 7,8);
|
selection.area(1,2, 7,8);
|
||||||
selection.floodfill(1,1);
|
selection.floodfill(1,1);
|
||||||
|
selection.floodfill(1,1, true);
|
||||||
selection.circle(40, 10, 9);
|
selection.circle(40, 10, 9);
|
||||||
selection.circle(40, 10, 9, 1);
|
selection.circle(40, 10, 9, 1);
|
||||||
selection.ellipse(40, 10, 20, 8);
|
selection.ellipse(40, 10, 20, 8);
|
||||||
@@ -357,22 +358,35 @@ function test_sel_filter_mapchar()
|
|||||||
sel_has_n_points(seld, 1659, __func__);
|
sel_has_n_points(seld, 1659, __func__);
|
||||||
end -- test_sel_filter_mapchar
|
end -- test_sel_filter_mapchar
|
||||||
|
|
||||||
function test_sel_flood()
|
function set_flood_test_pattern()
|
||||||
local __func__ = "test_sel_flood";
|
|
||||||
local sela = selection.new();
|
|
||||||
local sela_clone = sela:clone();
|
|
||||||
|
|
||||||
des.terrain(selection.negate(), ".");
|
des.terrain(selection.negate(), ".");
|
||||||
des.terrain(5,5, "L");
|
des.terrain(5,5, "L");
|
||||||
des.terrain(6,5, "L");
|
des.terrain(6,5, "L");
|
||||||
des.terrain(7,5, "L");
|
des.terrain(7,5, "L");
|
||||||
des.terrain(8,6, "L");
|
des.terrain(8,6, "L");
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_sel_flood()
|
||||||
|
local __func__ = "test_sel_flood";
|
||||||
|
local sela = selection.new();
|
||||||
|
local sela_clone = sela:clone();
|
||||||
|
|
||||||
|
set_flood_test_pattern();
|
||||||
|
|
||||||
local selb = selection.floodfill(6,5);
|
local selb = selection.floodfill(6,5);
|
||||||
sel_has_n_points(selb, 3, __func__);
|
sel_has_n_points(selb, 3, __func__);
|
||||||
sel_pt_ne(selb, 5,5, 1, __func__);
|
sel_pt_ne(selb, 5,5, 1, __func__);
|
||||||
sel_pt_ne(selb, 6,5, 1, __func__);
|
sel_pt_ne(selb, 6,5, 1, __func__);
|
||||||
sel_pt_ne(selb, 7,5, 1, __func__);
|
sel_pt_ne(selb, 7,5, 1, __func__);
|
||||||
|
|
||||||
|
set_flood_test_pattern();
|
||||||
|
|
||||||
|
local selc = selection.floodfill(6,5, true);
|
||||||
|
sel_has_n_points(selc, 4, __func__);
|
||||||
|
sel_pt_ne(selc, 5,5, 1, __func__);
|
||||||
|
sel_pt_ne(selc, 6,5, 1, __func__);
|
||||||
|
sel_pt_ne(selc, 7,5, 1, __func__);
|
||||||
|
sel_pt_ne(selc, 8,6, 1, __func__);
|
||||||
end -- test_sel_flood
|
end -- test_sel_flood
|
||||||
|
|
||||||
function test_sel_match()
|
function test_sel_match()
|
||||||
|
|||||||
Reference in New Issue
Block a user