Skip to content

Instantly share code, notes, and snippets.

@fserb
fserb / polygon.hx
Created March 24, 2014 22:25
SAT for Polygon intersection in 50 lines of Haxe
// Given a Vec2 vector class...
function hitPolygonAxis(points: Array<Vec2>, ret: Array<Float>) {
for (i in 0...points.length) {
var a = points[i];
var b = points[(i+1) % points.length];
var v = Vec2.make(b.x - a.x, b.y - a.y).normal();
// we should be able to only use half circunference.
ret.push(v.angle());
}
}
import haxe.macro.Expr;
class FTW
{
public static function build()
{
return haxe.macro.Context.getBuildFields().map(transformField);
}
static function transformField(field:Field)