Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion raster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ build_program_in_subdir(

build_program_in_subdir(r.latlong DEPENDS grass_gis grass_raster grass_gproj)

build_program_in_subdir(r.lake DEPENDS grass_gis grass_raster)
build_program_in_subdir(r.lake DEPENDS grass_gis grass_raster ${LIBM})

build_program_in_subdir(
r.mask.status
Expand Down
2 changes: 1 addition & 1 deletion raster/r.lake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MODULE_TOPDIR = ../..

PGM = r.lake

LIBES = $(RASTERLIB) $(GISLIB)
LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
DEPENDENCIES = $(RASTERDEP) $(GISDEP)

include $(MODULE_TOPDIR)/include/Make/Module.make
Expand Down
5 changes: 3 additions & 2 deletions raster/r.lake/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Kaarliit, shii programma ir veltiita Tev.
*
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

Expand Down Expand Up @@ -232,8 +233,8 @@ int main(int argc, char *argv[])

G_scan_easting(sdxy_opt->answers[0], &east, G_projection());
G_scan_northing(sdxy_opt->answers[1], &north, G_projection());
start_col = (int)Rast_easting_to_col(east, &window);
start_row = (int)Rast_northing_to_row(north, &window);
start_col = (int)floor(Rast_easting_to_col(east, &window));
start_row = (int)floor(Rast_northing_to_row(north, &window));

if (start_row < 0 || start_row >= rows || start_col < 0 ||
start_col >= cols)
Expand Down
43 changes: 43 additions & 0 deletions raster/r.lake/tests/r_lake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ def test_seed_coordinates_on_region_edge_are_rejected(
assert "Seed point outside the current region" in error.value.errors


@pytest.mark.parametrize(
"coordinates",
[(25.5, 50.5), (25.5, 50.9), (-0.5, 25.5), (-0.9, 25.5)],
ids=["north", "north-almost-one-cell", "west", "west-almost-one-cell"],
)
def test_seed_coordinates_less_than_a_cell_outside_are_rejected(
session_with_flat_terrain, coordinates
):
"""Coordinates north or west of the region are outside it.

Truncating the converted index towards zero turns the whole interval
between -1 and 0 into row or column 0, which hides these coordinates from
the check below zero.
"""
tools = Tools(session=session_with_flat_terrain)

with pytest.raises(ToolError) as error:
tools.r_lake(
elevation="terrain",
water_level=10,
lake="lake_out",
coordinates=coordinates,
)

assert error.value.returncode == 1
assert "Seed point outside the current region" in error.value.errors


def test_seed_coordinates_in_last_row_are_accepted(session_with_flat_terrain):
"""Coordinates in the last row are inside the region and fill it."""
tools = Tools(session=session_with_flat_terrain)
Expand All @@ -120,3 +148,18 @@ def test_seed_coordinates_in_last_row_are_accepted(session_with_flat_terrain):

stats = tools.r_univar(map="lake_out", format="json").json
assert stats["n"] == 2500


@pytest.mark.parametrize("coordinates", [(25.5, 50), (0, 25.5)], ids=["north", "west"])
def test_seed_coordinates_on_north_and_west_edge_are_accepted(
session_with_flat_terrain, coordinates
):
"""The northern and western edges belong to the first row and column."""
tools = Tools(session=session_with_flat_terrain)

tools.r_lake(
elevation="terrain", water_level=10, lake="lake_out", coordinates=coordinates
)

stats = tools.r_univar(map="lake_out", format="json").json
assert stats["n"] == 2500
Loading