I found this function in getHashCode
const _ExtractAsInt = (value: number) => {
return parseInt(value.toString().replace(/\W/g, ""));
};
/**
* Gets current vector hash code
* @returns the Vector2 hash code as a number
*/
public getHashCode(): number {
const x = _ExtractAsInt(this.x);
const y = _ExtractAsInt(this.y);
let hash = x;
hash = (hash * 397) ^ y;
return hash;
}
It transforms a number into a positive int, meaning that new Vector(-1,0,1)
and new Vector(1,0,1)
have the same hash code.
Why not use a hash library or an UUID or just simply use Symbol.for()
as an unique identifier?