Created
June 3, 2020 15:29
-
-
Save bhouston/d14b756ab92e9baaaefa23e280206c09 to your computer and use it in GitHub Desktop.
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
let arrayBuffer = new ArrayBuffer( 12 * 16 ); | |
let floatArray = new Float32Array( arrayBuffer ); | |
let intArray = new Int32Array( arrayBuffer ); | |
function hashFloat1( v ) { | |
floatArray[0] = v; | |
return intArray[0]; | |
} | |
function hashFloat2( v0, v1 ) { | |
floatArray[0] = v0; | |
floatArray[1] = v1; | |
// https://github.com/BabylonJS/Babylon.js/blob/master/src/Maths/math.vector.ts#L42 | |
let hash = intArray[0]; | |
return (hash * 397) ^ (intArray[1]); | |
} | |
function hashFloat3( v0, v1, v2 ) { | |
floatArray[0] = v0; | |
floatArray[1] = v1; | |
floatArray[2] = v2; | |
// https://github.com/BabylonJS/Babylon.js/blob/master/src/Maths/math.vector.ts#L718 | |
let hash = intArray[0] | 0; | |
hash = (hash * 397) ^ (intArray[1] | 0); | |
return (hash * 397) ^ (intArray[2] | 0); | |
} | |
function hashFloatArray( elements ) { | |
for( let i = 0; i < elements.length; i ++ ) { | |
floatArray[i] = elements[i]; | |
} | |
// https://github.com/BabylonJS/Babylon.js/blob/master/src/Maths/math.vector.ts#L4017 | |
let hash = intArray[0] | 0; | |
for (let i = 1; i < 16; i++) { | |
hash = (hash * 397) ^ (intArray[i] | 0); | |
} | |
return hash; | |
} | |
hashFloat3( 0.127, 0.255, 0.512 ); | |
hashFloat3( 0.127, 0.512, 0.512 ); | |
hashFloat3( 1.127, 0.512, 0.512 ); | |
hashFloat3( -0.127, 0.512, 0.512 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment