11///
2- /// Class: gpu_utils
2+ /// Class: GPUUtils
33///
44/// Various utility functions / snippets of code that GPU.JS uses internally.\
55/// This covers various snippets of code that is NOT gpu.js specific
66///
7- /// Note that all moethods in this class is "static" by nature `gpu_utils .functionName()`
7+ /// Note that all moethods in this class is "static" by nature `GPUUtils .functionName()`
88///
9- var gpu_utils = ( function ( ) {
9+ var GPUUtils = ( function ( ) {
1010
11- function gpu_utils ( ) {
12- throw new Error ( "This is a utility class - do not construct it" ) ;
13- }
11+ var GPUUtils = { } ;
1412
1513 // system_endianness closure based memoizer
16- var system_endianness_memoizer = null ;
14+ var endianness = null ;
1715
1816 ///
1917 /// Function: system_endianness
2018 ///
2119 /// Gets the system endianness, and cache it
2220 ///
2321 /// Returns:
24- /// {String} "LE" or "BE" depending on system settings
22+ /// {String} "LE" or "BE" depending on system architecture
2523 ///
2624 /// Credit: https://gist.github.com/TooTallNate/4750953
27- function system_endianness ( ) {
28- if ( system_endianness_memoizer !== null ) {
29- return system_endianness_memoizer ;
25+ function systemEndianness ( ) {
26+ if ( endianness !== null ) {
27+ return endianness ;
3028 }
3129
3230 var b = new ArrayBuffer ( 4 ) ;
3331 var a = new Uint32Array ( b ) ;
3432 var c = new Uint8Array ( b ) ;
3533 a [ 0 ] = 0xdeadbeef ;
36- if ( c [ 0 ] == 0xef ) return system_endianness_memoizer = 'LE' ;
37- if ( c [ 0 ] == 0xde ) return system_endianness_memoizer = 'BE' ;
34+ if ( c [ 0 ] == 0xef ) return endianness = 'LE' ;
35+ if ( c [ 0 ] == 0xde ) return endianness = 'BE' ;
3836 throw new Error ( 'unknown endianness' ) ;
3937 }
40- gpu_utils . system_endianness = system_endianness ;
38+ GPUUtils . systemEndianness = systemEndianness ;
4139
4240 ///
4341 /// Function: isFunction
@@ -53,7 +51,7 @@ var gpu_utils = (function() {
5351 function isFunction ( funcObj ) {
5452 return typeof ( funcObj ) === 'function' ;
5553 }
56- gpu_utils . isFunction = isFunction ;
54+ GPUUtils . isFunction = isFunction ;
5755
5856 ///
5957 /// Function: isFunctionString
@@ -74,7 +72,7 @@ var gpu_utils = (function() {
7472 }
7573 return false ;
7674 }
77- gpu_utils . isFunctionString = isFunctionString ;
75+ GPUUtils . isFunctionString = isFunctionString ;
7876
7977 // FUNCTION_NAME regex
8078 var FUNCTION_NAME = / f u n c t i o n ( [ ^ ( ] * ) / ;
@@ -93,7 +91,7 @@ var gpu_utils = (function() {
9391 function getFunctionName_fromString ( funcStr ) {
9492 return FUNCTION_NAME . exec ( funcStr ) [ 1 ] ;
9593 }
96- gpu_utils . getFunctionName_fromString = getFunctionName_fromString ;
94+ GPUUtils . getFunctionName_fromString = getFunctionName_fromString ;
9795
9896 // STRIP COMMENTS regex
9997 var STRIP_COMMENTS = / ( ( \/ \/ .* $ ) | ( \/ \* [ \s \S ] * ?\* \/ ) ) / mg;
@@ -119,7 +117,36 @@ var gpu_utils = (function() {
119117 result = [ ] ;
120118 return result ;
121119 }
122- gpu_utils . getParamNames_fromString = getParamNames_fromString ;
120+ GPUUtils . getParamNames_fromString = getParamNames_fromString ;
121+
122+ ///
123+ /// Function: clone
124+ ///
125+ /// Returns a clone
126+ ///
127+ /// Parameters:
128+ /// obj - {Object} Object to clone
129+ ///
130+ /// Returns:
131+ /// {Object} Cloned object
132+ ///
133+ function clone ( obj ) {
134+ if ( obj === null || typeof ( obj ) !== 'object' || 'isActiveClone' in obj )
135+ return obj ;
136+
137+ var temp = obj . constructor ( ) ; // changed
138+
139+ for ( var key in obj ) {
140+ if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
141+ obj . isActiveClone = null ;
142+ temp [ key ] = clone ( obj [ key ] ) ;
143+ delete obj . isActiveClone ;
144+ }
145+ }
146+
147+ return temp ;
148+ }
149+ GPUUtils . clone = clone ;
123150
124- return gpu_utils ;
151+ return GPUUtils ;
125152} ) ( ) ;
0 commit comments