diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ee170ee1..76ef957565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog for releases ## v1.0.0 -- asdf +- `orientation_to_neighbor` 45, 135, 225, and 315 degrees are all considered `east_west`. Previously, 45 and 225 degrees were considered `north_south`. ## v0.0.0 - Initial release diff --git a/naturf/nodes.py b/naturf/nodes.py index 770359abdd..44e9aa6abe 100644 --- a/naturf/nodes.py +++ b/naturf/nodes.py @@ -301,9 +301,9 @@ def orientation_to_neighbor(angle_in_degrees_to_neighbor: pd.Series) -> pd.Serie (((Settings.SOUTHEAST_DEGREES <= angle_in_degrees_to_neighbor) & (angle_in_degrees_to_neighbor <= Settings.DEGREES_IN_CIRCLE)) | ((Settings.START_OF_CIRCLE_DEGREES <= angle_in_degrees_to_neighbor) & - (angle_in_degrees_to_neighbor < Settings.NORTHEAST_DEGREES))) + (angle_in_degrees_to_neighbor <= Settings.NORTHEAST_DEGREES))) | ((Settings.NORTHWEST_DEGREES <= angle_in_degrees_to_neighbor) & - (angle_in_degrees_to_neighbor < Settings.SOUTHWEST_DEGREES)), + (angle_in_degrees_to_neighbor <= Settings.SOUTHWEST_DEGREES)), "east_west", "north_south" ), diff --git a/naturf/tests/test_nodes.py b/naturf/tests/test_nodes.py index 9e49e5ea4c..3c8739d8f7 100644 --- a/naturf/tests/test_nodes.py +++ b/naturf/tests/test_nodes.py @@ -11,7 +11,7 @@ from naturf.driver import Model -from naturf.nodes import angle_in_degrees_to_neighbor +import naturf.nodes as nodes class TestNodes(unittest.TestCase): @@ -70,7 +70,7 @@ class TestCase: ] for case in testcases: - actual = angle_in_degrees_to_neighbor(gpd.GeoSeries(case.target_input), gpd.GeoSeries(case.neighbor_input)) + actual = nodes.angle_in_degrees_to_neighbor(gpd.GeoSeries(case.target_input), gpd.GeoSeries(case.neighbor_input)) expected = pd.Series(case.expected) pd.testing.assert_series_equal( expected, @@ -80,6 +80,32 @@ class TestCase: ), ) + def test_orientation_to_neighbor(self): + """Test that the function `orientation_to_neighbor` returns either `east_west` or `north_south` correctly.""" + @dataclass + class TestCase: + name: str + input: List[int] + expected: List[int] + + east_west = "east_west" + north_south = "north_south" + + testcases = [ + TestCase(name="zero_degrees", input=[0.0, -0.0], expected=[east_west, east_west]), + TestCase(name="north_south", input=[90, 270], expected=[north_south, north_south]), + TestCase(name="east_west", input=[45, 135, 225, 315, 360], expected=[east_west, east_west, east_west, east_west, east_west]), + ] + + for case in testcases: + actual = nodes.orientation_to_neighbor(pd.Series(case.input)) + expected = pd.Series(case.expected) + pd.testing.assert_series_equal( + expected, + actual, + f"failed test {case.name} expected {expected}, actual {actual}" + ) + if __name__ == '__main__': - unittest.main() + unittest.main() \ No newline at end of file