diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-02-18 17:09:26 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-03-01 20:58:54 +0000 |
commit | f3fc87261c2f2db71ac9d63b680417836885da13 (patch) | |
tree | ac96b0dda727b5a262b664c121ae5579f9c0d645 /src/mbgl/text | |
parent | 411a562061f404fa7174222f38a1a9a13a396fd9 (diff) | |
download | qtlocation-mapboxgl-f3fc87261c2f2db71ac9d63b680417836885da13.tar.gz |
[core] Coordinate is now GeometryCoordinate
Also introduced GeometryCoordinates (vector of GeometryCoordinate
items), to better cope with GeometryCollection.
Diffstat (limited to 'src/mbgl/text')
-rw-r--r-- | src/mbgl/text/check_max_angle.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/text/check_max_angle.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/text/collision_feature.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/text/collision_feature.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/text/get_anchors.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/text/get_anchors.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/text/quads.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/text/quads.hpp | 5 |
8 files changed, 37 insertions, 28 deletions
diff --git a/src/mbgl/text/check_max_angle.cpp b/src/mbgl/text/check_max_angle.cpp index bb32e4235e..4777f66a23 100644 --- a/src/mbgl/text/check_max_angle.cpp +++ b/src/mbgl/text/check_max_angle.cpp @@ -1,4 +1,7 @@ #include <mbgl/text/check_max_angle.hpp> +#include <mbgl/geometry/anchor.hpp> +#include <mbgl/util/math.hpp> + #include <queue> namespace mbgl{ @@ -10,14 +13,14 @@ struct Corner { float angleDelta; }; -bool checkMaxAngle(const std::vector<Coordinate> &line, Anchor &anchor, const float labelLength, +bool checkMaxAngle(const GeometryCoordinates &line, Anchor &anchor, const float labelLength, const float windowSize, const float maxAngle) { // horizontal labels always pass if (anchor.segment < 0) return true; - Coordinate anchorPoint = Coordinate{ (int16_t)anchor.x, (int16_t)anchor.y }; - Coordinate &p = anchorPoint; + GeometryCoordinate anchorPoint = { (int16_t)anchor.x, (int16_t)anchor.y }; + GeometryCoordinate &p = anchorPoint; int index = anchor.segment + 1; float anchorDistance = 0; diff --git a/src/mbgl/text/check_max_angle.hpp b/src/mbgl/text/check_max_angle.hpp index 1354abe95e..0fb8a715a9 100644 --- a/src/mbgl/text/check_max_angle.hpp +++ b/src/mbgl/text/check_max_angle.hpp @@ -1,12 +1,13 @@ #ifndef MBGL_TEXT_CHECK_MAX_ANGLE #define MBGL_TEXT_CHECK_MAX_ANGLE -#include <mbgl/geometry/anchor.hpp> -#include <mbgl/util/math.hpp> +#include <mbgl/tile/geometry_tile.hpp> namespace mbgl { -bool checkMaxAngle(const std::vector<Coordinate> &line, Anchor &anchor, const float labelLength, +struct Anchor; + +bool checkMaxAngle(const GeometryCoordinates &line, Anchor &anchor, const float labelLength, const float windowSize, const float maxAngle); } // namespace mbgl diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp index 186fb39b5d..42f1119b33 100644 --- a/src/mbgl/text/collision_feature.cpp +++ b/src/mbgl/text/collision_feature.cpp @@ -3,7 +3,7 @@ namespace mbgl { -CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor, +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, const bool straight) { @@ -22,12 +22,12 @@ CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const An height = std::max(10.0f * boxScale, height); - Coordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y)); + GeometryCoordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y)); if (straight) { // used for icon labels that are aligned with the line, but don't curve along it const vec2<double> vector = util::unit(vec2<double>(line[anchor.segment + 1] - line[anchor.segment])) * length; - const std::vector<Coordinate> newLine({ anchorPoint - vector, anchorPoint + vector }); + const GeometryCoordinates newLine({ anchorPoint - vector, anchorPoint + vector }); bboxifyLabel(newLine, anchorPoint, 0, length, height); } else { // used for text labels that curve along a line @@ -38,8 +38,8 @@ CollisionFeature::CollisionFeature(const std::vector<Coordinate> &line, const An } } -void CollisionFeature::bboxifyLabel(const std::vector<Coordinate> &line, - Coordinate &anchorPoint, const int segment, const float labelLength, const float boxSize) { +void CollisionFeature::bboxifyLabel(const GeometryCoordinates &line, + GeometryCoordinate &anchorPoint, const int segment, const float labelLength, const float boxSize) { const float step = boxSize / 2; const unsigned int nBoxes = std::floor(labelLength / step); @@ -48,7 +48,7 @@ void CollisionFeature::bboxifyLabel(const std::vector<Coordinate> &line, // box is at the edge of the label. const float firstBoxOffset = -boxSize / 2; - Coordinate &p = anchorPoint; + GeometryCoordinate &p = anchorPoint; int index = segment + 1; float anchorDistance = firstBoxOffset; diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp index a9d227de1b..fcfb8e9ae9 100644 --- a/src/mbgl/text/collision_feature.hpp +++ b/src/mbgl/text/collision_feature.hpp @@ -4,6 +4,8 @@ #include <mbgl/util/vec.hpp> #include <mbgl/geometry/anchor.hpp> #include <mbgl/text/shaping.hpp> +#include <mbgl/tile/geometry_tile.hpp> + #include <vector> namespace mbgl { @@ -32,7 +34,7 @@ namespace mbgl { class CollisionFeature { public: // for text - inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor, + inline explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor, const Shaping &shapedText, const float boxScale, const float padding, const bool alongLine) : CollisionFeature(line, anchor, @@ -40,14 +42,14 @@ namespace mbgl { boxScale, padding, alongLine, false) {} // for icons - inline explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor, + inline explicit CollisionFeature(const GeometryCoordinates &line, const Anchor &anchor, const PositionedIcon &shapedIcon, const float boxScale, const float padding, const bool alongLine) : CollisionFeature(line, anchor, shapedIcon.top, shapedIcon.bottom, shapedIcon.left, shapedIcon.right, boxScale, padding, alongLine, true) {} - explicit CollisionFeature(const std::vector<Coordinate> &line, const Anchor &anchor, + 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 bool straight); @@ -55,7 +57,7 @@ namespace mbgl { std::vector<CollisionBox> boxes; private: - void bboxifyLabel(const std::vector<Coordinate> &line, Coordinate &anchorPoint, const int segment, const float length, const float height); + void bboxifyLabel(const GeometryCoordinates &line, GeometryCoordinate &anchorPoint, const int segment, const float length, const float height); }; } // namespace mbgl diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp index 7a129d692c..740ec288b3 100644 --- a/src/mbgl/text/get_anchors.cpp +++ b/src/mbgl/text/get_anchors.cpp @@ -7,7 +7,7 @@ namespace mbgl { -Anchors resample(const std::vector<Coordinate> &line, const float offset, const float spacing, +Anchors resample(const GeometryCoordinates &line, const float offset, const float spacing, const float angleWindowSize, const float maxAngle, const float labelLength, const bool continuedLine, const bool placeAtMiddle) { const float halfLabelLength = labelLength / 2.0f; @@ -23,8 +23,8 @@ Anchors resample(const std::vector<Coordinate> &line, const float offset, const int i = 0; for (auto it = line.begin(), end = line.end() - 1; it != end; it++, i++) { - const Coordinate &a = *(it); - const Coordinate &b = *(it + 1); + const GeometryCoordinate &a = *(it); + const GeometryCoordinate &b = *(it + 1); const float segmentDist = util::dist<float>(a, b); const float angle = util::angle_to(b, a); @@ -65,7 +65,7 @@ Anchors resample(const std::vector<Coordinate> &line, const float offset, const return anchors; } -Anchors getAnchors(const std::vector<Coordinate> &line, float spacing, +Anchors getAnchors(const GeometryCoordinates &line, float spacing, const float maxAngle, const float textLeft, const float textRight, const float iconLeft, const float iconRight, const float glyphSize, const float boxScale, const float overscaling) { diff --git a/src/mbgl/text/get_anchors.hpp b/src/mbgl/text/get_anchors.hpp index fcb0578d5b..1f76685f9a 100644 --- a/src/mbgl/text/get_anchors.hpp +++ b/src/mbgl/text/get_anchors.hpp @@ -2,11 +2,12 @@ #define MBGL_TEXT_GETANCHORS #include <mbgl/geometry/anchor.hpp> +#include <mbgl/tile/geometry_tile.hpp> #include <mbgl/util/math.hpp> namespace mbgl { -Anchors getAnchors(const std::vector<Coordinate> &line, float spacing, +Anchors getAnchors(const GeometryCoordinates &line, float spacing, const float maxAngle, const float textLeft, const float textRight, const float iconLeft, const float iconRight, const float glyphSize, const float boxScale, const float overscaling); diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 1950f41fc7..2117538232 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -1,5 +1,6 @@ #include <mbgl/text/quads.hpp> #include <mbgl/text/shaping.hpp> +#include <mbgl/tile/geometry_tile.hpp> #include <mbgl/geometry/anchor.hpp> #include <mbgl/layer/symbol_layer.hpp> #include <mbgl/util/math.hpp> @@ -11,7 +12,7 @@ namespace mbgl { const float globalMinScale = 0.5f; // underscale by 1 zoom level SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, - const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout, + const GeometryCoordinates& line, const SymbolLayoutProperties& layout, const bool alongLine) { auto image = *(shapedIcon.image); @@ -30,10 +31,10 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, float angle = layout.icon.rotate * util::DEG2RAD; if (alongLine) { assert(static_cast<unsigned int>(anchor.segment) < line.size()); - const Coordinate &prev= line[anchor.segment]; + const GeometryCoordinate &prev= line[anchor.segment]; if (anchor.y == prev.y && anchor.x == prev.x && static_cast<unsigned int>(anchor.segment + 1) < line.size()) { - const Coordinate &next= line[anchor.segment + 1]; + const GeometryCoordinate &next= line[anchor.segment + 1]; angle += std::atan2(anchor.y - next.y, anchor.x - next.x) + M_PI; } else { angle += std::atan2(anchor.y - prev.y, anchor.x - prev.x); @@ -74,7 +75,7 @@ struct GlyphInstance { typedef std::vector<GlyphInstance> GlyphInstances; void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &anchor, - float offset, const std::vector<Coordinate> &line, int segment, bool forward) { + float offset, const GeometryCoordinates &line, int segment, bool forward) { const bool upsideDown = !forward; @@ -132,7 +133,7 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor & } SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, - const float boxScale, const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout, + const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout, const bool alongLine, const GlyphPositions& face) { const float textRotate = layout.text.rotate * util::DEG2RAD; diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp index cdf7c23627..12b8893503 100644 --- a/src/mbgl/text/quads.hpp +++ b/src/mbgl/text/quads.hpp @@ -2,6 +2,7 @@ #define MBGL_TEXT_QUADS #include <mbgl/text/glyph.hpp> +#include <mbgl/tile/geometry_tile.hpp> #include <mbgl/util/vec.hpp> #include <vector> @@ -37,11 +38,11 @@ namespace mbgl { class PositionedIcon; SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, - const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout, + const GeometryCoordinates& line, const SymbolLayoutProperties& layout, const bool alongLine); SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, - const float boxScale, const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout, + const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout, const bool alongLine, const GlyphPositions& face); } // namespace mbgl |