d1c6cc1692
This is a reland of 2c3cec998f
Original change's description:
> [canvaskit] Break up helper.js into smaller files
>
> This will hopefully make some things easier to find/understand.
> I have a few more ideas for breaking up other parts.
>
> Bug: skia:11203
> Change-Id: Ia54c13fd6e3c897e04a737b258f6e77c50a1aed3
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356839
> Reviewed-by: Nathaniel Nifong <nifong@google.com>
Bug: skia:11203
Change-Id: I8850e8e9e5f39f537232e0f1f8a814f763ab7853
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/363942
Reviewed-by: Kevin Lubick <kjlubick@google.com>
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/**
|
|
* This file houses miscellaneous helper functions and constants.
|
|
*/
|
|
|
|
var nullptr = 0; // emscripten doesn't like to take null as uintptr_t
|
|
|
|
|
|
function radiansToDegrees(rad) {
|
|
return (rad / Math.PI) * 180;
|
|
}
|
|
|
|
function degreesToRadians(deg) {
|
|
return (deg / 180) * Math.PI;
|
|
}
|
|
|
|
// See https://stackoverflow.com/a/31090240
|
|
// This contraption keeps closure from minifying away the check
|
|
// if btoa is defined *and* prevents runtime 'btoa' or 'window' is not defined.
|
|
// Defined outside any scopes to make it available in all files.
|
|
var isNode = !(new Function('try {return this===window;}catch(e){ return false;}')());
|
|
|
|
function almostEqual(floata, floatb) {
|
|
return Math.abs(floata - floatb) < 0.00001;
|
|
}
|
|
|
|
function saveBytesToFile(bytes, fileName) {
|
|
if (!isNode) {
|
|
// https://stackoverflow.com/a/32094834
|
|
var blob = new Blob([bytes], {type: 'application/octet-stream'});
|
|
url = window.URL.createObjectURL(blob);
|
|
var a = document.createElement('a');
|
|
document.body.appendChild(a);
|
|
a.href = url;
|
|
a.download = fileName;
|
|
a.click();
|
|
// clean up after because FF might not download it synchronously
|
|
setTimeout(function() {
|
|
URL.revokeObjectURL(url);
|
|
a.remove();
|
|
}, 50);
|
|
} else {
|
|
var fs = require('fs');
|
|
// https://stackoverflow.com/a/42006750
|
|
// https://stackoverflow.com/a/47018122
|
|
fs.writeFile(fileName, new Buffer(bytes), function(err) {
|
|
if (err) throw err;
|
|
});
|
|
}
|
|
} |