Make lua selection randline create a new selection
This commit is contained in:
+3
-1
@@ -486,6 +486,7 @@ lua_State *L;
|
|||||||
x2 = (schar) luaL_checkinteger(L, 4);
|
x2 = (schar) luaL_checkinteger(L, 4);
|
||||||
y2 = (schar) luaL_checkinteger(L, 5);
|
y2 = (schar) luaL_checkinteger(L, 5);
|
||||||
roughness = (int) luaL_checkinteger(L, 6);
|
roughness = (int) luaL_checkinteger(L, 6);
|
||||||
|
lua_pop(L, 5);
|
||||||
} else if (argc == 5 && lua_type(L, 1) == LUA_TNUMBER) {
|
} else if (argc == 5 && lua_type(L, 1) == LUA_TNUMBER) {
|
||||||
x1 = (schar) luaL_checkinteger(L, 1);
|
x1 = (schar) luaL_checkinteger(L, 1);
|
||||||
y1 = (schar) luaL_checkinteger(L, 2);
|
y1 = (schar) luaL_checkinteger(L, 2);
|
||||||
@@ -502,8 +503,9 @@ lua_State *L;
|
|||||||
get_location_coord(&x2, &y2, ANY_LOC,
|
get_location_coord(&x2, &y2, ANY_LOC,
|
||||||
g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x2, y2));
|
g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x2, y2));
|
||||||
|
|
||||||
|
(void) l_selection_clone(L);
|
||||||
|
sel = l_selection_check(L, 1);
|
||||||
selection_do_randline(x1, y1, x2, y2, roughness, 12, sel);
|
selection_do_randline(x1, y1, x2, y2, roughness, 12, sel);
|
||||||
lua_settop(L, 1);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-8
@@ -4474,14 +4474,8 @@ struct selectionvar *ov;
|
|||||||
int mx, my;
|
int mx, my;
|
||||||
int dx, dy;
|
int dx, dy;
|
||||||
|
|
||||||
if (rec < 1) {
|
if (rec < 1 || (x2 == x1 && y2 == y1))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if ((x2 == x1) && (y2 == y1)) {
|
|
||||||
selection_setpoint(x1, y1, ov, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rough > max(abs(x2 - x1), abs(y2 - y1)))
|
if (rough > max(abs(x2 - x1), abs(y2 - y1)))
|
||||||
rough = max(abs(x2 - x1), abs(y2 - y1));
|
rough = max(abs(x2 - x1), abs(y2 - y1));
|
||||||
@@ -4498,7 +4492,9 @@ struct selectionvar *ov;
|
|||||||
} while ((mx > COLNO - 1 || mx < 0 || my < 0 || my > ROWNO - 1));
|
} while ((mx > COLNO - 1 || mx < 0 || my < 0 || my > ROWNO - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
selection_setpoint(mx, my, ov, 1);
|
if (!selection_getpoint(mx, my, ov)) {
|
||||||
|
selection_setpoint(mx, my, ov, 1);
|
||||||
|
}
|
||||||
|
|
||||||
rough = (rough * 2) / 3;
|
rough = (rough * 2) / 3;
|
||||||
|
|
||||||
@@ -4506,6 +4502,8 @@ struct selectionvar *ov;
|
|||||||
|
|
||||||
selection_do_randline(x1, y1, mx, my, rough, rec, ov);
|
selection_do_randline(x1, y1, mx, my, rough, rec, ov);
|
||||||
selection_do_randline(mx, my, x2, y2, rough, rec, ov);
|
selection_do_randline(mx, my, x2, y2, rough, rec, ov);
|
||||||
|
|
||||||
|
selection_setpoint(x2, y2, ov, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -278,6 +278,20 @@ function test_sel_fillrect()
|
|||||||
end
|
end
|
||||||
end -- test_sel_fillrect
|
end -- test_sel_fillrect
|
||||||
|
|
||||||
|
function test_sel_randline()
|
||||||
|
local __func__ = "test_sel_randline";
|
||||||
|
local sela = selection.new();
|
||||||
|
local sela_clone = sela:clone();
|
||||||
|
|
||||||
|
-- roughness 0 is drawn line a straight line
|
||||||
|
local selb = sela:randline(1,1, 5,5, 0);
|
||||||
|
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
|
||||||
|
end -- test_sel_randline
|
||||||
|
|
||||||
test_selection_params();
|
test_selection_params();
|
||||||
test_sel_negate();
|
test_sel_negate();
|
||||||
test_sel_logical_and();
|
test_sel_logical_and();
|
||||||
@@ -287,3 +301,4 @@ test_sel_filter_percent();
|
|||||||
test_sel_line();
|
test_sel_line();
|
||||||
test_sel_rect();
|
test_sel_rect();
|
||||||
test_sel_fillrect();
|
test_sel_fillrect();
|
||||||
|
test_sel_randline();
|
||||||
|
|||||||
Reference in New Issue
Block a user