projects
/
linpy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make coordinates mandatory in Point constructor
[linpy.git]
/
pypol
/
coordinates.py
diff --git
a/pypol/coordinates.py
b/pypol/coordinates.py
index
44b9e9d
..
f76b30a
100644
(file)
--- a/
pypol/coordinates.py
+++ b/
pypol/coordinates.py
@@
-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
@@
-74,8
+74,8
@@
class Point(Coordinates):
This class represents points in space.
"""
This class represents points in space.
"""
- def __new__(cls, coordinates
=None
):
- if isinstance(coordinates,
dict
):
+ def __new__(cls, coordinates):
+ if isinstance(coordinates,
Mapping
):
coordinates = coordinates.items()
self = object().__new__(cls)
self._coordinates = OrderedDict()
coordinates = coordinates.items()
self = object().__new__(cls)
self._coordinates = OrderedDict()
@@
-112,6
+112,13
@@
class Point(Coordinates):
return isinstance(other, Point) and \
self._coordinates == other._coordinates
return isinstance(other, Point) and \
self._coordinates == other._coordinates
+ def aspolyhedron(self):
+ from .polyhedra import Polyhedron
+ equalities = []
+ for symbol, coordinate in self.coordinates():
+ equalities.append(symbol - coordinate)
+ return Polyhedron(equalities)
+
class Vector(Coordinates):
"""
class Vector(Coordinates):
"""
@@
-227,8
+234,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)