Skip to content

Instantly share code, notes, and snippets.

View w8r's full-sized avatar
💭
learning

Alexander Milevski w8r

💭
learning
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@w8r
w8r / .block
Last active August 6, 2019 23:33
Leaflet + mapbox-gl
license: mit
height: 500
border: no
@w8r
w8r / Bunny.js
Created July 30, 2019 09:19 — forked from bberak/Bunny.js
How to use regl in React or React Native
import React, { PureComponent } from "react";
import { StyleSheet } from "react-native";
import ReglView from "./ReglView";
import mat4 from "gl-mat4";
import bunny from "bunny";
export default class Bunny extends PureComponent {
drawCommand = regl => {
return regl({
vert: `
@w8r
w8r / .gitignore
Last active April 29, 2019 09:22
Namespaces vs. classes
node_modules
dist
@w8r
w8r / welzl.js
Created November 12, 2018 17:53
welzl algorithm
function shuffle(arr) {
for (let i = arr.length - 1; i >= 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
j = Math.max(Math.min(j, i), 0);
const tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
return arr;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@w8r
w8r / heapset.js
Created September 19, 2018 13:27
HeapSet - unordered heap with random access and pop() and unshift()
export default class HeapSet {
constructor (values) {
this._values = values;
this._list = new Array(values.length * 3);
this._idToIndex = {};
const list = this._list;
for (let i = 0, prev = -1; i < values.length; i++) {
@w8r
w8r / point_in_polygon_wn.js
Created September 19, 2018 11:49
Point in polygon by winding number
function isLeft (x0, y0, x1, y1, x2, y2) {
return ((x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0));
}
export default function pointInPoygon (x, y, V) {
let wn = 0; // winding number
for (let i = 0; i < V.length - 1; i++) { // edge from V[i] to V[i+1]
const vi = V[i], vj = V[i + 1];
if (vi.y <= y) { // start y <= P.y
if (vj.y > y) { // an upward crossing
{
"nodes": [
{
"id": 0,
"data": {
"type": "device",
"name": "iPhone"
}
},
{
@w8r
w8r / mindisc.js
Created August 27, 2018 12:45
Minimum enclosing disc
function circleContainsCircle(cx, cy, cr, x, y, r) {
const dx = cx - x;
const dy = cy - y;
const dr = cr - r;
// reduce precision not to deal with square roots
return (dx * dx + dy * dy) < (dr * dr + 1e-6);
}
function from2discs(ax, ay, bx, by, ar, br) {
const dx = bx - ax;