summaryrefslogtreecommitdiff
path: root/src/mbgl/layout/symbol_projection.hpp
blob: e04f8908b621ecde42f844be27b4ab5196aea72a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once

#include <mbgl/util/mat4.hpp>
#include <mbgl/gfx/vertex_buffer.hpp>
#include <mbgl/programs/symbol_program.hpp>

namespace mbgl {

    class TransformState;
    class RenderTile;
    class SymbolSizeBinder;
    class PlacedSymbol;
    namespace style {
        class SymbolPropertyValues;
    } // end namespace style
    
    struct TileDistance {
        TileDistance(float prevTileDistance_, float lastSegmentViewportDistance_)
            : prevTileDistance(prevTileDistance_), lastSegmentViewportDistance(lastSegmentViewportDistance_)
        {}
        float prevTileDistance;
        float lastSegmentViewportDistance;
    };
    
    struct PlacedGlyph {
        PlacedGlyph() = default;

        PlacedGlyph(Point<float> point_, float angle_, optional<TileDistance> tileDistance_)
            : point(point_), angle(angle_), tileDistance(std::move(tileDistance_))
        {}
        PlacedGlyph(PlacedGlyph&& other) noexcept
            : point(other.point), angle(other.angle), tileDistance(std::move(other.tileDistance)) {}
        PlacedGlyph(const PlacedGlyph& other)
            : point(other.point), angle(other.angle), tileDistance(other.tileDistance) {}
        Point<float> point;
        float angle;
        optional<TileDistance> tileDistance;
    };

    float evaluateSizeForFeature(const ZoomEvaluatedSize& zoomEvaluatedSize, const PlacedSymbol& placedSymbol);
    mat4 getLabelPlaneMatrix(const mat4& posMatrix,
                             bool pitchWithMap,
                             bool rotateWithMap,
                             const TransformState& state,
                             float pixelsToTileUnits);
    mat4 getGlCoordMatrix(const mat4& posMatrix,
                          bool pitchWithMap,
                          bool rotateWithMap,
                          const TransformState& state,
                          float pixelsToTileUnits);

    using PointAndCameraDistance = std::pair<Point<float>,float>;
    PointAndCameraDistance project(const Point<float>& point, const mat4& matrix);

    void reprojectLineLabels(gfx::VertexVector<gfx::Vertex<SymbolDynamicLayoutAttributes>>&, const std::vector<PlacedSymbol>&,
            const mat4& posMatrix, bool pitchWithMap, bool rotateWithMap, bool keepUpright,
            const RenderTile&, const SymbolSizeBinder& sizeBinder, const TransformState&);

    optional<std::pair<PlacedGlyph, PlacedGlyph>> placeFirstAndLastGlyph(float fontScale,
                                                                         float lineOffsetX,
                                                                         float lineOffsetY,
                                                                         bool flip,
                                                                         const Point<float>& anchorPoint,
                                                                         const Point<float>& tileAnchorPoint,
                                                                         const PlacedSymbol& symbol,
                                                                         const mat4& labelPlaneMatrix,
                                                                         bool returnTileDistance);

    void hideGlyphs(std::size_t numGlyphs,
                    gfx::VertexVector<gfx::Vertex<SymbolDynamicLayoutAttributes>>& dynamicVertexArray);
    void addDynamicAttributes(const Point<float>& anchorPoint,
                              float angle,
                              gfx::VertexVector<gfx::Vertex<SymbolDynamicLayoutAttributes>>& dynamicVertexArray);

} // end namespace mbgl