Skip to content

Instantly share code, notes, and snippets.

@eyelash
Created February 14, 2016 14:26
Show Gist options
  • Select an option

  • Save eyelash/17e319a6bc4711e941e4 to your computer and use it in GitHub Desktop.

Select an option

Save eyelash/17e319a6bc4711e941e4 to your computer and use it in GitHub Desktop.
function curve(x) {
return Math.sqrt(1 - x * x);
}
function curveInt(x) {
return 0.5*(Math.sqrt(1-x*x)*x+Math.asin(x));
}
function corner(x, y, w, h) {
if ((x+w)*(x+w)+(y+h)*(y+h) <= 1) return 1;
if (x*x+y*y >= 1) return 0;
//if (x > 1 || y > 1) return 0;
var start = x;
var end = x + w;
var result = 0;
if (curve(x) > y + h) {
start = curve(y+h);
result += (start-x) / w;
}
if (curve(y) < end) {
end = curve(y);
}
result += (curveInt(end)-curveInt(start)-(end-start)*y)/(w*h);
if (x <= 50/512) console.log(start*512 + ", " + end*512 + ", result " + result);
if (result < 0) console.log("error");
return result;
}
function easyCorner(x, y, w, h) {
return corner(x/w, y/h, 1/w, 1/h) * 256;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment