Simplify .gitignore file
[linpy.git] / linpy / geometry.py
index 43344e4..0b05493 100644 (file)
@@ -85,14 +85,15 @@ class Coordinates:
         if isinstance(coordinates, Mapping):
             coordinates = coordinates.items()
         self = object().__new__(cls)
         if isinstance(coordinates, Mapping):
             coordinates = coordinates.items()
         self = object().__new__(cls)
-        self._coordinates = OrderedDict()
-        for symbol, coordinate in sorted(coordinates,
-                key=lambda item: item[0].sortkey()):
+        self._coordinates = []
+        for symbol, coordinate in coordinates:
             if not isinstance(symbol, Symbol):
                 raise TypeError('symbols must be Symbol instances')
             if not isinstance(coordinate, numbers.Real):
                 raise TypeError('coordinates must be real numbers')
             if not isinstance(symbol, Symbol):
                 raise TypeError('symbols must be Symbol instances')
             if not isinstance(coordinate, numbers.Real):
                 raise TypeError('coordinates must be real numbers')
-            self._coordinates[symbol] = coordinate
+            self._coordinates.append((symbol, coordinate))
+        self._coordinates.sort(key=lambda item: item[0].sortkey())
+        self._coordinates = OrderedDict(self._coordinates)
         return self
 
     @property
         return self
 
     @property
@@ -141,6 +142,14 @@ class Coordinates:
         """
         return any(self._coordinates.values())
 
         """
         return any(self._coordinates.values())
 
+    def __eq__(self, other):
+        """
+        Return True if two coordinate systems are equal.
+        """
+        if isinstance(other, self.__class__):
+            return self._coordinates == other._coordinates
+        return NotImplemented
+
     def __hash__(self):
         return hash(tuple(self.coordinates()))
 
     def __hash__(self):
         return hash(tuple(self.coordinates()))
 
@@ -205,14 +214,6 @@ class Point(Coordinates, GeometricObject):
             return Point(coordinates)
         return NotImplemented
 
             return Point(coordinates)
         return NotImplemented
 
-    def __eq__(self, other):
-        """
-        Test whether two points are equal.
-        """
-        if isinstance(other, Point):
-            return self._coordinates == other._coordinates
-        return NotImplemented
-
     def aspolyhedron(self):
         from .polyhedra import Polyhedron
         equalities = []
     def aspolyhedron(self):
         from .polyhedra import Polyhedron
         equalities = []
@@ -300,14 +301,6 @@ class Vector(Coordinates):
             return Vector(coordinates)
         return NotImplemented
 
             return Vector(coordinates)
         return NotImplemented
 
-    def __eq__(self, other):
-        """
-        Test whether two vectors are equal.
-        """
-        if isinstance(other, Vector):
-            return self._coordinates == other._coordinates
-        return NotImplemented
-
     def angle(self, other):
         """
         Retrieve the angle required to rotate the vector into the vector passed
     def angle(self, other):
         """
         Retrieve the angle required to rotate the vector into the vector passed