NURBSCurve.tests.js 2.0 KB

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