Skip to content

Commit

Permalink
Make Geometry3D comparable
Browse files Browse the repository at this point in the history
  • Loading branch information
vanous committed Dec 22, 2023
1 parent f481306 commit b65359e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pymvr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,17 @@ def _read_xml(self, xml_node: "Element"):
self.uuid = xml_node.attrib.get("uuid")

self.symbol = [Symbol(xml_node=i) for i in xml_node.findall("Symbol")]
self.geometry3d = [Geometry3D(xml_node=i) for i in xml_node.findall("Geometry3D")]
_geometry3d = [Geometry3D(xml_node=i) for i in xml_node.findall("Geometry3D")]
if xml_node.find("ChildList"):
child_list = xml_node.find("ChildList")

symbols = [Symbol(xml_node=i) for i in child_list.findall("Symbol")]
geometry3ds = [Geometry3D(xml_node=i) for i in child_list.findall("Geometry3D")]
self.symbol += symbols # TODO remove this over time, children should only be in the child_list
self.geometry3d += geometry3ds
self.symbol += symbols
_geometry3d += geometry3ds

# sometimes the list of geometry3d is full of duplicates, eliminate them here
self.geometry3d = list(set(_geometry3d))

class Geometry3D(BaseNode):
def __init__(
Expand All @@ -588,7 +590,19 @@ def _read_xml(self, xml_node: "Element"):
self.matrix = Matrix(str_repr=xml_node.find("Matrix").text)

def __str__(self):
return f"{self.file_name}"
return f"{self.file_name} {self.matrix}"

def __repr__(self):
return f"{self.file_name} {self.matrix}"

def __eq__(self, other):
return self.file_name == other.file_name and self.matrix == other.matrix

def __ne__(self, other):
return self.file_name != other.file_name or self.matrix != other.matrix

def __hash__(self):
return hash((self.file_name, str(self.matrix)))


class Symbol(BaseNode):
Expand Down
10 changes: 10 additions & 0 deletions pymvr/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ def __init__(self, str_repr):
[component[6], component[7], component[8], 0],
[component[9] * 0.001, component[10] * 0.001, component[11] * 0.001, 0],
]
def __eq__(self, other):
return self.matrix == other.matrix

def __ne__(self, other):
return self.matrix == other.matrix

def __str__(self):
return f"{self.matrix}"

def __repr__(self):
return f"{self.matrix}"

# A node link represents a link to another node in the XML tree, starting from
# start_point and traversing the tree with a decimal-point notation in str_link.
Expand Down

0 comments on commit b65359e

Please sign in to comment.