-
-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
173 additions
and
32 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
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
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
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,56 @@ | ||
OV.Node = class | ||
{ | ||
constructor () | ||
{ | ||
this.parent = null; | ||
this.name = ''; | ||
this.childNodes = []; | ||
this.meshIndices = []; | ||
} | ||
|
||
GetParent () | ||
{ | ||
return this.parent; | ||
} | ||
|
||
GetName () | ||
{ | ||
return this.name; | ||
} | ||
|
||
SetName (name) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
AddChildNode (node) | ||
{ | ||
node.parent = this; | ||
this.childNodes.push (node); | ||
return this.childNodes.length - 1; | ||
} | ||
|
||
GetChildNodes () | ||
{ | ||
return this.childNodes; | ||
} | ||
|
||
AddMeshIndex (index) | ||
{ | ||
this.meshIndices.push (index); | ||
return this.meshIndices.length - 1; | ||
} | ||
|
||
GetMeshIndices () | ||
{ | ||
return this.meshIndices; | ||
} | ||
|
||
EnumerateChildren (processor) | ||
{ | ||
for (const childNode of this.childNodes) { | ||
processor (childNode); | ||
childNode.EnumerateChildren (processor); | ||
} | ||
} | ||
}; |
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,60 @@ | ||
var assert = require ('assert'); | ||
|
||
describe ('Node', function() { | ||
it ('Default Initialization', function () { | ||
let node = new OV.Node (); | ||
assert.strictEqual (node.GetName (), ''); | ||
assert.deepStrictEqual (node.GetChildNodes (), []); | ||
assert.deepStrictEqual (node.GetMeshIndices (), []); | ||
}); | ||
|
||
it ('Set Name', function () { | ||
let node = new OV.Node (); | ||
node.SetName ('New Name'); | ||
assert.strictEqual (node.GetName (), 'New Name'); | ||
}); | ||
|
||
it ('Add Mesh Indices', function () { | ||
let node = new OV.Node (); | ||
node.AddMeshIndex (0); | ||
node.AddMeshIndex (4); | ||
node.AddMeshIndex (8); | ||
assert.deepStrictEqual (node.GetMeshIndices (), [0, 4, 8]); | ||
}); | ||
|
||
it ('Add Child Node', function () { | ||
let node = new OV.Node (); | ||
let child1 = new OV.Node (); | ||
let child2 = new OV.Node (); | ||
child1.SetName ('Child 1'); | ||
child2.SetName ('Child 2'); | ||
node.AddChildNode (child1); | ||
node.AddChildNode (child2); | ||
assert.strictEqual (node.GetChildNodes ().length, 2); | ||
assert.strictEqual (node.GetChildNodes ()[0].GetName (), 'Child 1'); | ||
assert.strictEqual (node.GetChildNodes ()[1].GetName (), 'Child 2'); | ||
assert.strictEqual (node.GetChildNodes ()[0].GetParent (), node); | ||
assert.strictEqual (node.GetChildNodes ()[1].GetParent (), node); | ||
}); | ||
|
||
it ('Recursive Enumeration', function () { | ||
let node = new OV.Node (); | ||
let child1 = new OV.Node (); | ||
let child2 = new OV.Node (); | ||
let child11 = new OV.Node (); | ||
let child12 = new OV.Node (); | ||
|
||
node.AddChildNode (child1); | ||
node.AddChildNode (child2); | ||
|
||
child1.AddChildNode (child11); | ||
child1.AddChildNode (child12); | ||
|
||
let enumerated = []; | ||
node.EnumerateChildren ((child) => { | ||
enumerated.push (child); | ||
}); | ||
|
||
assert.deepStrictEqual (enumerated, [child1, child11, child12, child2]); | ||
}); | ||
}); |
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
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
Oops, something went wrong.