obj2gltf/specs/matchers/equals.js
2016-07-08 18:10:18 -04:00

46 lines
1.3 KiB
JavaScript

//This file is a copy of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/equals.js
/*global define*/
define([
'Cesium/Core/FeatureDetection'
], function(
FeatureDetection) {
'use strict';
/*global CanvasPixelArray*/
var typedArrayTypes = [];
// Earlier versions of IE do not support typed arrays
if (FeatureDetection.supportsTypedArrays()) {
typedArrayTypes.push(Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array);
if (typeof Uint8ClampedArray !== 'undefined') {
typedArrayTypes.push(Uint8ClampedArray);
}
if (typeof CanvasPixelArray !== 'undefined') {
typedArrayTypes.push(CanvasPixelArray);
}
}
function isTypedArray(o) {
return typedArrayTypes.some(function(type) {
return o instanceof type;
});
}
function typedArrayToArray(array) {
if (array !== null && typeof array === 'object' && isTypedArray(array)) {
return Array.prototype.slice.call(array, 0);
}
return array;
}
function equals(util, customEqualiyTesters, a, b) {
a = typedArrayToArray(a);
b = typedArrayToArray(b);
return util.equals(a, b, customEqualiyTesters);
}
return equals;
});