Skip to content

Orient line labels based on the relative position of their first and last glyphs - #4853

Merged
ChrisLoer merged 2 commits into
masterfrom
cloer_upright_labels
Jun 23, 2017
Merged

ChrisLoer merged 2 commits into
masterfrom
cloer_upright_labels

Conversation

@ChrisLoer

Copy link
Copy Markdown
Contributor

Fixes #4825

Before:

image

After:
screenshot 2017-06-19 14 15 47

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

…last glyph, instead of the orientation of their central glyph.
@ChrisLoer
ChrisLoer requested a review from ansis June 19, 2017 21:29

@ansis ansis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ChrisLoer
ChrisLoer force-pushed the cloer_upright_labels branch from a82f9aa to 672b3d7 Compare June 23, 2017 05:11
@ChrisLoer
ChrisLoer force-pushed the cloer_upright_labels branch from 672b3d7 to 73540d2 Compare June 23, 2017 05:17
@ChrisLoer

Copy link
Copy Markdown
Contributor Author

@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).

@ansis

ansis commented Jun 23, 2017

Copy link
Copy Markdown
Contributor

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants