[core] change bool *AlongLine to SymbolPlacementType

This commit is contained in:
Konstantin Käfer
2016-09-06 16:11:29 +02:00
parent 1845919c25
commit f3191dbbb4
7 changed files with 69 additions and 54 deletions

View File

@@ -36,8 +36,8 @@ using namespace style;
SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
const Shaping& shapedText, const PositionedIcon& shapedIcon,
const SymbolLayoutProperties& layout, const bool addToBuffers, const uint32_t index_,
const float textBoxScale, const float textPadding, const float textAlongLine,
const float iconBoxScale, const float iconPadding, const float iconAlongLine,
const float textBoxScale, const float textPadding, const SymbolPlacementType textPlacement,
const float iconBoxScale, const float iconPadding, const SymbolPlacementType iconPlacement,
const GlyphPositions& face, const IndexedSubfeature& indexedFeature) :
point(anchor.point),
index(index_),
@@ -46,17 +46,17 @@ SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
// Create the quads used for rendering the glyphs.
glyphQuads(addToBuffers && shapedText ?
getGlyphQuads(anchor, shapedText, textBoxScale, line, layout, textAlongLine, face) :
getGlyphQuads(anchor, shapedText, textBoxScale, line, layout, textPlacement, face) :
SymbolQuads()),
// Create the quad used for rendering the icon.
iconQuads(addToBuffers && shapedIcon ?
getIconQuads(anchor, shapedIcon, line, layout, iconAlongLine, shapedText) :
getIconQuads(anchor, shapedIcon, line, layout, iconPlacement, shapedText) :
SymbolQuads()),
// Create the collision features that will be used to check whether this symbol instance can be placed
textCollisionFeature(line, anchor, shapedText, textBoxScale, textPadding, textAlongLine, indexedFeature),
iconCollisionFeature(line, anchor, shapedIcon, iconBoxScale, iconPadding, iconAlongLine, indexedFeature)
textCollisionFeature(line, anchor, shapedText, textBoxScale, textPadding, textPlacement, indexedFeature),
iconCollisionFeature(line, anchor, shapedIcon, iconBoxScale, iconPadding, iconPlacement, indexedFeature)
{}
@@ -313,12 +313,12 @@ void SymbolBucket::addFeature(const GeometryCollection &lines,
const float textPadding = layout.textPadding * tilePixelRatio;
const float iconPadding = layout.iconPadding * tilePixelRatio;
const float textMaxAngle = layout.textMaxAngle * util::DEG2RAD;
const bool textAlongLine =
layout.textRotationAlignment == AlignmentType::Map &&
layout.symbolPlacement == SymbolPlacementType::Line;
const bool iconAlongLine =
layout.iconRotationAlignment == AlignmentType::Map &&
layout.symbolPlacement == SymbolPlacementType::Line;
const SymbolPlacementType textPlacement = layout.textRotationAlignment != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
const SymbolPlacementType iconPlacement = layout.iconRotationAlignment != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
const bool mayOverlap = layout.textAllowOverlap || layout.iconAllowOverlap ||
layout.textIgnorePlacement || layout.iconIgnorePlacement;
const bool isLine = layout.symbolPlacement == SymbolPlacementType::Line;
@@ -364,8 +364,8 @@ void SymbolBucket::addFeature(const GeometryCollection &lines,
const bool addToBuffers = (mode == MapMode::Still) || inside || (mayOverlap && false);
symbolInstances.emplace_back(anchor, line, shapedText, shapedIcon, layout, addToBuffers, symbolInstances.size(),
textBoxScale, textPadding, textAlongLine,
iconBoxScale, iconPadding, iconAlongLine,
textBoxScale, textPadding, textPlacement,
iconBoxScale, iconPadding, iconPlacement,
face, indexedFeature);
}
}
@@ -393,12 +393,12 @@ void SymbolBucket::placeFeatures(CollisionTile& collisionTile) {
// Calculate which labels can be shown and when they can be shown and
// create the bufers used for rendering.
const bool textAlongLine =
layout.textRotationAlignment == AlignmentType::Map &&
layout.symbolPlacement == SymbolPlacementType::Line;
const bool iconAlongLine =
layout.iconRotationAlignment == AlignmentType::Map &&
layout.symbolPlacement == SymbolPlacementType::Line;
const SymbolPlacementType textPlacement = layout.textRotationAlignment != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
const SymbolPlacementType iconPlacement = layout.iconRotationAlignment != AlignmentType::Map
? SymbolPlacementType::Point
: layout.symbolPlacement;
const bool mayOverlap = layout.textAllowOverlap || layout.iconAllowOverlap ||
layout.textIgnorePlacement || layout.iconIgnorePlacement;
@@ -458,7 +458,7 @@ void SymbolBucket::placeFeatures(CollisionTile& collisionTile) {
if (glyphScale < collisionTile.maxScale) {
addSymbols<SymbolRenderData::TextBuffer, TextElementGroup>(
renderDataInProgress->text, symbolInstance.glyphQuads, glyphScale,
layout.textKeepUpright, textAlongLine, collisionTile.config.angle);
layout.textKeepUpright, textPlacement, collisionTile.config.angle);
}
}
@@ -467,7 +467,7 @@ void SymbolBucket::placeFeatures(CollisionTile& collisionTile) {
if (iconScale < collisionTile.maxScale) {
addSymbols<SymbolRenderData::IconBuffer, IconElementGroup>(
renderDataInProgress->icon, symbolInstance.iconQuads, iconScale,
layout.iconKeepUpright, iconAlongLine, collisionTile.config.angle);
layout.iconKeepUpright, iconPlacement, collisionTile.config.angle);
}
}
}
@@ -478,7 +478,7 @@ void SymbolBucket::placeFeatures(CollisionTile& collisionTile) {
}
template <typename Buffer, typename GroupType>
void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const bool alongLine, const float placementAngle) {
void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle) {
const float placementZoom = ::fmax(std::log(scale) / std::log(2) + zoom, 0);
@@ -496,8 +496,10 @@ void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
// drop upside down versions of glyphs
const float a = std::fmod(symbol.anchorAngle + placementAngle + M_PI, M_PI * 2);
if (keepUpright && alongLine && (a <= M_PI / 2 || a > M_PI * 3 / 2)) continue;
if (keepUpright && placement == style::SymbolPlacementType::Line &&
(a <= M_PI / 2 || a > M_PI * 3 / 2)) {
continue;
}
if (maxZoom <= minZoom)
continue;

View File

@@ -47,8 +47,8 @@ class SymbolInstance {
explicit SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
const Shaping& shapedText, const PositionedIcon& shapedIcon,
const style::SymbolLayoutProperties&, const bool inside, const uint32_t index,
const float textBoxScale, const float textPadding, const float textAlongLine,
const float iconBoxScale, const float iconPadding, const float iconAlongLine,
const float textBoxScale, const float textPadding, style::SymbolPlacementType textPlacement,
const float iconBoxScale, const float iconPadding, style::SymbolPlacementType iconPlacement,
const GlyphPositions& face, const IndexedSubfeature& indexedfeature);
Point<float> point;
uint32_t index;
@@ -106,7 +106,7 @@ private:
// Adds placed items to the buffer.
template <typename Buffer, typename GroupType>
void addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale,
const bool keepUpright, const bool alongLine, const float placementAngle);
const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle);
public:
style::SymbolLayoutProperties layout;

View File

@@ -5,7 +5,7 @@ namespace mbgl {
CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const float top, const float bottom, const float left, const float right,
const float boxScale, const float padding, const bool alongLine, IndexedSubfeature indexedFeature_,
const float boxScale, const float padding, const style::SymbolPlacementType placement, IndexedSubfeature indexedFeature_,
const bool straight)
: indexedFeature(std::move(indexedFeature_)) {
@@ -16,7 +16,7 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor
const float x1 = left * boxScale - padding;
const float x2 = right * boxScale + padding;
if (alongLine) {
if (placement == style::SymbolPlacementType::Line) {
float height = y2 - y1;
const double length = x2 - x1;

View File

@@ -35,22 +35,22 @@ namespace mbgl {
// for text
explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const Shaping &shapedText,
const float boxScale, const float padding, const bool alongLine, const IndexedSubfeature& indexedFeature_)
const float boxScale, const float padding, const style::SymbolPlacementType placement, const IndexedSubfeature& indexedFeature_)
: CollisionFeature(line, anchor,
shapedText.top, shapedText.bottom, shapedText.left, shapedText.right,
boxScale, padding, alongLine, indexedFeature_, false) {}
boxScale, padding, placement, indexedFeature_, false) {}
// for icons
explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const PositionedIcon &shapedIcon,
const float boxScale, const float padding, const bool alongLine, const IndexedSubfeature& indexedFeature_)
const float boxScale, const float padding, const style::SymbolPlacementType placement, const IndexedSubfeature& indexedFeature_)
: CollisionFeature(line, anchor,
shapedIcon.top, shapedIcon.bottom, shapedIcon.left, shapedIcon.right,
boxScale, padding, alongLine, indexedFeature_, true) {}
boxScale, padding, placement, indexedFeature_, true) {}
explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor,
const float top, const float bottom, const float left, const float right,
const float boxScale, const float padding, const bool alongLine,
const float boxScale, const float padding, const style::SymbolPlacementType placement,
IndexedSubfeature, const bool straight);

View File

@@ -15,7 +15,7 @@ const float globalMinScale = 0.5f; // underscale by 1 zoom level
SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
const GeometryCoordinates& line, const SymbolLayoutProperties& layout,
const bool alongLine, const Shaping& shapedText) {
const style::SymbolPlacementType placement, const Shaping& shapedText) {
auto image = *(shapedIcon.image);
@@ -63,7 +63,7 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
}
float angle = layout.iconRotate * util::DEG2RAD;
if (alongLine) {
if (placement == style::SymbolPlacementType::Line) {
assert(static_cast<unsigned int>(anchor.segment) < line.size());
const GeometryCoordinate &prev= line[anchor.segment];
if (anchor.point.y == prev.y && anchor.point.x == prev.x &&
@@ -166,7 +166,7 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &
SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout,
const bool alongLine, const GlyphPositions& face) {
const style::SymbolPlacementType placement, const GlyphPositions& face) {
const float textRotate = layout.textRotate * util::DEG2RAD;
const bool keepUpright = layout.textKeepUpright;
@@ -189,7 +189,7 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
const float centerX = (positionedGlyph.x + glyph.metrics.advance / 2.0f) * boxScale;
GlyphInstances glyphInstances;
if (alongLine) {
if (placement == style::SymbolPlacementType::Line) {
getSegmentGlyphs(std::back_inserter(glyphInstances), anchor, centerX, line, anchor.segment, true);
if (keepUpright)
getSegmentGlyphs(std::back_inserter(glyphInstances), anchor, centerX, line, anchor.segment, false);

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/text/glyph.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <vector>
@@ -40,10 +41,10 @@ typedef std::vector<SymbolQuad> SymbolQuads;
SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
const GeometryCoordinates& line, const style::SymbolLayoutProperties&,
const bool alongLine, const Shaping& shapedText);
style::SymbolPlacementType placement, const Shaping& shapedText);
SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
const float boxScale, const GeometryCoordinates& line, const style::SymbolLayoutProperties&,
const bool alongLine, const GlyphPositions& face);
style::SymbolPlacementType placement, const GlyphPositions& face);
} // namespace mbgl

View File

@@ -21,8 +21,9 @@ TEST(getIconQuads, normal) {
GeometryCoordinates line;
Shaping shapedText;
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads.size(), 1u);
ASSERT_EQ(quads[0].anchorPoint.x, 2);
ASSERT_EQ(quads[0].anchorPoint.y, 3);
@@ -58,7 +59,8 @@ TEST(getIconQuads, style) {
// none
{
SymbolLayoutProperties layout;
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads.size(), 1u);
ASSERT_EQ(quads[0].anchorPoint.x, 0);
@@ -81,7 +83,8 @@ TEST(getIconQuads, style) {
SymbolLayoutProperties layout;
layout.textSize = LayoutProperty<float>(24.0f);
layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -60);
ASSERT_EQ(quads[0].tl.y, 0);
@@ -98,7 +101,8 @@ TEST(getIconQuads, style) {
SymbolLayoutProperties layout;
layout.textSize = LayoutProperty<float>(12.0f);
layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -5);
@@ -119,7 +123,8 @@ TEST(getIconQuads, style) {
layout.iconTextFitPadding.value[1] = 10.0f;
layout.iconTextFitPadding.value[2] = 5.0f;
layout.iconTextFitPadding.value[3] = 10.0f;
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -40);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -136,7 +141,8 @@ TEST(getIconQuads, style) {
SymbolLayoutProperties layout;
layout.textSize = LayoutProperty<float>(24.0f);
layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -153,7 +159,8 @@ TEST(getIconQuads, style) {
SymbolLayoutProperties layout;
layout.textSize = LayoutProperty<float>(12.0f);
layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -20);
ASSERT_EQ(quads[0].tl.y, -5);
@@ -174,7 +181,8 @@ TEST(getIconQuads, style) {
layout.iconTextFitPadding.value[1] = 10.0f;
layout.iconTextFitPadding.value[2] = 5.0f;
layout.iconTextFitPadding.value[3] = 10.0f;
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -191,7 +199,8 @@ TEST(getIconQuads, style) {
SymbolLayoutProperties layout;
layout.textSize = LayoutProperty<float>(24.0f);
layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -60);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -208,7 +217,8 @@ TEST(getIconQuads, style) {
SymbolLayoutProperties layout;
layout.textSize = LayoutProperty<float>(12.0f);
layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -30);
ASSERT_EQ(quads[0].tl.y, -5);
@@ -229,7 +239,8 @@ TEST(getIconQuads, style) {
layout.iconTextFitPadding.value[1] = 10.0f;
layout.iconTextFitPadding.value[2] = 5.0f;
layout.iconTextFitPadding.value[3] = 10.0f;
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -40);
ASSERT_EQ(quads[0].tl.y, -10);
@@ -250,7 +261,8 @@ TEST(getIconQuads, style) {
layout.iconTextFitPadding.value[1] = 5.0f;
layout.iconTextFitPadding.value[2] = 10.0f;
layout.iconTextFitPadding.value[3] = 15.0f;
SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layout, false, shapedText);
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
ASSERT_EQ(quads[0].tl.x, -45);
ASSERT_EQ(quads[0].tl.y, -5);