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

Minor Tweaks to PolygonalRegion #290

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion src/scenic/core/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3049,7 +3049,14 @@ def __eq__(self, other):

@cached
def __hash__(self):
return hash((self.polygons, self.orientation, self.z))
return hash(
(
tuple(self._points) if self._points else None,
Eric-Vin marked this conversation as resolved.
Show resolved Hide resolved
self._polygon,
self.orientation,
self.z,
)
)


class CircularRegion(PolygonalRegion):
Expand Down
9 changes: 9 additions & 0 deletions tests/core/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shapely.geometry
import trimesh.voxel

from scenic.core.distributions import RandomControlFlowError, Range
from scenic.core.object_types import Object, OrientedPoint
from scenic.core.regions import *
from scenic.core.vectors import VectorField
Expand Down Expand Up @@ -222,6 +223,14 @@ def test_polygon_region():
PolygonalRegion([(1, 1), (3, 1), (2, 2), (1.3, 1.15)], z=3).uniformPointInner().z
== 3
)
assert i != d
hash(i)
e = CircularRegion((0, 0), Range(1, 3))
with pytest.raises(RandomControlFlowError):
i == e
with pytest.raises(RandomControlFlowError):
e == i
hash(e)


def test_polygon_unionAll():
Expand Down
Loading