Skip to content

Instantly share code, notes, and snippets.

View w8r's full-sized avatar
💭
learning

Alexander Milevski w8r

💭
learning
View GitHub Profile
import math
def between(a, b, c):
return a <= b and b <= c
class Region(object):
def intersects(self, other):
raise NotImplemented(
"%s does not know how to check for intersection with %s"
//
// CatmullRomLength()
//
//
//*******************************************************************************************
template <typename T>
T CatmullRomLength( const CVector2<T> &p0,
const CVector2<T> &p1,
const CVector2<T> &p2,
const CVector2<T> &p3,
@petrsm
petrsm / gist:d47be1fbd0f240b5051bdc81cb62f79e
Created November 22, 2017 08:28
2D point projection onto cubic (Catmull-Rom) curve
//
// CatmullRomCurveProjectPt()
//
//
//*******************************************************************************************
template <typename T>
T CatmullRomCurveProjectPt( const CVector2<T> &p0,
const CVector2<T> &p1,
const CVector2<T> &p2,
const CVector2<T> &p3,
@armollica
armollica / .DS_Store
Last active July 16, 2018 11:31
World Tour along Flying Arcs
@elijahmanor
elijahmanor / fake-server-unit-test.js
Last active August 28, 2018 09:23
Unit Test like a Secret Agent with Sinon.js
describe("getTweets - Server", function () {
var server, fakeData = [ /* ... */ ];
before(function () {
// Doesn’t work :( It’s JSONP!
server = sinon.fakeServer.create();
server.respondWith(
"GET",
"https://api.twitter.com/.../elijahmanor.json?count=5",
[200, { "Content-Type": "application/json" }, JSON.stringify(fakeData)]
@grahamboree
grahamboree / Quadtree.cs
Created November 15, 2017 17:25
Generic Loose Quadtree for Unity
using System.Collections.Generic;
using UnityEngine;
public interface QuadtreeItem {
Rect GetBounds();
}
public class QuadtreeNode<T> where T : QuadtreeItem {
const int MAX_DEPTH = 10;
@veltman
veltman / README.md
Last active November 25, 2019 20:16
Smoother polygon transitions

Smooth transitioning US tour in the same vein as this example. Steps:

  1. Compares both shapes and adds evenly-spaced points to whichever polygon has fewer so that both have the same number of points
  2. Picks the winding of the first polygon that minimizes the sum of the squared distances between point pairs

Some possible improvements:

  • Adding additional points to both shapes first such that every segment longer than a certain distance is bisected
  • Tweaking the placement of added points with simulated annealing
  • Using a cost function that factors in self-intersections at the halfway mark in addition to distance traveled
@MoritzStefaner
MoritzStefaner / .block
Last active January 20, 2020 10:46
Force-based label placement
license: apache-2.0
@birkir
birkir / Cube.tsx
Created September 2, 2019 14:42
react native react-three-fiber
function Cube({ position }: { position?: number[] | THREE.Vector3 }) {
const mesh = useRef<THREE.Mesh>();
const touched = useTouch(mesh);
return (
<mesh ref={mesh} castShadow receiveShadow position={position}>
<boxGeometry attach="geometry" args={[1, 1, 1]} />
<meshStandardMaterial
attach="material"
color={touched ? 0xff0000 : 0xffffff}
@rpgove
rpgove / .block
Last active January 10, 2023 06:29
Force-directed layout
license: gpl-3.0
height: 600