Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix icon-fit with variable label placement #8755

Merged
merged 11 commits into from Sep 20, 2019
Merged

Fix icon-fit with variable label placement #8755

merged 11 commits into from Sep 20, 2019

Conversation

arindam1993
Copy link
Contributor

@arindam1993 arindam1993 commented Sep 14, 2019

This is an attempt to isolate and cherry pick just the fix required for #8583 from #8737 .
The issue seems to be caused by the fact that draw_symbol.js:#updateVariableAnchors applies an offset to the text glyphs , but never touches the icon buffer at all.

This PR adds an attribute to the placedSymbol buffers, called associatedSymbolIndex, this lets the text placedSymbol instances know which icon they're associated with.
So at render time the offsets can be applied in both buffers.
It also moves the offset calculation out of the paint loop, since icons and text need to share the same data.

This still leaves out making icon-text-fit update the collision box (#8722) and making it work with vertical labels.

UPDATE:
demo, 1 frame desynch fixed
2019-09-17 13 41 22

Added a render test
Before (on master):
actual

After:
expected

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
  • tagged @mapbox/studio and/or @mapbox/maps-design if this PR includes style spec changes
  • tagged @mapbox/gl-native if this PR includes shader changes or needs a native port

@arindam1993 arindam1993 changed the title [dnm] Attempting to fix icon-fit with variable label placement Attempting to fix icon-fit with variable label placement Sep 17, 2019
@arindam1993 arindam1993 marked this pull request as ready for review September 17, 2019 20:42
@arindam1993 arindam1993 changed the title Attempting to fix icon-fit with variable label placement Fix icon-fit with variable label placement Sep 17, 2019
debug/8583.html Outdated
@@ -0,0 +1,133 @@
<!DOCTYPE html>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to commit this file? It would be more useful for the next developer if it was named more appropriately.

@arindam1993 arindam1993 added this to the release-ristretto milestone Sep 17, 2019
Copy link

@vakila vakila left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding the render test @arindam1993 , both that & the debug page (on Linux Firefox/Chrome) look good 💚

One question below, and relatedly: do we need tests that this works also when combined with multi-line and/or vertical labels?

Some of those (currently ignored) tests are failing, for example text-writing-mode/point_label/mixed-multiline-vertical-horizontal-mode-icon-text-fit, and the failure doesn't look to me like it has to do with the 1px issue addressed in #8741. Thoughts?

updateVariableAnchors(bucket, rotateWithMap, pitchWithMap, variableOffsets, symbolSize,
tr, labelPlaneMatrix, coord.posMatrix, tileScale, size);
} else if (isText && size && bucket.allowVerticalPlacement) {
} else if (isText && size && bucket.allowVerticalPlacement && !variablePlacement) {
Copy link

Choose a reason for hiding this comment

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

Perhaps I'm missing something but why the && !variablePlacement here? IIRC we can have both vertical & variable placement enabled at the same time, are we accounting for that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we're not. In the interest of time time this PR only handles icon-text-fit rendering for horizontal variable anchor labels.

Copy link

Choose a reason for hiding this comment

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

👌 Maybe we should ticket that out

const variablePlacement = layer.layout.get('text-variable-anchor');

//Compute variable-offsets before painting since icons and text data positioning
//depend on each other in this case.
Copy link

Choose a reason for hiding this comment

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

Nice 👍

@arindam1993
Copy link
Contributor Author

LGTM! Thanks for adding the render test @arindam1993 , both that & the debug page (on Linux Firefox/Chrome) look good 💚

One question below, and relatedly: do we need tests that this works also when combined with multi-line and/or vertical labels?

Some of those (currently ignored) tests are failing, for example text-writing-mode/point_label/mixed-multiline-vertical-horizontal-mode-icon-text-fit, and the failure doesn't look to me like it has to do with the 1px issue addressed in #8741. Thoughts?

Yes, will address that and shifting of icon collision boxes in a separate PR. This was intended as a fix to the biggest visual glitch.

@vakila vakila self-requested a review September 18, 2019 00:18
Copy link

@vakila vakila left a comment

Choose a reason for hiding this comment

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

👍 since we're not attempting to resolve the combo-vertical-variable-placement issue in this PR

Copy link
Contributor

@asheemmamoowala asheemmamoowala left a comment

Choose a reason for hiding this comment

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

Just a few additional notes:

  • This PR does not change the behavior for multi-line labels - that case remains broken.
  • Works well with CJK characters
  • Needs follow up issues for fixing icon-text-fit with vertical symbols and fixing collision boxes

src/data/array_types.js Show resolved Hide resolved
const verticalTextBoxStartIndex = verticalTextCollisionFeature ? verticalTextCollisionFeature.boxStartIndex : bucket.collisionBoxArray.length;
const verticalTextBoxEndIndex = verticalTextCollisionFeature ? verticalTextCollisionFeature.boxEndIndex : bucket.collisionBoxArray.length;

//Place icon first, so text can have a reference it its index in the placed symbol array.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo in reference it its index

const size = symbolSize.evaluateSizeForZoom(sizeData, tr.zoom);

const s = pixelsToTileUnits(tile, 1, painter.transform.zoom);
const labelPlaneMatrix = symbolProjection.getLabelPlaneMatrix(coord.posMatrix, pitchWithMap, rotateWithMap, painter.transform, s);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Avoid temporary variable buffers and s

Copy link
Contributor

@kkaefer kkaefer left a comment

Choose a reason for hiding this comment

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

Is the intention to fix text-writing-mode/point_label/cjk-variable-anchors-vertical-horizontal-mode-icon-text-fit as well? Regardless of the icon-text-fit aspect, it seems like the

Here's the native version with collision boxes activated (which arguably seems wrong too):

actual

And this is the JS version in this branch:

actual

for reference, this is the JS version before this patch:

actual

It looks like there are no tests that are unignored, which means there are render test cases missing that were broken in the old behavior, but work with this patch applied. Could you please add some?

@arindam1993
Copy link
Contributor Author

Is the intention to fix text-writing-mode/point_label/cjk-variable-anchors-vertical-horizontal-mode-icon-text-fit as well? Regardless of the icon-text-fit aspect, it seems like the

Here's the native version with collision boxes activated (which arguably seems wrong too):

actual

And this is the JS version in this branch:

actual

for reference, this is the JS version before this patch:

actual

No I didn't intend to fix that, this change only ensures that the offset thats calculated and applied to text-variable-anchor at render time updateVariableAnchors gets applied to the icon quad as well, it doesnt touch placement or layout.

It looks like there are no tests that are unignored, which means there are render test cases missing that were broken in the old behavior, but work with this patch applied. Could you please add some?

I have added one(see original PR body), but its not fully representative of this fix since its doing collision. Updating so icon/text-overlap is true so collision is ignored but the probelm with un-offset icons is still surfaced.

Master:
actual
This branch:
expected

@arindam1993
Copy link
Contributor Author

@asheemmamoowala
Cleaner render tests added:
Master:
icon-text-fit/text-variable-anchor:
actual

icon-text-fit/text-variable-anchor-overlap:
actual

This branch:
icon-text-fit/text-variable-anchor:
expected

icon-text-fit/text-variable-anchor-overlap:
expected

@arindam1993
Copy link
Contributor Author

I've fixed the vertical label getting hidden issue. this is what the text-writing-mode/point_label/cjk-variable-anchors-vertical-horizontal-mode-icon-text-fit looks like now:
actual

The box sizing is still incorrect, but this PR isn't intended to fix that.

Copy link
Contributor

@kkaefer kkaefer left a comment

Choose a reason for hiding this comment

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

Thanks for looking at the vertical icons!

@kkaefer kkaefer merged commit 1dac2c8 into master Sep 20, 2019
@kkaefer kkaefer deleted the fix-8583 branch September 20, 2019 06:17
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.

None yet

5 participants