NURBSCurve.tests.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* global QUnit */
  2. import { NURBSCurve } from '../../../../examples/jsm/curves/NURBSCurve.js';
  3. import { MathUtils } from '../../../../src/math/MathUtils.js';
  4. import { Vector4 } from '../../../../src/math/Vector4.js';
  5. export default QUnit.module( 'Extras', () => {
  6. QUnit.module( 'Curves', () => {
  7. QUnit.module( 'NURBSCurve', ( hooks ) => {
  8. let _nurbsCurve = undefined;
  9. hooks.before( function () {
  10. const nurbsControlPoints = [];
  11. const nurbsKnots = [];
  12. const nurbsDegree = 3;
  13. for ( let i = 0; i <= nurbsDegree; i ++ ) {
  14. nurbsKnots.push( 0 );
  15. }
  16. for ( let i = 0, j = 20; i < j; i ++ ) {
  17. const point = new Vector4( Math.random(), Math.random(), Math.random(), 1 );
  18. nurbsControlPoints.push( point );
  19. const knot = ( i + 1 ) / ( j - nurbsDegree );
  20. nurbsKnots.push( MathUtils.clamp( knot, 0, 1 ) );
  21. }
  22. _nurbsCurve = new NURBSCurve( nurbsDegree, nurbsKnots, nurbsControlPoints );
  23. } );
  24. QUnit.test( 'toJSON', ( assert ) => {
  25. const json = _nurbsCurve.toJSON();
  26. assert.equal( json.degree, _nurbsCurve.degree, 'json.degree ok' );
  27. assert.deepEqual( json.knots, _nurbsCurve.knots, 'json.knots ok' );
  28. assert.deepEqual( json.controlPoints, _nurbsCurve.controlPoints.map( p => p.toArray() ), 'json.controlPoints ok' );
  29. assert.equal( json.startKnot, _nurbsCurve.startKnot, 'json.startKnot ok' );
  30. assert.equal( json.endKnot, _nurbsCurve.endKnot, 'json.endKnot ok' );
  31. } );
  32. QUnit.test( 'fromJSON', ( assert ) => {
  33. const json = _nurbsCurve.toJSON();
  34. const fromJson = new NURBSCurve().fromJSON( json );
  35. assert.equal( fromJson.degree, _nurbsCurve.degree, 'json.degree ok' );
  36. assert.deepEqual( fromJson.knots, _nurbsCurve.knots, 'json.knots ok' );
  37. assert.deepEqual( fromJson.controlPoints, _nurbsCurve.controlPoints, 'json.controlPoints ok' );
  38. assert.equal( fromJson.startKnot, _nurbsCurve.startKnot, 'json.startKnot ok' );
  39. assert.equal( fromJson.endKnot, _nurbsCurve.endKnot, 'json.endKnot ok' );
  40. } );
  41. } );
  42. } );
  43. } );
粤ICP备19079148号