Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created March 14, 2010 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmarkbage/332160 to your computer and use it in GitHub Desktop.
Save sebmarkbage/332160 to your computer and use it in GitHub Desktop.
/*
---
name: ART.Wedge
description: Wedge shape for ART
authors: [Sebastian Markbåge](http://calyptus.eu)
provides: [ART.Wedge]
requires: [ART.Path, ART.Shape]
...
*/
ART.Wedge = new Class({
Extends: ART.Shape,
initialize: function(innerRadius, outerRadius, startAngle, endAngle){
this.parent();
if (innerRadius != null || outerRadius != null) this.draw(innerRadius, outerRadius, startAngle, endAngle);
},
draw: function(innerRadius, outerRadius, startAngle, endAngle){
var path = new ART.Path;
var circle = Math.PI * 2,
radiansPerDegree = Math.PI / 180,
sa = startAngle * radiansPerDegree % circle || 0,
ea = endAngle * radiansPerDegree % circle || 0,
ir = Math.min(innerRadius || 0, outerRadius || 0),
or = Math.max(innerRadius || 0, outerRadius || 0),
a = sa > ea ? circle - sa + ea : ea - sa;
if (a >= circle){
path.move(0, or).arc(or * 2, 0, or).arc(-or * 2, 0, or);
if (ir) path.move(or - ir, 0).counterArc(ir * 2, 0, ir).counterArc(-ir * 2, 0, ir);
} else {
var ss = Math.sin(sa), es = Math.sin(ea),
sc = Math.cos(sa), ec = Math.cos(ea),
ds = es - ss, dc = ec - sc, dr = ir - or,
large = a > Math.PI;
path.move(or + or * ss, or - or * sc).arc(or * ds, or * -dc, or, or, large).line(dr * es, dr * -ec);
if (ir) path.counterArc(ir * -ds, ir * dc, ir, ir, large);
}
path.close();
return this.parent(path);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment