Navigation Menu

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_sort_comparator.js
Created January 12, 2017 17:27
Circle Sort Comparator
/**
* This is a comparator for two points to position them along the circle around C(x,y)
*
* @example
* points.sort(function (a, b) {
* return comparator(a.x, a.y, bx, b.y, c.x, c.y);
* });
*
* @param {number} ax
* @param {number} ay
@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 / Readme.md
Last active November 14, 2017 22:34
Removing overlaps on radial layout

This algorithm moves along the circle and removes the overlapping of the nodes laid out on a circle maintaining a custom gap between them. O(n), doesn't use trigonometry. Relaxation sometimes cannot be completed in one sweep, cause it moves nodes in one direction: clockwise.

Special case is when a node is pushed across the 0° mark.

@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 / Readme.md
Last active January 27, 2017 17:37
Huygens' arc length approximation
@w8r
w8r / Readme.md
Last active June 1, 2017 08:08
Circle packing!

Circle packing

Simple directed layout to pack different-sized circles as close as possible

@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 / 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 / .block
Created February 23, 2017 10:01 — forked from enjalot/.block
Rainbow Pack (adapted for d3.unconf badge)
license: gpl-3.0
height: 960