X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/2a1055d4f4754fa33c53d3f155cc050e4911a2a3..dc449ca80b432de202188a4300ef990abeb968a1:/pypol/geometry.py diff --git a/pypol/geometry.py b/pypol/geometry.py index 1dc50eb..520a1ec 100644 --- a/pypol/geometry.py +++ b/pypol/geometry.py @@ -107,18 +107,27 @@ class Point(Coordinates, GeometricObject): """ def isorigin(self): + """ + Return True if a Point is the origin. + """ return not bool(self) def __hash__(self): return super().__hash__() def __add__(self, other): + """ + Adds a Point to a Vector and returns the result as a Point. + """ if not isinstance(other, Vector): return NotImplemented coordinates = self._map2(other, operator.add) return Point(coordinates) def __sub__(self, other): + """ + Returns the difference between two Points as a Vector. + """ coordinates = [] if isinstance(other, Point): coordinates = self._map2(other, operator.sub) @@ -130,10 +139,16 @@ class Point(Coordinates, GeometricObject): return NotImplemented def __eq__(self, other): + """ + Compares two Points for equality. + """ return isinstance(other, Point) and \ self._coordinates == other._coordinates def aspolyhedron(self): + """ + Return a Point as a polyhedron. + """ from .polyhedra import Polyhedron equalities = [] for symbol, coordinate in self.coordinates(): @@ -158,12 +173,18 @@ class Vector(Coordinates): return super().__new__(cls, coordinates) def isnull(self): + """ + Returns true if a Vector is null. + """ return not bool(self) def __hash__(self): return super().__hash__() def __add__(self, other): + """ + Adds either a Point or Vector to a Vector. + """ if isinstance(other, (Point, Vector)): coordinates = self._map2(other, operator.add) return other.__class__(coordinates) @@ -171,9 +192,7 @@ class Vector(Coordinates): def angle(self, other): """ - Retrieve the angle required to rotate the vector into the vector passed - in argument. The result is an angle in radians, ranging between -pi and - pi. + Retrieve the angle required to rotate the vector into the vector passed in argument. The result is an angle in radians, ranging between -pi and pi. """ if not isinstance(other, Vector): raise TypeError('argument must be a Vector instance') @@ -219,6 +238,9 @@ class Vector(Coordinates): return result def __eq__(self, other): + """ + Compares two Vectors for equality. + """ return isinstance(other, Vector) and \ self._coordinates == other._coordinates @@ -226,6 +248,9 @@ class Vector(Coordinates): return hash(tuple(self.coordinates())) def __mul__(self, other): + """ + Multiplies a Vector by a scalar value. + """ if not isinstance(other, numbers.Real): return NotImplemented coordinates = self._map(lambda coordinate: other * coordinate) @@ -234,10 +259,16 @@ class Vector(Coordinates): __rmul__ = __mul__ def __neg__(self): + """ + Returns the negated form of a Vector. + """ coordinates = self._map(operator.neg) return Vector(coordinates) def norm(self): + """ + Normalizes a Vector. + """ return math.sqrt(self.norm2()) def norm2(self): @@ -250,6 +281,9 @@ class Vector(Coordinates): return self / self.norm() def __sub__(self, other): + """ + Subtract a Point or Vector from a Vector. + """ if isinstance(other, (Point, Vector)): coordinates = self._map2(other, operator.sub) return other.__class__(coordinates)