diff --git a/aerosandbox/atmosphere/thermodynamics/gas.py b/aerosandbox/atmosphere/thermodynamics/gas.py index 261890d3d..b565c6a94 100644 --- a/aerosandbox/atmosphere/thermodynamics/gas.py +++ b/aerosandbox/atmosphere/thermodynamics/gas.py @@ -55,11 +55,6 @@ def __repr__(self) -> str: return f"Gas (P = {f(self.pressure, 'Pa')}, T = {self.temperature:.6g} K, ρ = {self.density:.6g} kg/m^3, Pv^gamma = {self.pressure * self.specific_volume ** self.ratio_of_specific_heats: .6g})" - def __eq__(self, other): - if self.__class__ != other.__class__: - return False - return self.__dict__ == other.__dict__ - @property def density(self): return self.pressure / (self.temperature * self.specific_gas_constant) diff --git a/aerosandbox/common.py b/aerosandbox/common.py index 8e3cc203d..a57289a78 100644 --- a/aerosandbox/common.py +++ b/aerosandbox/common.py @@ -22,6 +22,31 @@ def __init__(self): """ pass + def __eq__(self, other): + """ + Checks if two AeroSandbox objects are value-equivalent. A more sensible default for classes that represent + physical objects than checking for memory equivalence. + + This is done by checking if the two objects are of the same type and have the same __dict__. + + Args: + other: Another object. + + Returns: + bool: True if the objects are equal, False otherwise. + """ + if type(self) != type(other): + return False + if set(self.__dict__.keys()) != set(other.__dict__.keys()): + return False + + for key in self.__dict__.keys(): + if np.all(self.__dict__[key] == other.__dict__[key]): + continue + else: + return False + return True + def save(self, filename: Union[str, Path] = None, verbose: bool = True, diff --git a/aerosandbox/geometry/polygon.py b/aerosandbox/geometry/polygon.py index 4f92b0609..b7dfa5442 100644 --- a/aerosandbox/geometry/polygon.py +++ b/aerosandbox/geometry/polygon.py @@ -19,12 +19,6 @@ def __init__(self, def __repr__(self): return f"Polygon ({self.n_points()} points)" - def __eq__(self, other): - return np.all(self.coordinates == other.coordinates) - - def __ne__(self, other): - return not self.__eq__(other) - def x(self) -> np.ndarray: """ Returns the x coordinates of the polygon. Equivalent to Polygon.coordinates[:,0]. diff --git a/aerosandbox/weights/mass_properties.py b/aerosandbox/weights/mass_properties.py index e991fb516..262e44599 100644 --- a/aerosandbox/weights/mass_properties.py +++ b/aerosandbox/weights/mass_properties.py @@ -294,32 +294,6 @@ def __truediv__(self, other: float) -> "MassProperties": """ return self.__mul__(1 / other) - def __eq__(self, other: "MassProperties") -> bool: - """ - Returns True if all expected attributes of the two MassProperties objects are exactly equal. - """ - if not isinstance(other, MassProperties): - raise TypeError("MassProperties objects can only be compared to other MassProperties objects.") - - return all([ - getattr(self, attribute) == getattr(other, attribute) - for attribute in [ - "mass", - "x_cg", - "y_cg", - "z_cg", - "Ixx", - "Iyy", - "Izz", - "Ixy", - "Iyz", - "Ixz", - ] - ]) - - def __ne__(self, other: "MassProperties") -> bool: - return not self.__eq__(other) - def allclose(self, other: "MassProperties", rtol=1e-5,