Last active
May 31, 2020 08:04
-
-
Save Zeta611/48be3e9cfd29d73b574418dc7c19c973 to your computer and use it in GitHub Desktop.
[pathLabel] Add a label to a path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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