Skip to content

Instantly share code, notes, and snippets.

View w8r's full-sized avatar
💭
learning

Alexander Milevski w8r

💭
learning
View GitHub Profile
@w8r
w8r / circle_circle_intersection.js
Created January 12, 2017 17:44
Circle-circle intersection
/**
* Intersection point of 2 circles
*
* http://paulbourke.net/geometry/circlesphere/
*
* @param {number} x0
* @param {number} y0
* @param {number} r0
* @param {number} x1
* @param {number} y1
@w8r
w8r / minHeap-oop.js
Created January 23, 2017 09:23
Min-heap OOP style
// Prototype of a utility function to swap two integers
const swap = (arr, x, y) => {
let tmp = arr[x];
arr[x] = arr[y];
arr[y] = tmp;
};
const parent = (index) => Math.floor((index - 1) / 2);
@w8r
w8r / minHeap-fn.js
Created January 23, 2017 09:25
Min-heap functional style
/**
* Min heap priority queue implementation
*
* @param {Array} [arr] [[]]
* @param {function (a:number, b:number)} [cmp] [function (a, b) { return a - b; }] Comparator
* @return {Object}
*/
const heap = function (arr, cmp = (a, b) => a - b) {
/**
@w8r
w8r / minheap.js
Created February 9, 2017 10:21
min heap
function minHeap (cmp, arr = []) {
const up = (i) => {
let object = arr[i];
while (i > 0) {
let up = ((i + 1) >> 1) - 1,
parent = arr[up];
if (cmp(object, parent) >= 0) break;
arr[parent.index = i] = parent;
arr[object.index = i = up] = object;
@w8r
w8r / Readme.md
Last active February 10, 2017 16:37
Smallest enclosing circle

Smallest enclosing circle

This is an implementation of Welzl (1991) algorithm of smallest enclosing circle. Uses some parts of Mike Bostock's code for circumscribed discs.

Move points around and click to add new ones.

@w8r
w8r / .block
Created February 23, 2017 10:01 — forked from enjalot/.block
Rainbow Pack (adapted for d3.unconf badge)
license: gpl-3.0
height: 960
@w8r
w8r / .block
Created February 23, 2017 10:01 — forked from enjalot/.block
Rainbow Pack (adapted for d3.unconf badge)
license: gpl-3.0
height: 960
@w8r
w8r / matrix.js
Created February 23, 2017 17:24
Matrix container
class Matrix {
constructor (h, w, ArrayType = Uint32Array) {
this._w = w;
this._h = h;
this._arrayType = ArrayType;
this._mtr = new (this._arrayType)(this._w * this._h);
}
get (r, c) {
return this._mtr[this._w * r + c];
@w8r
w8r / index.html
Last active February 24, 2017 14:20
Collision detection on 1000s of lines
<!doctype html>
<html>
<head>
<title>Measure rtree for feature detection</title>
<script src="https://unpkg.com/d3@4.4.1"></script>
<script src="https://unpkg.com/rbush@2.0.1/rbush.min.js"></script>
<style>
html, body {
width: 100%;
@w8r
w8r / sqrt-non-recursive.js
Last active February 27, 2017 16:36
Non-reqursive sqrt approximation
function sqrt(x, eps = 1e-3){
function mean(a,b){
return (a + b) / 2
}
function newEstimate(estimate){
return mean( estimate, x / estimate )
}