Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and whisk committed Nov 5, 2023
1 parent 8e83459 commit 57c41a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pygeoif/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def force_2d(

geometry["coordinates"] = move_coordinates( # type: ignore [typeddict-unknown-key]
geometry["coordinates"], # type: ignore [typeddict-item]
(0, 0),
(0, 0),
)
return shape(geometry)

Expand Down
26 changes: 17 additions & 9 deletions tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ def test_force_2d_multilinestring() -> None:
# 3d multi line string to 2d multi line string
mls = geometry.MultiLineString([[(1, 2, 3), (4, 5, 6)], [(7, 8, 9), (10, 11, 12)]])
mls2d = factories.force_2d(mls)
assert list(mls2d.geoms) == [geometry.LineString([(1, 2), (4, 5)]), geometry.LineString([(7, 8), (10, 11)])]
assert list(mls2d.geoms) == [
geometry.LineString([(1, 2), (4, 5)]),
geometry.LineString([(7, 8), (10, 11)]),
]


def test_force_2d_polygon() -> None:
# 2d to 2d (no actual change)
external = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]
internal = [(0.5, 0.5), (0.5, 1.5), (1.5, 1.5), (1.5, 0.5), (0.5, 0.5)]
p = geometry.Polygon(external, [internal])
p2d = factories.force_2d(p)
assert p2d.coords[0] == (
((0, 0), (0, 2), (2, 2), (2, 0), (0, 0))
)
assert p2d.coords[0] == (((0, 0), (0, 2), (2, 2), (2, 0), (0, 0)))
assert p2d.coords[1] == (
((0.5, 0.5), (0.5, 1.5), (1.5, 1.5), (1.5, 0.5), (0.5, 0.5)),
)
Expand All @@ -96,13 +98,17 @@ def test_force_2d_polygon() -> None:

# 3d to 2d
external = [(0, 0, 1), (0, 2, 1), (2, 2, 1), (2, 0, 1), (0, 0, 1)]
internal = [(0.5, 0.5, 1), (0.5, 1.5, 1), (1.5, 1.5, 1), (1.5, 0.5, 1), (0.5, 0.5, 1)]
internal = [
(0.5, 0.5, 1),
(0.5, 1.5, 1),
(1.5, 1.5, 1),
(1.5, 0.5, 1),
(0.5, 0.5, 1),
]

p = geometry.Polygon(external, [internal])
p2d = factories.force_2d(p)
assert p2d.coords[0] == (
((0, 0), (0, 2), (2, 2), (2, 0), (0, 0))
)
assert p2d.coords[0] == (((0, 0), (0, 2), (2, 2), (2, 0), (0, 0)))
assert p2d.coords[1] == (
((0.5, 0.5), (0.5, 1.5), (1.5, 1.5), (1.5, 0.5), (0.5, 0.5)),
)
Expand All @@ -126,7 +132,9 @@ def test_force2d_collection() -> None:
assert list(gc2d.geoms) == list(gc.geoms)

# 3d to 2d
gc = geometry.GeometryCollection([geometry.Point(-1, 1, 0), geometry.Point(-2, 2, 0)])
gc = geometry.GeometryCollection(
[geometry.Point(-1, 1, 0), geometry.Point(-2, 2, 0)],
)
gc2d = factories.force_2d(gc)
assert list(gc2d.geoms) == [geometry.Point(-1, 1), geometry.Point(-2, 2)]

Expand Down

0 comments on commit 57c41a0

Please sign in to comment.