Skip to content

Commit

Permalink
[Python] format
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Oct 9, 2019
1 parent 0a78aff commit cba6436
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
2 changes: 1 addition & 1 deletion python/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .libparametric_curves_pywrap import *
from .libparametric_curves_pywrap import * # noqa
100 changes: 48 additions & 52 deletions python/test/test.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,76 @@
from spline import bezier, bezier6, polynom, exact_cubic, curve_constraints, spline_deriv_constraint

from numpy import matrix
from numpy.linalg import norm

waypoints = matrix([[1.,2.,3.],[4.,5.,6.]]).transpose()
waypoints6 = matrix([[1.,2.,3.,7.,5.,5.],[4.,5.,6.,4.,5.,6.]]).transpose()
time_waypoints = matrix([0.,1.])
from spline import (bezier, bezier6, curve_constraints, exact_cubic, polynom, spline_deriv_constraint)

waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
waypoints6 = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).transpose()
time_waypoints = matrix([0., 1.])

#testing bezier curve
# testing bezier curve
a = bezier6(waypoints6)
a = bezier(waypoints, -1., 3.)

assert(a.degree == a.nbWaypoints -1)
assert (a.degree == a.nbWaypoints - 1)
a.min()
a.max()
a(0.4)
assert((a.derivate(0.4,0) == a(0.4)).all())
a.derivate(0.4,2)
assert ((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)
a = a.compute_derivate(100)

prim = a.compute_primitive(1)

for i in range(10):
t = float(i) / 10.
assert(a(t) == prim.derivate(t,1)).all()
assert(prim(0) == matrix([0.,0.,0.])).all()
t = float(i) / 10.
assert (a(t) == prim.derivate(t, 1)).all()
assert (prim(0) == matrix([0., 0., 0.])).all()

prim = a.compute_primitive(2)
for i in range(10):
t = float(i) / 10.
assert(a(t) == prim.derivate(t,2)).all()
assert(prim(0) == matrix([0.,0.,0.])).all()


#testing bezier with constraints
c = curve_constraints();
c.init_vel = matrix([0.,1.,1.]);
c.end_vel = matrix([0.,1.,1.]);
c.init_acc = matrix([0.,1.,-1.]);
c.end_acc = matrix([0.,100.,1.]);


a = bezier(waypoints,c)
assert norm(a.derivate(0,1) - c.init_vel) < 1e-10
assert norm(a.derivate(1,2) - c.end_acc) < 1e-10


#testing polynom function
t = float(i) / 10.
assert (a(t) == prim.derivate(t, 2)).all()
assert (prim(0) == matrix([0., 0., 0.])).all()

# testing bezier with constraints
c = curve_constraints()
c.init_vel = matrix([0., 1., 1.])
c.end_vel = matrix([0., 1., 1.])
c.init_acc = matrix([0., 1., -1.])
c.end_acc = matrix([0., 100., 1.])

a = bezier(waypoints, c)
assert norm(a.derivate(0, 1) - c.init_vel) < 1e-10
assert norm(a.derivate(1, 2) - c.end_acc) < 1e-10

# testing polynom function
a = polynom(waypoints)
a = polynom(waypoints, -1., 3.)
a.min()
a.max()
a(0.4)
assert((a.derivate(0.4,0) == a(0.4)).all())
a.derivate(0.4,2)
assert ((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)

#testing exact_cubic function
# testing exact_cubic function
a = exact_cubic(waypoints, time_waypoints)
a.min()
a.max()
a(0.4)
assert((a.derivate(0.4,0) == a(0.4)).all())
a.derivate(0.4,2)

#testing spline_deriv_constraints
c = curve_constraints();
c.init_vel;
c.end_vel;
c.init_acc;
c.end_acc;


c.init_vel = matrix([0.,1.,1.]);
c.end_vel = matrix([0.,1.,1.]);
c.init_acc = matrix([0.,1.,1.]);
c.end_acc = matrix([0.,1.,1.]);

a = spline_deriv_constraint (waypoints, time_waypoints)
a = spline_deriv_constraint (waypoints, time_waypoints, c)
assert ((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)

# testing spline_deriv_constraints
c = curve_constraints()
c.init_vel
c.end_vel
c.init_acc
c.end_acc

c.init_vel = matrix([0., 1., 1.])
c.end_vel = matrix([0., 1., 1.])
c.init_acc = matrix([0., 1., 1.])
c.end_acc = matrix([0., 1., 1.])

a = spline_deriv_constraint(waypoints, time_waypoints)
a = spline_deriv_constraint(waypoints, time_waypoints, c)

0 comments on commit cba6436

Please sign in to comment.