X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/0995f79a8db531aa3a2ca951af65f3f0fa4943e5..8332ae24f41a1f2bbba78597cc9e412ef9935ae8:/pypol/domains.py?ds=sidebyside diff --git a/pypol/domains.py b/pypol/domains.py index 3ab7d44..d80fd91 100644 --- a/pypol/domains.py +++ b/pypol/domains.py @@ -5,8 +5,8 @@ import re from fractions import Fraction from . import islhelper -from .islhelper import mainctx, libisl, isl_set_basic_sets -from .coordinates import Point +from .islhelper import mainctx, libisl +from .geometry import GeometricObject, Point from .linexprs import Expression, Symbol @@ -17,7 +17,7 @@ __all__ = [ @functools.total_ordering -class Domain: +class Domain(GeometricObject): __slots__ = ( '_polyhedra', @@ -28,14 +28,14 @@ class Domain: def __new__(cls, *polyhedra): from .polyhedra import Polyhedron if len(polyhedra) == 1: - polyhedron = polyhedra[0] - if isinstance(polyhedron, str): - return cls.fromstring(polyhedron) - elif isinstance(polyhedron, Polyhedron): - return polyhedron + argument = polyhedra[0] + if isinstance(argument, str): + return cls.fromstring(argument) + elif isinstance(argument, GeometricObject): + return argument.aspolyhedron() else: raise TypeError('argument must be a string ' - 'or a Polyhedron instance') + 'or a GeometricObject instance') else: for polyhedron in polyhedra: if not isinstance(polyhedron, Polyhedron): @@ -154,6 +154,9 @@ class Domain: islbset = libisl.isl_set_polyhedral_hull(islset) return Polyhedron._fromislbasicset(islbset, self.symbols) + def asdomain(self): + return self + def project(self, dims): # use to remove certain variables islset = self._toislset(self.polyhedra, self.symbols) @@ -312,6 +315,12 @@ class Domain: points.append(Point(coordinates)) return points + def __contains__(self, point): + for polyhedron in self.polyhedra: + if point in polyhedron: + return True + return False + def subs(self, symbol, expression=None): polyhedra = [polyhedron.subs(symbol, expression) for polyhedron in self.polyhedra] @@ -321,7 +330,7 @@ class Domain: def _fromislset(cls, islset, symbols): from .polyhedra import Polyhedron islset = libisl.isl_set_remove_divs(islset) - islbsets = isl_set_basic_sets(islset) + islbsets = islhelper.isl_set_basic_sets(islset) libisl.isl_set_free(islset) polyhedra = [] for islbset in islbsets: