Add Unit test for failing conversion of table to std::vector.
@@ -3,15 +3,13 @@ local ts = require("tinyspline")
+TestFrames = {}
+
local function assertOrthogonal(v1, v2)
angle = v1:angle(v2)
lu.assertAlmostEquals(angle, 90, ts.TS_POINT_EPSILON)
end
-
-
-TestFrames = {}
-
function TestFrames:testVectors()
-- Given
spline = ts.BSpline(7, 2)
@@ -50,4 +48,56 @@ TestFrames = {}
+TestInterpolation = {}
+
+local function assertEquals(vec, x, y)
+ dist = vec:distance(ts.Vec2(x, y))
+ lu.assertAlmostEquals(dist, 0, ts.TS_POINT_EPSILON)
+end
+
+function TestInterpolation:testCubicNatural()
+ -- Given
+ points = {
+ 1.0, -1.0, -- P1
+ -1.0, 2.0, -- P2
+ 1.0, 4.0, -- P3
+ 4.0, 3.0, -- P4
+ 7.0, 5.0 -- P5
+ }
+
+ -- When
+ spline = ts.BSpline_interpolate_cubic_natural(points, 2)
+
+ -- Then
+ lu.assertEquals(spline.num_control_points, 16)
+
+ -- First bezier segment
+ assertEquals(spline:control_point_vec_2at(0), 1.0, -1.0)
+ assertEquals(spline:control_point_vec_2at(1), 0.0, 0.0)
+ assertEquals(spline:control_point_vec_2at(2), -1.0, 1.0)
+ assertEquals(spline:control_point_vec_2at(3), -1.0, 2.0)
+
+ -- Second bezier segment
+ assertEquals(spline:control_point_vec_2at(4), -1.0, 2.0)
+ assertEquals(spline:control_point_vec_2at(5), -1.0, 3.0)
+ assertEquals(spline:control_point_vec_2at(6), 0.0, 4.0)
+ assertEquals(spline:control_point_vec_2at(7), 1.0, 4.0)
+
+ -- Third bezier segment
+ assertEquals(spline:control_point_vec_2at(8), 1.0, 4.0)
+ assertEquals(spline:control_point_vec_2at(9), 2.0, 4.0)
+ assertEquals(spline:control_point_vec_2at(10), 3.0, 3.0)
+ assertEquals(spline:control_point_vec_2at(11), 4.0, 3.0)
+
+ -- Forth bezier segment
+ assertEquals(spline:control_point_vec_2at(12), 4.0, 3.0)
+ assertEquals(spline:control_point_vec_2at(13), 5.0, 3.0)
+ assertEquals(spline:control_point_vec_2at(14), 6.0, 4.0)
+ assertEquals(spline:control_point_vec_2at(15), 7.0, 5.0)
+end
+
+-- end TestInterpolation
+
+
+
os.exit( lu.run() )
