diff trafficintelligence/moving.py @ 1076:108c5dc4e34a

Correcting loaders
author Wendlasida
date Fri, 20 Jul 2018 13:50:43 -0400
parents 67144f26609e
children 3939ae415be0
line wrap: on
line diff
--- a/trafficintelligence/moving.py	Wed Jul 11 15:01:37 2018 -0400
+++ b/trafficintelligence/moving.py	Fri Jul 20 13:50:43 2018 -0400
@@ -71,7 +71,7 @@
     @classmethod
     def union(cls, interval1, interval2):
         '''Smallest interval comprising self and interval2'''
-        return cls(min(interval1.first, interval2.first), max(interval2.last, interval2.last))
+        return cls(min(interval1.first, interval2.first), max(interval1.last, interval2.last))
         
     @classmethod
     def intersection(cls, interval1, interval2):
@@ -1215,7 +1215,7 @@
         commonTimeInterval = obj1.commonTimeInterval(obj2)
         if commonTimeInterval.empty():
             #print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval()))
-            emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant()))
+            emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant())+1)
             if obj1.existsAtInstant(emptyInterval.last):
                 firstObject = obj2
                 secondObject = obj1
@@ -1228,7 +1228,7 @@
             featurePositions = Trajectory()
             featureVelocities = Trajectory()
             p = firstObject.getPositionAtInstant(emptyInterval.first)+v
-            for t in range(emptyInterval.first+1, emptyInterval.last):
+            for t in range(emptyInterval.first+1, emptyInterval.last+1):
             	positions.addPosition(p)
             	velocities.addPosition(v)
             	featurePositions.addPosition(p)
@@ -1245,6 +1245,7 @@
                     print('Issue, new created feature has no num id')
             if obj1.hasFeatures() and obj2.hasFeatures():
                 newObject.features = obj1.getFeatures()+obj2.getFeatures()+[MovingObject(newFeatureNum, TimeInterval(emptyInterval.first+1, emptyInterval.last-1), featurePositions, featureVelocities)]
+                newObject.updatePositions()
         else: # time intervals overlap
             newTimeInterval = TimeInterval.union(obj1.getTimeInterval(), obj2.getTimeInterval())
             newObject = MovingObject(newNum, newTimeInterval, nObjects = 1) # hypothesis is that it's the same object being reunited