Skip to content

Instantly share code, notes, and snippets.

@Zeta611
Last active May 31, 2020 08:04
Show Gist options
  • Save Zeta611/48be3e9cfd29d73b574418dc7c19c973 to your computer and use it in GitHub Desktop.
Save Zeta611/48be3e9cfd29d73b574418dc7c19c973 to your computer and use it in GitHub Desktop.
[pathLabel] Add a label to a path
void pathLabel(
picture pic=currentpicture,
Label l,
path g,
real position=0.5,
align align=NoAlign,
bool sloped=false,
pen p=currentpen,
filltype filltype=NoFill
) {
Label l2 = Label(l, align, p, filltype, position=Relative(position));
if (sloped) {
pair direction = dir(g, reltime(g, position));
real angle = degrees(atan2(direction.y, direction.x));
l2 = rotate(angle) * l2;
}
label(pic, l2, g);
}
// Examples
// pathlabel("BeginPoint", p, position=0);
// pathlabel("Relative(0.25)", p, position=0.25);
// pathlabel("MidPoint", p, position=0.5, align=Relative(W), sloped=true);
// pathlabel("EndPoint", p, align=Relative(E), position=1.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment