-
Notifications
You must be signed in to change notification settings - Fork 0
/
EBe7lOj8
52 lines (38 loc) · 1.18 KB
/
EBe7lOj8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from collections import deque, namedtuple
import datetime
from threading import Lock
class InitBlob:
def __init__(self):
self.prev = None
def location(self):
return None
@staticmethod
def timediff(m1, m2):
return abs(m1.time - m2.time)
@staticmethod
def dist2(p1, p2):
"distance squared"
return (p1.r-p2.r)**2 + (p1.c-p2.c)**2
class Blob(InitBlob):
def __init__(self, r, c, vr, vc, t, surface):
self.r=r
self.c=c
self.vr=vr
self.vc=vc
self.time=t
self.lock = Lock()
self.surface = surface
def fit(self, pos, time):
"how likely it is that the given pos is a location of the blob at a given time"
#1/distance squared
if self.prev == None:
return float('inf')
with self.lock:
return - BlobInfo.dist2(self.blob, pos) #IN PROGRESS
def location(self, time):
#thread safe
"get the approximate location at the specified time"
t = time - self.time
if t < 0:
return None
return (self.r+self.vr*t, self.c+self.vc*t)