MCPcopy Create free account
hub / github.com/NetHack/NetHack / l_selection_sub

Function l_selection_sub

src/nhlsel.c:360–385  ·  view source on GitHub ↗

local sel = selection.area(10,10, 20,20) - selection.area(14,14, 17,17) * - i.e. points that are in A but not in B */

Source from the content-addressed store, hash-verified

358/* local sel = selection.area(10,10, 20,20) - selection.area(14,14, 17,17)
359 * - i.e. points that are in A but not in B */
360staticfn int
361l_selection_sub(lua_State *L)
362{
363 int x,y;
364 struct selectionvar *sela = l_selection_check(L, 1);
365 struct selectionvar *selb = l_selection_check(L, 2);
366 struct selectionvar *selr = l_selection_push_new(L);
367 NhRect rect = cg.zeroNhRect;
368
369 rect_bounds(sela->bounds, selb->bounds, &rect);
370
371 for (x = rect.lx; x <= rect.hx; x++)
372 for (y = rect.ly; y <= rect.hy; y++) {
373 coordxy a_pt = selection_getpoint(x, y, sela);
374 coordxy b_pt = selection_getpoint(x, y, selb);
375 int val = (a_pt ^ b_pt) & a_pt;
376 selection_setpoint(x, y, selr, val);
377 }
378 /* this may have created a smaller or irregular selection with
379 * bounds_dirty set to true - update its boundaries */
380 selection_recalc_bounds(selr);
381
382 lua_remove(L, 1);
383 lua_remove(L, 1);
384 return 1;
385}
386
387/* local s = selection.percentage(sel, 50); */
388staticfn int

Callers

nothing calls this directly

Calls 6

l_selection_checkFunction · 0.85
l_selection_push_newFunction · 0.85
rect_boundsFunction · 0.85
selection_getpointFunction · 0.85
selection_setpointFunction · 0.85
selection_recalc_boundsFunction · 0.85

Tested by

no test coverage detected