diff python/moving.py @ 863:a8ca72dc1564

work on user detectors
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 08 Nov 2016 17:59:40 -0500
parents 07fb949ff98f
children eb2f8ce2b39d
line wrap: on
line diff
--- a/python/moving.py	Mon Nov 07 11:11:10 2016 -0500
+++ b/python/moving.py	Tue Nov 08 17:59:40 2016 -0500
@@ -946,6 +946,15 @@
                            self.positions[1][::step]])
 
     if shapelyAvailable:
+        def getInstantsInPolygon(self, polygon):
+            '''Returns the list of instants at which the trajectory is in the polygon'''
+            instants = []
+            n = self.length()
+            for t, x, y in zip(range(n), self.positions[0], self.positions[1]):
+                if polygon.contains(shapelyPoint(x, y)):
+                    instants.append(t)
+            return instants
+
         def getTrajectoryInPolygon(self, polygon, t2 = None):
             '''Returns the trajectory built with the set of points inside the (shapely) polygon
             The polygon could be a prepared polygon (faster) from prepared.prep
@@ -966,9 +975,9 @@
             return traj, traj2
 
         def proportionInPolygon(self, polygon, minProportion = 0.5):
-            inPolygon = [polygon.contains(shapelyPoint(x, y)) for x, y in zip(self.positions[0], self.positions[1])]
+            instants = self.getInstantsInPolygon(polygon)
             lengthThreshold = float(self.length())*minProportion
-            return sum(inPolygon) >= lengthThreshold
+            return len(instants) >= lengthThreshold
     else:
         def getTrajectoryInPolygon(self, polygon, t2 = None):
             '''Returns the trajectory built with the set of points inside the polygon