Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.random.cells: treat distance as minimum distance #1797

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions raster/r.random.cells/indep.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void Indep(void)
Out[DRow][DCol] = ++Found;
for (R = DRow; R < Rs; R++) {
RowDist = NS * (R - DRow);
if (RowDist > MaxDistSq) {
if (RowDist >= MaxDistSq) {
R = Rs;
}
else {
Expand All @@ -45,7 +45,7 @@ void Indep(void)
G_debug(3, "(ColDist):%.12lf", ColDist);
G_debug(3, "(MaxDistSq):%.12lf", MaxDistSq);

if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
if (MaxDistSq > RowDistSq + ColDist * ColDist) {
if (0 != FlagGet(Cells, R, C)) {
G_debug(2, "unset()");
FLAG_UNSET(Cells, R, C);
Expand All @@ -62,14 +62,14 @@ void Indep(void)
G_debug(2, "it1()");
for (R = DRow - 1; R >= 0; R--) {
RowDist = NS * (DRow - R);
if (RowDist > MaxDistSq) {
if (RowDist >= MaxDistSq) {
R = 0;
}
else {
RowDistSq = RowDist * RowDist;
for (C = DCol; C < Cs; C++) {
ColDist = EW * (C - DCol);
if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
if (MaxDistSq > RowDistSq + ColDist * ColDist) {
if (0 != FlagGet(Cells, R, C)) {
G_debug(2, "unset()");
FLAG_UNSET(Cells, R, C);
Expand All @@ -86,14 +86,14 @@ void Indep(void)
G_debug(2, "it2()");
for (R = DRow; R < Rs; R++) {
RowDist = NS * (R - DRow);
if (RowDist > MaxDistSq) {
if (RowDist >= MaxDistSq) {
R = Rs;
}
else {
RowDistSq = RowDist * RowDist;
for (C = DCol - 1; C >= 0; C--) {
ColDist = EW * (DCol - C);
if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
if (MaxDistSq > RowDistSq + ColDist * ColDist) {
if (0 != FlagGet(Cells, R, C)) {
G_debug(2, "unset()");
FLAG_UNSET(Cells, R, C);
Expand All @@ -110,14 +110,14 @@ void Indep(void)
G_debug(2, "it3()");
for (R = DRow - 1; R >= 0; R--) {
RowDist = NS * (DRow - R);
if (RowDist > MaxDistSq) {
if (RowDist >= MaxDistSq) {
R = 0;
}
else {
RowDistSq = RowDist * RowDist;
for (C = DCol - 1; C >= 0; C--) {
ColDist = EW * (DCol - C);
if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
if (MaxDistSq > RowDistSq + ColDist * ColDist) {
if (0 != FlagGet(Cells, R, C)) {
G_debug(2, "unset()");
FLAG_UNSET(Cells, R, C);
Expand Down
4 changes: 2 additions & 2 deletions raster/r.random.cells/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ void Init()
G_debug(1, "(CellCount):%d", CellCount);

sscanf(Distance->answer, "%lf", &MaxDist);
if (MaxDist < 0.0)
G_fatal_error(_("Distance must be >= 0.0"));
if (!(MaxDist > 0.0))
neteler marked this conversation as resolved.
Show resolved Hide resolved
neteler marked this conversation as resolved.
Show resolved Hide resolved
G_fatal_error(_("Distance must be > 0.0"));

G_debug(3, "(MaxDist):%.12lf", MaxDist);
MaxDistSq = MaxDist * MaxDist;
Expand Down
4 changes: 3 additions & 1 deletion raster/r.random.cells/testsuite/test_random_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def test_fill_all(self):
)

def test_fill_some(self):
self.assertModule("r.random.cells", output=self.some_rast, distance=2, seed=100)
self.assertModule(
"r.random.cells", output=self.some_rast, distance=2.00001, seed=100
)
self.to_remove.append(self.some_rast)
self.assertRasterFitsUnivar(
self.some_rast, reference=dict(cells=self.n_cells, min=1)
Expand Down