Skip to content

Commit

Permalink
Implement __eq__ for DimensionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed May 28, 2021
1 parent 1241abe commit 0864f2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions laspy/point/dims.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,24 @@ def type_str(self) -> Optional[str]:
f"{self.num_elements}{self.kind.letter()}{self.num_bytes_singular_element}"
)

def __eq__(self, other: "DimensionInfo") -> bool:
# Named Tuple implements that for us, but
# when scales and offset are not None (thus are array)
# The default '==' won't work
# (ValueError, value of an array with more than one element is ambiguous)
return (
self.name == other.name
and self.kind == other.kind
and self.num_bits == other.num_bits
and self.is_standard == other.is_standard
and self.description == other.description
and np.all(self.offsets == other.offsets)
and np.all(self.scales == other.scales)
)

def __ne__(self, other: "DimensionInfo") -> bool:
return not self == other


def size_of_point_format_id(point_format_id: int) -> int:
return ALL_POINT_FORMATS_DTYPE[point_format_id].itemsize
Expand Down
3 changes: 3 additions & 0 deletions laspy/point/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def __eq__(self, other):
return False

for my_eb, ot_eb in zip_longest(self.extra_dimensions, other.extra_dimensions):
if my_eb is None or ot_eb is None:
return False

if my_eb != ot_eb:
return False

Expand Down

0 comments on commit 0864f2c

Please sign in to comment.