def test_remove_1(self): points = np.array([[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0]]) degree = 3 kv = np.array([0, 0, 0, 0, 1, 1, 1, 1], dtype=np.float64) weights = [1, 1, 1, 1] ts = np.linspace(0.0, 1.0, num=5) curve = SvNativeNurbsCurve(degree, kv, points, weights) orig_pts = curve.evaluate_array(ts) kv_err = sv_knotvector.check(degree, kv, len(points)) if kv_err is not None: raise Exception(kv_err) knot = 0.5 inserted = curve.insert_knot(knot, 2) self.assertEquals(len(inserted.get_control_points()), len(points) + 2) self.assert_numpy_arrays_equal(inserted.evaluate_array(ts), orig_pts, precision=8) expected_inserted_kv = np.array([0, 0, 0, 0, 0.5, 0.5, 1, 1, 1, 1]) inserted_kv = inserted.get_knotvector() self.assert_numpy_arrays_equal(inserted_kv, expected_inserted_kv, precision=8) removed = inserted.remove_knot(knot, 2) expected_removed_kv = kv self.assert_numpy_arrays_equal(removed.get_knotvector(), expected_removed_kv, precision=8) self.assert_numpy_arrays_equal(removed.evaluate_array(ts), orig_pts, precision=8)
def test_curve_eval(self): geomdl_curve = SvGeomdlCurve.build(self.degree, self.knotvector, self.control_points, self.weights) t1s = geomdl_curve.evaluate_array(self.ts) native_curve = SvNativeNurbsCurve(self.degree, self.knotvector, self.control_points, self.weights) t2s = native_curve.evaluate_array(self.ts) self.assert_numpy_arrays_equal(t1s, t2s, precision=8)
def test_insert_2(self): points = np.array([[0, 0, 0], [1, 1, 0], [2, 0, 0]]) degree = 2 kv = sv_knotvector.generate(degree, 3) weights = [1, 1, 1] curve = SvNativeNurbsCurve(degree, kv, points, weights) inserted = curve.insert_knot(0.5, 2) ts = np.array([0, 0.25, 0.5, 0.75, 1.0]) expected = curve.evaluate_array(ts) result = inserted.evaluate_array(ts) self.assert_numpy_arrays_equal(result, expected, precision=8)
def test_insert_1(self): points = np.array([[0, 0, 0], [1, 0, 0]]) kv = sv_knotvector.generate(1, 2) weights = [1, 1] curve = SvNativeNurbsCurve(1, kv, points, weights) curve = curve.insert_knot(0.5) ts = np.array([0, 0.25, 0.5, 0.75, 1.0]) expected = np.array([[0, 0, 0], [0.25, 0, 0], [0.5, 0, 0], [0.75, 0, 0], [1, 0, 0]]) result = curve.evaluate_array(ts) self.assert_numpy_arrays_equal(result, expected, precision=8)
def test_insert_3(self): points = np.array([[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0]]) degree = 2 kv = sv_knotvector.generate(degree, 4) weights = [1, 1, 1, 1] #print("test_insert_3: Kv:", kv) curve = SvNativeNurbsCurve(degree, kv, points, weights) inserted = curve.insert_knot(0.5) #print("Ins.kv:", inserted.knotvector) #print("Ins.cp:", inserted.control_points) ts = np.array([0, 0.25, 0.5, 0.75, 1.0]) expected = curve.evaluate_array(ts) result = inserted.evaluate_array(ts) self.assert_numpy_arrays_equal(result, expected, precision=8)