From: Vivien Maisonneuve Date: Fri, 11 Jul 2014 15:00:47 +0000 (+0200) Subject: Implement method Point.aspolyhedron() X-Git-Tag: 1.0~126 X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/commitdiff_plain/b595adab7a332fccf90714d194e70fdf73e458e3?ds=sidebyside;hp=663316ddc03c19cf06e95bad67fd5ac2bb5e1dfc Implement method Point.aspolyhedron() --- diff --git a/pypol/coordinates.py b/pypol/coordinates.py index 78e8d4a..7923648 100644 --- a/pypol/coordinates.py +++ b/pypol/coordinates.py @@ -112,6 +112,13 @@ class Point(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): """ diff --git a/pypol/tests/test_coordinates.py b/pypol/tests/test_coordinates.py index 2e14032..044d773 100644 --- a/pypol/tests/test_coordinates.py +++ b/pypol/tests/test_coordinates.py @@ -1,8 +1,9 @@ import math import unittest -from ..linexprs import Symbol from ..coordinates import * +from ..linexprs import Symbol +from ..polyhedra import Eq class TestPoint(unittest.TestCase): @@ -29,6 +30,9 @@ class TestPoint(unittest.TestCase): self.assertEqual(self.pt1 - self.pt2, Vector({self.x: -5, self.y: -35, self.z: -59})) self.assertEqual(self.pt1 - self.vec1, Point({self.x: -10, self.y: -25, self.z: -39})) + def test_aspolyhedron(self): + self.assertEqual(self.pt1.aspolyhedron(), Eq(self.x, 10) & Eq(self.y, 5) & Eq(self.z, 1)) + class TestVector(unittest.TestCase):