Repository navigation
Orient line labels based on the relative position of their first and last glyphs - #4853
Conversation
…last glyph, instead of the orientation of their central glyph.
There was a problem hiding this comment.
Looks good to me!
I'm wondering if it would be cleaner to handle the flip case with a second call to placeGlyphsAlongLine.
if (!placeGlyphsAlongLine(..., false /* don't flip*/, ...)) {
if (!placeGlyphsAlongLine(..., true /* flip */, ...)) {
hideGlyphs(...);
}
}This might allow placeFirstAndLastGlyphAlongLine to be inlined avoid the need for the firstAndLastGlyph object and the long function calls.
I think the current approach is fine though and good to merge if you think so.
a82f9aa to
672b3d7
Compare
672b3d7 to
73540d2
Compare
|
@ansis that sounds like a good idea, what do you think of the new flipping approach I tried? Instead of just returning a boolean I return two bits, so that we can still exit early in the case the glyphs don't fit on the line unflipped (it is possible they would fit if we flipped them, but the vast majority of the time they won't so we might as well save the extra work). |
|
Looks good! |
Fixes #4825
Before:
After:

This turned out to add a little more complexity to the code than I would have liked, but it shouldn't have too much of a performance impact. Because we have to project the first and last glyph to find out whether to do the flip, there's some extra work in the case that we flip (because we have to reproject the first and last glyph once they're flipped). On the other hand, there's a small savings here in that when there's not enough room on a line for a label, we exit earlier because we test the beginning and end before projecting all the glyphs in the middle.
/cc @ansis @nickidlugash