Skip to content

Detailing the prevention of non-deterministic labels - #1588

Merged
devemux86 merged 2 commits into
mapsforge:masterfrom
Sublimis:labels05-1
Dec 10, 2024
Merged

devemux86 merged 2 commits into
mapsforge:masterfrom
Sublimis:labels05-1

Conversation

@Sublimis

@Sublimis Sublimis commented Dec 9, 2024

Copy link
Copy Markdown
Contributor
  1. Improve DirectRenderer, i.e. make labels that are rendered directly on tiles (when using MapDataStoreLabelStore) deterministic with this one change: Omit drawing labels that span multiple tiles and clash with labels of similar priority.
  2. Improve labels/symbols clash detection (using clash rectangles, not just absolute boundary).
  3. Improve invisible labels/symbols handling (remove them before processing the rest).
  4. CanvasRasterer.renderContext reference (it's natural, because CanvasRasterer only lives inside RenderContext).
  5. Improve RenderContext fields encapsulation.
  6. Tests for LayerUtil.collisionAndContestingFreeOrdered() and LayerUtil.collisionFreeOrdered().

After implementing points 1. and 2., not a single label tear was observed when using the DirectRenderer method. It seems that the problem with non-deterministic labels has finally been completely solved. Yay!

Note that point 1. didn't change the way the current implementation of DatabaseRenderer handles tile-rendered labels when using TileBasedLabelStore.

We hope you don't mind points 4. and 5. It would be a pity to revert them because they make the code more future-proof and OOP-compliant (and less error-prone).

*/
public DatabaseRenderer(MapDataStore mapDataStore, GraphicFactory graphicFactory, TileCache tileCache,
TileBasedLabelStore labelStore, boolean renderLabels, boolean cacheLabels,
LabelStore labelStore, boolean renderLabels, boolean cacheLabels,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Sublimis Why is this change?
As it is always a TileBasedLabelStore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not always -- even in the current master it can be null. DatabaseRenderer does not depend on this being a TileBasedLabelStore. Current implementation of processLabels() also does not depend on a particular LabelStore implementation, it only assumes there's a LabelStore that contains some labels, nothing more. It can even run with labelStore == null.

And now that DirectRenderer extends DatabaseRenderer in this PR, LabelStore implementation can also be MapDataStoreLabelStore, so it feels natural to generalize things. If this is really something you want to avoid we can for example create a new interface extending LabelStore that would define the TileBasedLabelStore.storeMapItems(). Otherwise too much code would get duplicated in DirectRenderer (there would be no point in extending DatabaseRenderer if it can only work with TileBasedLabelStore).


public final double horizontalOffset;
public final boolean isVisible;
public final boolean isNotVisible;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Sublimis isVisible is more understandable and already used. Why change it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two reasons: 1) isVisible() was only ever used in negation, cluttering the code, 2) isVisible() returning true doesn't really mean much, and can be misleading, because it does not mean the item is visible like the name implies. Like the javadoc of the superclass method isNotVisible() says: "@return {@code true} if this is definitely not visible; {@code false} if it may or may not be visible"

private List<List<ShapePaintContainer>> drawingLayers;
public final List<MapElementContainer> labels;
public final List<List<List<ShapePaintContainer>>> ways;
private List<List<ShapePaintContainer>> drawingLayer;

@devemux86 devemux86 Dec 9, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Sublimis Why change to singular?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

First dimension of the three-dimensional ways field is the layers dimension, then levels, and then ShapePaintContainer-s, isn't that so? See the code:

for (int layer = 0, layers = this.ways.size(); layer < layers; ++layer) {
List<List<ShapePaintContainer>> shapePaintContainers = this.ways.get(layer);
for (int level = 0; level < levelsPerLayer; ++level) {
List<ShapePaintContainer> wayList = shapePaintContainers.get(level);
for (int index = wayList.size() - 1; index >= 0; --index) {
canvasRasterer.drawShapePaintContainer(wayList.get(index));
}
}
}

And when one picks an element from the list of layers, it becomes just a single layer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In fact this is also a typo, it should also be singular

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In fact this is also a typo, it should also be singular

@Sublimis Then we should also change this.

@Sublimis

Sublimis commented Dec 9, 2024

Copy link
Copy Markdown
Contributor Author

By the end of the week we'll also push the latest hill shading improvements, and that should be all from us for the foreseeable future 🙂

@Sublimis
Sublimis marked this pull request as draft December 9, 2024 18:08
@Sublimis
Sublimis marked this pull request as ready for review December 9, 2024 18:13
@devemux86 devemux86 added this to the 0.23.0 milestone Dec 10, 2024
@devemux86
devemux86 merged commit 326d67b into mapsforge:master Dec 10, 2024
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants