Improve mapping recognition
[linpy.git] / pypol / coordinates.py
index 9e46673..78e8d4a 100644 (file)
@@ -3,7 +3,7 @@ import numbers
 import operator
 
 from abc import ABC, abstractmethod
 import operator
 
 from abc import ABC, abstractmethod
-from collections import OrderedDict
+from collections import OrderedDict, Mapping
 
 from .linexprs import Symbol
 
 
 from .linexprs import Symbol
 
@@ -75,7 +75,7 @@ class Point(Coordinates):
     """
 
     def __new__(cls, coordinates=None):
     """
 
     def __new__(cls, coordinates=None):
-        if isinstance(coordinates, dict):
+        if isinstance(coordinates, Mapping):
             coordinates = coordinates.items()
         self = object().__new__(cls)
         self._coordinates = OrderedDict()
             coordinates = coordinates.items()
         self = object().__new__(cls)
         self._coordinates = OrderedDict()
@@ -133,30 +133,9 @@ class Vector(Coordinates):
             self._coordinates = terminal._map2(initial, operator.sub)
         return self
 
             self._coordinates = terminal._map2(initial, operator.sub)
         return self
 
-    @property
-    def symbols(self):
-        return tuple(self._coordinates)
-
-    @property
-    def dimension(self):
-        return len(self.symbols)
-
-    def coordinates(self):
-        yield from self._coordinates.items()
-
-    def coordinate(self, symbol):
-        if not isinstance(symbol, Symbol):
-            raise TypeError('symbol must be a Symbol instance')
-        return self._coordinates[symbol]
-
-    __getitem__ = coordinate
-
     def isnull(self):
         return not bool(self)
 
     def isnull(self):
         return not bool(self)
 
-    def __bool__(self):
-        return any(self._coordinates.values())
-
     def __add__(self, other):
         if isinstance(other, (Point, Vector)):
             coordinates = self._map2(other, operator.add)
     def __add__(self, other):
         if isinstance(other, (Point, Vector)):
             coordinates = self._map2(other, operator.add)
@@ -248,8 +227,3 @@ class Vector(Coordinates):
             coordinates = self._map2(other, operator.sub)
             return other.__class__(coordinates)
         return NotImplemented
             coordinates = self._map2(other, operator.sub)
             return other.__class__(coordinates)
         return NotImplemented
-
-    def __repr__(self):
-        string = ', '.join(['{!r}: {!r}'.format(symbol, coordinate)
-            for symbol, coordinate in self.coordinates()])
-        return '{}({{{}}})'.format(self.__class__.__name__, string)