Skip to content

Instantly share code, notes, and snippets.

🔥
making stuff faster

Vladimir Agafonkin mourner

🔥
making stuff faster
Block or report user

Report or block mourner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mourner
mourner / simplify.wasm
Created Sep 7, 2017
WIP WebAssembly simplify
View simplify.wasm
(module
(func $segDist (export "segDist")
(param $x0 f64) (param $y0 f64)
(param $x1 f64) (param $y1 f64)
(param $x2 f64) (param $y2 f64)
(result f64)
(local $x f64) (local $y f64)
(local $dx f64) (local $dy f64)
@mourner
mourner / index.js
Last active Sep 5, 2017
Fast GL JS expressions proof of concept
View index.js
'use strict';
function genFn(ctx, body) {
let id = ctx.cache[body];
if (!id) {
id = ctx.id++;
ctx.cache[body] = id;
ctx.src += `
function e${id}() { ${body} }`;
}
@mourner
mourner / index.css
Last active Sep 24, 2019
Mapbox GL JS + SunCalc hack Friday
View index.css
html, body {
margin: 0;
font-family: sans-serif;
}
#map {
position: absolute;
top: 45px;
bottom: 0;
@mourner
mourner / sunpos.js
Last active Mar 2, 2017
Minimal sun position calculating function
View sunpos.js
function getSunPosition(date, lat, lng) {
var r = Math.PI / 180, sin = Math.sin, cos = Math.cos, t = date / 315576e7 - 0.3,
m = r * (357.52911 + t * (35999.05029 - t * 1537e-7)), c = cos(r * (125.04 - 1934.136 * t)),
l = r * ((280.46646 + t * (36000.76983 + t * 3032e-7)) + (1.914602 - t * (4817e-6 - t * 14e-6)) *
sin(m) - (569e-5 + 478e-5 * c)) + (0.019993 - 101e-6 * t) * sin(2 * m) + 289e-6 * sin(3 * m),
e = r * (84381.448 - t * (46.815 - t * (59e-5 + 1813e-6 * t))) / 3600 + r * 256e-5 * c,
d = Math.asin(sin(e) * sin(l)),
h = r * (280.46061837 + 13184999.8983375 * t) + r * lng - Math.atan2(cos(e) * sin(l), cos(l)),
z = Math.atan2(sin(h), cos(h) * sin(r * lat) - (sin(d) / cos(d)) * cos(r * lat)),
a = Math.asin(sin(r * lat) * sin(d) + cos(r * lat) * cos(d) * cos(h));
@mourner
mourner / bench.js
Created Jan 17, 2017
Running a Mapbox GL JS benchmark in headless Electron
View bench.js
mapboxgl.accessToken = 'pk.eyJ1IjoibW91cm5lciIsImEiOiJWWnRiWG1VIn0.j6eccFHpE3Q04XPLI7JxbA';
console.log('Version: ' + mapboxgl.version);
const container = document.createElement('div');
container.style.width = '1200px';
container.style.height = '700px';
document.body.appendChild(container);
@mourner
mourner / arr.js
Created Dec 19, 2016
array vs typed array vs object for points
View arr.js
'use strict';
var v8 = require('v8');
var N = 1000000;
var values = [];
for (var i = 0; i < 2 * N; i++) values.push(Math.random());
var memStart = v8.getHeapStatistics().used_heap_size;
@mourner
mourner / approx.js
Created Aug 9, 2016
Mercator horner approximation
View approx.js
// not working
// based on https://github.com/Project-OSRM/osrm-backend/blob/master/include/util/web_mercator.hpp
'use strict';
function latY(lat) {
var sin = Math.sin(lat * Math.PI / 180);
return 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
}
View viz.js
function DebugViz(id, options) {
var canvas = this.canvas = document.getElementById(id);
var ctx = this.ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
}
var padding = 5;
DebugViz.prototype = {
@mourner
mourner / bad-polygons.json
Last active Mar 17, 2016
Polygons causing problems in earcut master
View bad-polygons.json
{"deviation":0.14022095,"coords":[[[3304,1016],[3264,1032],[3280,1056],[3352,1072],[3400,1024],[3448,1008],[3472,1016],[3480,1056],[3432,1064],[3424,1096],[3392,1128],[3368,1120],[3368,1152],[3392,1192],[3368,1192],[3336,1144],[3352,1192],[3344,1224],[3288,1256],[3328,1336],[3328,1408],[3312,1416],[3312,1480],[3280,1592],[3296,1688],[3256,1736],[3264,1792],[3248,1800],[3240,1864],[3216,1880],[3160,1880],[3136,1864],[3128,1896],[3056,1896],[3048,1864],[3008,1832],[2976,1864],[3040,1896],[3040,1928],[3072,1992],[3040,2032],[3040,2056],[3064,2064],[3096,2040],[3112,1920],[3176,2000],[3192,1992],[3200,1936],[3216,1936],[3208,1992],[3224,2032],[3224,2112],[3200,2192],[3176,2216],[3152,2216],[3144,2248],[3104,2256],[3104,2312],[3080,2304],[3072,2328],[3040,2320],[3016,2360],[2984,2360],[2976,2400],[3048,2416],[3056,2376],[3096,2368],[3104,2344],[3248,2352],[3232,2304],[3272,2304],[3288,2328],[3312,2328],[3384,2264],[3416,2280],[3432,2240],[3496,2248],[3512,2216],[3536,2224],[3560,2264],[3488,2296],[3456,2328],[3416
View debug.js
'use strict';
var polyclip = require('./');
var subject = [[3116,3071],[3118,3068],[3108,3102],[3100,3105],[3096,3113],[3099,3121],[3091,3135],[3099,3133],[3105,3144],[3113,3144],[3105,3143],[3117,3157],[3129,3155],[3137,3167],[3152,3177],[3160,3187],[3172,3204],[3174,3195],[3179,3217],[3197,3225],[3189,3217],[3203,3217],[3199,3202],[3186,3188],[3186,3174],[3174,3166],[3165,3145],[3168,3143],[3159,3143],[3151,3118],[3154,3107],[3165,3110],[3174,3105],[3175,3082],[3186,3076],[3178,3089],[3183,3103],[3196,3116],[3181,3105],[3180,3111],[3155,3111],[3173,3130],[3179,3150],[3197,3170],[3199,3178],[3216,3190],[3214,3203],[3235,3219],[3243,3212],[3244,3198],[3246,3208],[3244,3219],[3236,3240],[3237,3249],[3248,3262],[3263,3267],[3327,3313],[3338,3327],[3340,3340],[3351,3349],[3353,3361],[3345,3365],[3355,3387],[3363,3392],[3364,3401],[3375,3413],[3382,3421],[3394,3431],[3404,3433],[3398,3416],[3406,3433],[3409,3422],[3428,3400],[3423,3392],[3446,3377],[3461,3366],[3495,3354],[3506,3343],[3506,3334],[3495,3338],[35
You can’t perform that action at this time.