-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* NURBSCurve.toJSON method * NURBSCurve.fromJSON method * Add NURBSCurve.tests.js to test runner * Move NURBSCurve.tests.js to test/unit/addons
- Loading branch information
Showing
3 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* global QUnit */ | ||
|
||
import { NURBSCurve } from '../../../../examples/jsm/curves/NURBSCurve.js'; | ||
import { MathUtils } from '../../../../src/math/MathUtils.js'; | ||
import { Vector4 } from '../../../../src/math/Vector4.js'; | ||
|
||
export default QUnit.module( 'Extras', () => { | ||
|
||
QUnit.module( 'Curves', () => { | ||
|
||
QUnit.module( 'NURBSCurve', ( hooks ) => { | ||
|
||
let _nurbsCurve = undefined; | ||
|
||
hooks.before( function () { | ||
|
||
const nurbsControlPoints = []; | ||
const nurbsKnots = []; | ||
const nurbsDegree = 3; | ||
|
||
for ( let i = 0; i <= nurbsDegree; i ++ ) { | ||
|
||
nurbsKnots.push( 0 ); | ||
|
||
} | ||
|
||
for ( let i = 0, j = 20; i < j; i ++ ) { | ||
|
||
const point = new Vector4( Math.random(), Math.random(), Math.random(), 1 ); | ||
nurbsControlPoints.push( point ); | ||
|
||
const knot = ( i + 1 ) / ( j - nurbsDegree ); | ||
nurbsKnots.push( MathUtils.clamp( knot, 0, 1 ) ); | ||
|
||
} | ||
|
||
_nurbsCurve = new NURBSCurve( nurbsDegree, nurbsKnots, nurbsControlPoints ); | ||
|
||
} ); | ||
|
||
QUnit.test( 'toJSON', ( assert ) => { | ||
|
||
const json = _nurbsCurve.toJSON(); | ||
|
||
assert.equal( json.degree, _nurbsCurve.degree, "json.degree ok" ); | ||
assert.deepEqual( json.knots, _nurbsCurve.knots, "json.knots ok" ); | ||
assert.deepEqual( json.controlPoints, _nurbsCurve.controlPoints.map( p => p.toArray() ), "json.controlPoints ok" ); | ||
assert.equal( json.startKnot, _nurbsCurve.startKnot, "json.startKnot ok" ); | ||
assert.equal( json.endKnot, _nurbsCurve.endKnot, "json.endKnot ok" ); | ||
|
||
} ); | ||
|
||
QUnit.test( 'fromJSON', ( assert ) => { | ||
|
||
const json = _nurbsCurve.toJSON(); | ||
const fromJson = new NURBSCurve().fromJSON( json ); | ||
|
||
assert.equal( fromJson.degree, _nurbsCurve.degree, "json.degree ok" ); | ||
assert.deepEqual( fromJson.knots, _nurbsCurve.knots, "json.knots ok" ); | ||
assert.deepEqual( fromJson.controlPoints, _nurbsCurve.controlPoints, "json.controlPoints ok" ); | ||
assert.equal( fromJson.startKnot, _nurbsCurve.startKnot, "json.startKnot ok" ); | ||
assert.equal( fromJson.endKnot, _nurbsCurve.endKnot, "json.endKnot ok" ); | ||
|
||
} ); | ||
|
||
} ); | ||
|
||
} ); | ||
|
||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters