Alias for <<_fillrect>>.
+=== bounds
+
+Get the bounding box for the selection. Returns a table with lx, ly, hx, hy integer fields.
+
+Example:
+
+ local rect = sel:bounds();
+ local s = string.format("(%i,%i)-(%i,%i)", rect.lx, rect.ly, rect.hx, rect.hy));
+
+
=== circle
Example:
static int l_selection_setpoint(lua_State *);
static int l_selection_filter_percent(lua_State *);
static int l_selection_rndcoord(lua_State *);
+static int l_selection_getbounds(lua_State *);
static boolean params_sel_2coords(lua_State *, struct selectionvar **,
coordxy *, coordxy *, coordxy *, coordxy *);
static int l_selection_line(lua_State *);
return 1;
}
+/* local rect = sel:bounds(); */
+static int
+l_selection_getbounds(lua_State *L)
+{
+ struct selectionvar *sel = l_selection_check(L, 1);
+ NhRect rect;
+
+ selection_getbounds(sel, &rect);
+ lua_settop(L, 0);
+ lua_newtable(L);
+ nhl_add_table_entry_int(L, "lx", rect.lx);
+ nhl_add_table_entry_int(L, "ly", rect.ly);
+ nhl_add_table_entry_int(L, "hx", rect.hx);
+ nhl_add_table_entry_int(L, "hy", rect.hy);
+ return 1;
+}
+
/* 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.
{ "ellipse", l_selection_ellipse },
{ "gradient", l_selection_gradient },
{ "iterate", l_selection_iterate },
+ { "bounds", l_selection_getbounds },
{ NULL, NULL }
};
is_map_at(5,5, "L");
is_map_at(7,5, "L");
is_map_at(9,5, "L");
+
+end
+
+function test_sel_bounds()
+ local __func__ = "test_sel_bounds";
+ local sel = selection.new();
+ sel:set(5, 5);
+ sel:set(7, 5);
+ sel:set(5, 6);
+
+ local rect = sel:bounds();
+ if (rect.lx ~= (5 + 1) or rect.ly ~= 5 or rect.hx ~= (7 + 1) or rect.hy ~= 6) then
+ error(string.format("selection bounds error:(%i,%i-%i,%i)", rect.lx, rect.ly, rect.hx, rect.hy));
+ end
end
nh.debug_flags({mongen = false, hunger = false, overwrite_stairs = true });
test_sel_flood();
test_sel_match();
test_sel_iterate();
+test_sel_bounds();