real q;
void operator init(pair center=(0,0), real q=1, real radius=2mm,
- pen outline=currentpen, pen fill=red, Label label="") {
+ pen outline=currentpen, pen fill=red, Label L="") {
this.lc.operator init(center=center, radius=radius, outline=outline,
- fill=fill, label=label);
+ fill=fill, L=L);
this.q = q;
}
// positive charge
Charge pCharge(pair center=(0,0), real q=1, real radius=2mm,
- pen outline=currentpen, Label label="")
+ pen outline=currentpen, Label L="")
{
return Charge(center=center, q=q, radius=radius, outline=outline, fill=red,
- label=label);
+ L=L);
}
// negative charge
Charge nCharge(pair center=(0,0), real q=-1, real radius=2mm,
- pen outline=currentpen, Label label="")
+ pen outline=currentpen, Label L="")
{
return Charge(center=center, q=q, radius=radius, outline=outline, fill=blue,
- label=label);
+ L=L);
}
// neutral charge
Charge neutralCharge(pair center=(0,0), real radius=2mm,
- pen outline=currentpen, Label label="")
+ pen outline=currentpen, Label L="")
{
return Charge(center=center, q=0, radius=radius, outline=outline, fill=grey,
- label=label);
+ L=L);
}
// auto-signed charge
Charge aCharge(pair center=(0,0), real q=1, real radius=2mm,
- pen outline=currentpen, Label label="")
+ pen outline=currentpen, Label L="")
{
Charge c;
if (q > 0) {
- c = pCharge(center, q, radius, outline, label);
+ c = pCharge(center, q, radius, outline, L);
} else if (q < 0) {
- c = nCharge(center, q, radius, outline, label);
+ c = nCharge(center, q, radius, outline, L);
} else {
- c = neutralCharge(center, radius, outline, label);
+ c = neutralCharge(center, radius, outline, L);
}
return c;
}
lc.label = "a";
lc.center = (-2u, 0.5u);
lc.draw();
-lc.draw_label(label=Label("e", align=E));
+lc.draw_label(Label("e", align=E));
lc.center = (-2u, 0);
lc.label.align = W;
lc.draw();
-lc.draw_label(label="b");
-lc.draw_label(label=Label("c", align=E));
-lc.draw_label(label=rotate(90)*Label("e------I", align=S));
-lc.draw_label(label=rotate(45)*Label("e------I", align=S));
+lc.draw_label("b");
+lc.draw_label(Label("c", align=E));
+lc.draw_label(rotate(90)*Label("e------I", align=S));
+lc.draw_label(rotate(45)*Label("e------I", align=S));
lc.center = (-2u, -2u);
lc.radius = u/2;
lc.label.align = E;
Label label;
void operator init(pair center=(0,0), real radius=2mm,
- pen outline=currentpen, pen fill=grey, Label label="") {
+ pen outline=currentpen, pen fill=grey, Label L="") {
this.center = center;
this.radius = radius;
this.outline = outline;
this.fill = fill;
- this.label = label;
+ this.label = L;
}
- void draw_label(picture pic=currentpicture, Label label=null) {
+ void draw_label(picture pic=currentpicture, Label L=null) {
picture picL;
align a;
- if (label == null) {
- label = this.label;
+ if (L == null) {
+ L = this.label;
}
- a = label.align;
- if (label.align != NoAlign && label.align != Align) {
- real m = labelmargin(label.p);
+ a = L.align;
+ if (L.align != NoAlign && L.align != Align) {
+ real m = labelmargin(L.p);
real scale = (m + this.radius)/m;
- if (label.align.is3D) {
- label.align.dir3 *= scale;
+ if (L.align.is3D) {
+ L.align.dir3 *= scale;
} else {
- label.align.dir *= scale;
+ L.align.dir *= scale;
}
}
- label(pic=pic, L=label, position=this.center);
- label.align = a;
+ label(pic=pic, L=L, position=this.center);
+ L.align = a;
}
void draw(picture pic=currentpicture) {
real m;
void operator init(pair center=(0,0), real m=1, real radius=2mm,
- pen outline=currentpen, pen fill=grey, Label label="") {
+ pen outline=currentpen, pen fill=grey, Label L="") {
this.lc.operator init(center=center, radius=radius, outline=outline,
- fill=fill, label=label);
+ fill=fill, L=L);
this.m = m;
}