// Copyright 2016 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland // www.source-code.biz, www.inventec.ch/chdh // // License: GPL, GNU General Public License, http://www.gnu.org/licenses/gpl.html // Home page: http://www.source-code.biz/snippets/typescript namespace Polyfills { export const isInteger = Number.isInteger || function (value: any) { return typeof value === "number" && isFinite(value) && Math.floor(value) === value; }; export const sign = Math.sign || function (x: number) { return x > 0 ? 1 : -1; }; export const hypot = Math.hypot || function (...x: number[]) { let sum = 0; for (let i = 0; i < x.length; i++) { sum += x[i] * x[i]; } return Math.sqrt(sum); }; export const performanceNow = (window.performance && window.performance.now) ? function() {return window.performance.now(); } : Date.now; export const windowRequestAnimationFrame = window.requestAnimationFrame || function (callback) { return window.setTimeout(callback, 0); }; export const windowCancelAnimationFrame = window.cancelAnimationFrame || function (handle) { return window.clearTimeout(handle); }; } // end namespace Polyfills //------------------------------------------------------------------------------ // Declaration of ES6 functions. interface NumberConstructor { isInteger (value: any): boolean; } interface Math { sign(x: number): number; hypot(...x: number[]): number; }