changeset 91:daa05fae1a70

modified the type of the result of interval lengths to float, added comments
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 09 Jun 2011 16:03:17 -0400
parents f84293ad4611
children a5ef9e40688e
files python/moving.py python/tests/moving.txt
diffstat 2 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Thu Jun 09 11:27:31 2011 -0400
+++ b/python/moving.py	Thu Jun 09 16:03:17 2011 -0400
@@ -30,7 +30,7 @@
 
     def length(self):
         '''Returns the length of the interval'''
-        return max(0,self.last-self.first)
+        return float(max(0,self.last-self.first))
 
     def getList(self):
         return [self.first, self.last]
@@ -52,7 +52,7 @@
 
 
 class TimeInterval(Interval):
-    '''Temporal interval
+    '''Temporal interval based on frame numbers (hence the modified length method)
     may be modified directly by setting first and last'''
 
     def __init__(self, first=0, last=-1):
@@ -75,7 +75,7 @@
 
     def length(self):
         '''Returns the length of the interval'''
-        return max(0,self.last-self.first+1)
+        return float(max(0,self.last-self.first+1))
 
 # class BoundingPolygon:
 #     '''Class for a polygon bounding a set of points
@@ -272,6 +272,7 @@
         return [hypot(x,y) for x,y in zip(self.positions[0], self.positions[1])]
 
     def cumulatedDisplacement(self):
+        'Returns the sum of the distances between each successive point'
         displacement = 0
         for i in xrange(self.length()-1):
             displacement += Point.distanceNorm2(self.__getitem__(i),self.__getitem__(i+1))
@@ -282,7 +283,8 @@
 
     def getIntersections(self, p1, p2):
         '''Returns a list of the indices at which the trajectory 
-        intersects with the segment of extremities p1 and p2 the list is empty if there is no crossing'''
+        intersects with the segment of extremities p1 and p2 
+        the list is empty if there is no crossing'''
         indices = []
 
         for i in xrange(self.length()-1):
--- a/python/tests/moving.txt	Thu Jun 09 11:27:31 2011 -0400
+++ b/python/tests/moving.txt	Thu Jun 09 16:03:17 2011 -0400
@@ -5,16 +5,16 @@
 >>> Interval(0,1).empty()
 False
 >>> Interval(0,1).length()
-1
+1.0
 >>> Interval(23.2,24.9).length()
 1.6999999999999993
 >>> Interval(10,8).length()
-0
+0.0
 
 >>> TimeInterval(0,1).length()
-2
+2.0
 >>> TimeInterval(10,8).length()
-0
+0.0
 
 >>> Point(3,4)-Point(1,7)
 (2.000000,-3.000000)
@@ -31,8 +31,8 @@
 True
 
 >>> t1 = Trajectory([[0.5,1.5,2.5],[0.5,3.5,6.5]])
->>> t1.length()
-3
+>>> t1.length() == 3.
+True
 >>> t1[1]
 (1.500000,3.500000)
 >>> t1.getTrajectoryInPolygon1([Point(0,0),Point(4,0),Point(4,3),Point(0,3)])