>>> from prediction import *
>>> import moving, storage, utils
>>> from numpy import absolute, array

>>> et = PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0))
>>> et.predictPosition(4) # doctest:+ELLIPSIS
(4.0...,0.0...)
>>> et.predictPosition(1) # doctest:+ELLIPSIS
(1.0...,0.0...)

>>> et = PredictedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0), moving.NormAngle(0.1,0), maxSpeed = 2)
>>> et.predictPosition(10) # doctest:+ELLIPSIS
(15.5...,0.0...)
>>> et.predictPosition(11) # doctest:+ELLIPSIS
(17.5...,0.0...)
>>> et.predictPosition(12) # doctest:+ELLIPSIS
(19.5...,0.0...)

>>> import random
>>> acceleration = lambda: random.uniform(-0.5,0.5)
>>> steering = lambda: random.uniform(-0.1,0.1)
>>> et = PredictedTrajectoryRandomControl(moving.Point(0,0),moving.Point(1,1), acceleration, steering, maxSpeed = 2)
>>> p = et.predictPosition(500)
>>> from numpy import max
>>> max(et.getPredictedSpeeds()) <= 2.
True

>>> p = moving.Point(3,4)
>>> sp = SafetyPoint(p, 0.1, 0)
>>> print(sp)
3 4 0.1 0

>>> et1 = PredictedTrajectoryConstant(moving.Point(-5.,0.), moving.Point(1.,0.))
>>> et2 = PredictedTrajectoryConstant(moving.Point(0.,-5.), moving.Point(0.,1.))
>>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 10)
>>> collision
True
>>> t
5
>>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 5)
>>> collision
True
>>> t
5
>>> collision, t, cp1, cp2 = computeCollisionTime(et1, et2, 0.1, 4)
>>> collision
False

>>> proto = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'feature', [1204])[0]
>>> proto.getPositions().computeCumulativeDistances()
>>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.5, 0.5), proto.getVelocityAt(10)*0.9, proto, True)
>>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.9) < 1e-5
True
>>> for t in xrange(int(proto.length())): x=et.predictPosition(t)
>>> traj = et.getPredictedTrajectory()
>>> traj.computeCumulativeDistances()
>>> absolute(array(traj.distances).mean() - et.initialSpeed < 1e-3)
True

>>> et = PredictedTrajectoryPrototype(proto.getPositionAt(10)+moving.Point(0.6, 0.6), proto.getVelocityAt(10)*0.7, proto, False)
>>> absolute(et.initialSpeed - proto.getVelocityAt(10).norm2()*0.7) < 1e-5
True
>>> proto = moving.MovingObject.generate(1, moving.Point(-5.,0.), moving.Point(1.,0.), moving.TimeInterval(0,10))
>>> et = PredictedTrajectoryPrototype(proto.getPositionAt(0)+moving.Point(0., 1.), proto.getVelocityAt(0)*0.5, proto, False)
>>> for t in xrange(int(proto.length()/0.5)): x=et.predictPosition(t)
>>> et.predictPosition(10) # doctest:+ELLIPSIS
(0.0...,1.0...)
>>> et.predictPosition(12) # doctest:+ELLIPSIS
(1.0...,1.0...)


