Skip to content

Instantly share code, notes, and snippets.

@rafalrusin
Created March 7, 2011 21:12
Show Gist options
  • Save rafalrusin/859239 to your computer and use it in GitHub Desktop.
Save rafalrusin/859239 to your computer and use it in GitHub Desktop.
bisect.fx
var u:Point2D = a.findBoundaryPoint(b.position, a.position);
var v:Point2D = b.findBoundaryPoint(a.position, b.position);
var l:Float = Math.sqrt(pointsLenSqr(u, v));
content = [
Path {
transforms: [
Affine {
mxx: (v.x-u.x)/l
mxy: (v.y-u.y)/l
myx: (v.y-u.y)/l
myy: -(v.x-u.x)/l
tx: u.x
ty: u.y
}
]
elements: [
MoveTo {
x: 0
y: 0
}
LineTo {
x: l
y: 0
}
LineTo {
x: l-10
y: 5
}
MoveTo {
x: l
y: 0
}
LineTo {
x: l-10
y: -5
}
...
public function findBoundaryPoint(a:Point2D,b:Point2D):Point2D {
// a is outside, b is inside
var m:Point2D = middle(a,b);
if (pointsLenSqr(a, b) < 1.) {
return m;
} else {
var n:Point2D = Point2D {
x: m.x - position.x
y: m.y - position.y
}
if (contains(n)) {
return findBoundaryPoint(a,m);
} else {
return findBoundaryPoint(m,b);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment