Unverified Commit 875a0ab4 authored by Fernbach Pierre's avatar Fernbach Pierre Committed by GitHub
Browse files

Merge pull request #33 from pFernbach/devel

[Python] Fix issue #32
parents 5f14887a d740879b
Pipeline #8319 passed with stage
in 21 minutes and 46 seconds
......@@ -212,9 +212,9 @@ struct piecewise_curve : public curve_abc<Time, Numeric, Safe, Point, Point_deri
std::size_t num_curves() const { return curves_.size(); }
const curve_ptr_t& curve_at_time(const time_t t) const { return curves_[find_interval(t)]; }
curve_ptr_t curve_at_time(const time_t t) const { return curves_[find_interval(t)]; }
const curve_ptr_t& curve_at_index(const std::size_t idx) const {
curve_ptr_t curve_at_index(const std::size_t idx) const {
if (Safe && idx >= num_curves()) {
throw std::length_error(
"curve_at_index: requested index greater than number of curves in piecewise_curve instance");
......
This diff is collapsed.
......@@ -360,6 +360,11 @@ class TestCurves(unittest.TestCase):
pc.derivate(0.4, 2)
pc.is_continuous(0)
pc.is_continuous(1)
a0 = pc.curve_at_index(0)
self.assertTrue(array_equal(a0(0.5), pc(0.5)))
self.assertTrue(a0 == a)
a0 = b # should not have any effect
self.assertTrue(array_equal(pc.curve_at_index(0)(0.5), a(0.5)))
# Test serialization
pc.saveAsText("serialization_pc.test")
pc_test = piecewise()
......@@ -413,6 +418,13 @@ class TestCurves(unittest.TestCase):
for i in range(N):
self.assertTrue(isclose(polC0(time_points[i, 0]), points[:, i]).all())
c0 = polC0.curve_at_index(0)
self.assertEqual(c0.min(), time_points[0])
self.assertEqual(c0.max(), time_points[1])
self.assertEqual(c0.dim(), 3)
mid_t = (c0.max() + c0.min()) /2.
self.assertTrue(array_equal(polC0(mid_t), c0(mid_t)))
polC1 = piecewise.FromPointsList(points, points_derivative, time_points)
self.assertEqual(polC1.min(), time_points[0, 0])
self.assertEqual(polC1.max(), time_points[-1, 0])
......@@ -500,6 +512,11 @@ class TestCurves(unittest.TestCase):
pc.derivate(0.4, 2)
pc.is_continuous(0)
pc.is_continuous(1)
a0 = pc.curve_at_index(0)
self.assertTrue(array_equal(a0(0.5), pc(0.5)))
self.assertTrue(a0 == a)
a0 = b # should not have any effect
self.assertTrue(array_equal(pc.curve_at_index(0)(0.5), a(0.5)))
# Test serialization
pc.saveAsText("serialization_pc.test")
pc_test = piecewise()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment