diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-03-16 17:45:00 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-05-05 11:30:53 -0700 |
commit | 9330d674a983652d248d6a43fa4adbf5970c3d30 (patch) | |
tree | bd9292fcdb14f416922197f36c7707bb52e13591 /src/mbgl/text | |
parent | f89cfacab2457602c5bd81ab9da35cede23584e2 (diff) | |
download | qtlocation-mapboxgl-9330d674a983652d248d6a43fa4adbf5970c3d30.tar.gz |
[core] Use geometry.hpp's point
Diffstat (limited to 'src/mbgl/text')
-rw-r--r-- | src/mbgl/text/check_max_angle.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/text/collision_feature.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/text/collision_feature.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/text/collision_tile.cpp | 42 | ||||
-rw-r--r-- | src/mbgl/text/collision_tile.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/text/glyph_set.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/text/glyph_set.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/text/quads.cpp | 64 | ||||
-rw-r--r-- | src/mbgl/text/quads.hpp | 11 | ||||
-rw-r--r-- | src/mbgl/text/shaping.hpp | 2 |
10 files changed, 76 insertions, 78 deletions
diff --git a/src/mbgl/text/check_max_angle.cpp b/src/mbgl/text/check_max_angle.cpp index 4777f66a23..3ef13a0dd7 100644 --- a/src/mbgl/text/check_max_angle.cpp +++ b/src/mbgl/text/check_max_angle.cpp @@ -19,7 +19,7 @@ bool checkMaxAngle(const GeometryCoordinates &line, Anchor &anchor, const float // horizontal labels always pass if (anchor.segment < 0) return true; - GeometryCoordinate anchorPoint = { (int16_t)anchor.x, (int16_t)anchor.y }; + GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point); GeometryCoordinate &p = anchorPoint; int index = anchor.segment + 1; float anchorDistance = 0; diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp index 09c04ede78..8f0f099670 100644 --- a/src/mbgl/text/collision_feature.cpp +++ b/src/mbgl/text/collision_feature.cpp @@ -17,17 +17,17 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor if (alongLine) { float height = y2 - y1; - const float length = x2 - x1; + const double length = x2 - x1; if (height <= 0.0f) return; height = std::max(10.0f * boxScale, height); - GeometryCoordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y)); + GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point); 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 GeometryCoordinate vector = convertPoint<int16_t>(util::unit(convertPoint<double>(line[anchor.segment + 1] - line[anchor.segment])) * length); const GeometryCoordinates newLine({ anchorPoint - vector, anchorPoint + vector }); bboxifyLabel(newLine, anchorPoint, 0, length, height, indexedFeature); } else { @@ -35,7 +35,7 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor bboxifyLabel(line, anchorPoint, anchor.segment, length, height, indexedFeature); } } else { - boxes.emplace_back(anchor, x1, y1, x2, y2, std::numeric_limits<float>::infinity(), indexedFeature); + boxes.emplace_back(anchor.point, x1, y1, x2, y2, std::numeric_limits<float>::infinity(), indexedFeature); } } @@ -89,7 +89,7 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates &line, const auto& p0 = line[index]; const auto& p1 = line[index + 1]; - vec2<float> boxAnchor = { + Point<float> boxAnchor = { p0.x + segmentBoxDistance / segmentLength * (p1.x - p0.x), p0.y + segmentBoxDistance / segmentLength * (p1.y - p0.y) }; diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp index 0cd0b5554c..0fe248a3de 100644 --- a/src/mbgl/text/collision_feature.hpp +++ b/src/mbgl/text/collision_feature.hpp @@ -1,7 +1,6 @@ #ifndef MBGL_TEXT_COLLISION_FEATURE #define MBGL_TEXT_COLLISION_FEATURE -#include <mbgl/util/vec.hpp> #include <mbgl/geometry/anchor.hpp> #include <mbgl/text/shaping.hpp> #include <mbgl/tile/geometry_tile.hpp> @@ -12,12 +11,12 @@ namespace mbgl { class CollisionBox { public: - explicit CollisionBox(const vec2<float> &_anchor, float _x1, float _y1, float _x2, float _y2, float _maxScale, + explicit CollisionBox(const Point<float> &_anchor, float _x1, float _y1, float _x2, float _y2, float _maxScale, const IndexedSubfeature& indexedFeature_ = { 0, "", "", 0 }) : anchor(_anchor), x1(_x1), y1(_y1), x2(_x2), y2(_y2), maxScale(_maxScale), indexedFeature(indexedFeature_) {} // the box is centered around the anchor point - vec2<float> anchor; + Point<float> anchor; // distances to the edges from the anchor float x1; diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp index 6b9240df1f..ef7e9ab850 100644 --- a/src/mbgl/text/collision_tile.cpp +++ b/src/mbgl/text/collision_tile.cpp @@ -1,6 +1,8 @@ #include <mbgl/text/collision_tile.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/util/constants.hpp> +#include <mbgl/util/math.hpp> + #include <cmath> namespace mbgl { @@ -10,13 +12,13 @@ auto infinity = std::numeric_limits<float>::infinity(); CollisionTile::CollisionTile(PlacementConfig config_) : config(config_), edges({{ // left - CollisionBox(vec2<float>(0, 0), 0, -infinity, 0, infinity, infinity), + CollisionBox(Point<float>(0, 0), 0, -infinity, 0, infinity, infinity), // right - CollisionBox(vec2<float>(util::EXTENT, 0), 0, -infinity, 0, infinity, infinity), + CollisionBox(Point<float>(util::EXTENT, 0), 0, -infinity, 0, infinity, infinity), // top - CollisionBox(vec2<float>(0, 0), -infinity, 0, infinity, 0, infinity), + CollisionBox(Point<float>(0, 0), -infinity, 0, infinity, 0, infinity), // bottom - CollisionBox(vec2<float>(0, util::EXTENT), -infinity, 0, infinity, 0, infinity), + CollisionBox(Point<float>(0, util::EXTENT), -infinity, 0, infinity, 0, infinity), }}) { tree.clear(); @@ -35,8 +37,8 @@ CollisionTile::CollisionTile(PlacementConfig config_) : config(config_), } -float CollisionTile::findPlacementScale(float minPlacementScale, const vec2<float>& anchor, - const CollisionBox& box, const vec2<float>& blockingAnchor, const CollisionBox& blocking) { +float CollisionTile::findPlacementScale(float minPlacementScale, const Point<float>& anchor, + const CollisionBox& box, const Point<float>& blockingAnchor, const CollisionBox& blocking) { // Find the lowest scale at which the two boxes can fit side by side without overlapping. @@ -80,7 +82,7 @@ float CollisionTile::placeFeature(const CollisionFeature &feature, const bool al float minPlacementScale = minScale; for (auto& box : feature.boxes) { - const auto anchor = box.anchor.matMul(rotationMatrix); + const auto anchor = util::matrixMultiply(rotationMatrix, box.anchor); if (!allowOverlap) { std::vector<CollisionTreeBox> blockingBoxes; @@ -88,7 +90,7 @@ float CollisionTile::placeFeature(const CollisionFeature &feature, const bool al for (auto& blockingTreeBox : blockingBoxes) { const auto& blocking = std::get<1>(blockingTreeBox); - auto blockingAnchor = blocking.anchor.matMul(rotationMatrix); + auto blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor); minPlacementScale = findPlacementScale(minPlacementScale, anchor, box, blockingAnchor, blocking); if (minPlacementScale >= maxScale) return minPlacementScale; @@ -96,14 +98,14 @@ float CollisionTile::placeFeature(const CollisionFeature &feature, const bool al } if (avoidEdges) { - const vec2<float> tl = { box.x1, box.y1 }; - const vec2<float> tr = { box.x2, box.y1 }; - const vec2<float> bl = { box.x1, box.y2 }; - const vec2<float> br = { box.x2, box.y2 }; - const vec2<float> rtl = tl.matMul(reverseRotationMatrix); - const vec2<float> rtr = tr.matMul(reverseRotationMatrix); - const vec2<float> rbl = bl.matMul(reverseRotationMatrix); - const vec2<float> rbr = br.matMul(reverseRotationMatrix); + const Point<float> tl = { box.x1, box.y1 }; + const Point<float> tr = { box.x2, box.y1 }; + const Point<float> bl = { box.x1, box.y2 }; + const Point<float> br = { box.x2, box.y2 }; + const Point<float> rtl = util::matrixMultiply(reverseRotationMatrix, tl); + const Point<float> rtr = util::matrixMultiply(reverseRotationMatrix, tr); + const Point<float> rbl = util::matrixMultiply(reverseRotationMatrix, bl); + const Point<float> rbr = util::matrixMultiply(reverseRotationMatrix, br); CollisionBox rotatedBox(box.anchor, ::fmin(::fmin(rtl.x, rtr.x), ::fmin(rbl.x, rbr.x)), ::fmin(::fmin(rtl.y, rtr.y), ::fmin(rbl.y, rbr.y)), @@ -130,7 +132,7 @@ void CollisionTile::insertFeature(CollisionFeature &feature, const float minPlac if (minPlacementScale < maxScale) { std::vector<CollisionTreeBox> treeBoxes; for (auto& box : feature.boxes) { - treeBoxes.emplace_back(getTreeBox(box.anchor.matMul(rotationMatrix), box), box); + treeBoxes.emplace_back(getTreeBox(util::matrixMultiply(rotationMatrix, box.anchor), box), box); } if (ignorePlacement) { ignoredTree.insert(treeBoxes.begin(), treeBoxes.end()); @@ -141,7 +143,7 @@ void CollisionTile::insertFeature(CollisionFeature &feature, const float minPlac } -Box CollisionTile::getTreeBox(const vec2<float> &anchor, const CollisionBox &box, const float scale) { +Box CollisionTile::getTreeBox(const Point<float> &anchor, const CollisionBox &box, const float scale) { return Box{ CollisionPoint{ anchor.x + box.x1 / scale, @@ -158,7 +160,7 @@ std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float m std::vector<IndexedSubfeature> result; - auto anchor = vec2<float>(minX, minY).matMul(rotationMatrix); + auto anchor = util::matrixMultiply(rotationMatrix, Point<float>(minX, minY)); CollisionBox queryBox(anchor, 0, 0, maxX - minX, maxY - minY, scale); std::vector<CollisionTreeBox> blockingBoxes; @@ -174,7 +176,7 @@ std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float m auto& seenFeatures = sourceLayerFeatures[indexedFeature.sourceLayerName]; if (seenFeatures.find(indexedFeature.index) == seenFeatures.end()) { - auto blockingAnchor = blocking.anchor.matMul(rotationMatrix); + auto blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor); float minPlacementScale = findPlacementScale(minScale, anchor, queryBox, blockingAnchor, blocking); if (minPlacementScale >= scale) { seenFeatures.insert(indexedFeature.index); diff --git a/src/mbgl/text/collision_tile.hpp b/src/mbgl/text/collision_tile.hpp index 4bc25ddcb7..df769ac203 100644 --- a/src/mbgl/text/collision_tile.hpp +++ b/src/mbgl/text/collision_tile.hpp @@ -52,9 +52,9 @@ public: private: float findPlacementScale(float minPlacementScale, - const vec2<float>& anchor, const CollisionBox& box, - const vec2<float>& blockingAnchor, const CollisionBox& blocking); - Box getTreeBox(const vec2<float>& anchor, const CollisionBox& box, const float scale = 1.0); + const Point<float>& anchor, const CollisionBox& box, + const Point<float>& blockingAnchor, const CollisionBox& blocking); + Box getTreeBox(const Point<float>& anchor, const CollisionBox& box, const float scale = 1.0); Tree tree; Tree ignoredTree; diff --git a/src/mbgl/text/glyph_set.cpp b/src/mbgl/text/glyph_set.cpp index f63c1eae7f..8bd7e4ae03 100644 --- a/src/mbgl/text/glyph_set.cpp +++ b/src/mbgl/text/glyph_set.cpp @@ -33,7 +33,7 @@ const std::map<uint32_t, SDFGlyph> &GlyphSet::getSDFs() const { const Shaping GlyphSet::getShaping(const std::u32string &string, const float maxWidth, const float lineHeight, const float horizontalAlign, const float verticalAlign, const float justify, - const float spacing, const vec2<float> &translate) const { + const float spacing, const Point<float> &translate) const { Shaping shaping(translate.x * 24, translate.y * 24, string); // the y offset *should* be part of the font metadata @@ -61,7 +61,7 @@ const Shaping GlyphSet::getShaping(const std::u32string &string, const float max void align(Shaping &shaping, const float justify, const float horizontalAlign, const float verticalAlign, const uint32_t maxLineLength, const float lineHeight, - const uint32_t line, const vec2<float> &translate) { + const uint32_t line, const Point<float> &translate) { const float shiftX = (justify - horizontalAlign) * maxLineLength + ::round(translate.x * 24/* one em */); const float shiftY = (-verticalAlign * (line + 1) + 0.5) * lineHeight + ::round(translate.y * 24/* one em */); @@ -87,7 +87,7 @@ void justifyLine(std::vector<PositionedGlyph> &positionedGlyphs, const std::map< void GlyphSet::lineWrap(Shaping &shaping, const float lineHeight, const float maxWidth, const float horizontalAlign, const float verticalAlign, - const float justify, const vec2<float> &translate) const { + const float justify, const Point<float> &translate) const { uint32_t lastSafeBreak = 0; uint32_t lengthBeforeCurrentLine = 0; diff --git a/src/mbgl/text/glyph_set.hpp b/src/mbgl/text/glyph_set.hpp index 5714071650..40f87835fd 100644 --- a/src/mbgl/text/glyph_set.hpp +++ b/src/mbgl/text/glyph_set.hpp @@ -2,7 +2,7 @@ #define MBGL_TEXT_GLYPH_SET #include <mbgl/text/glyph.hpp> -#include <mbgl/util/vec.hpp> +#include <mbgl/util/geometry.hpp> namespace mbgl { @@ -12,9 +12,9 @@ public: const std::map<uint32_t, SDFGlyph> &getSDFs() const; const Shaping getShaping(const std::u32string &string, float maxWidth, float lineHeight, float horizontalAlign, float verticalAlign, float justify, - float spacing, const vec2<float> &translate) const; + float spacing, const Point<float> &translate) const; void lineWrap(Shaping &shaping, float lineHeight, float maxWidth, float horizontalAlign, - float verticalAlign, float justify, const vec2<float> &translate) const; + float verticalAlign, float justify, const Point<float> &translate) const; private: std::map<uint32_t, SDFGlyph> sdfs; diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 2b5db023c0..f78d913e74 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -22,22 +22,22 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, auto right = left + image.pos.w / image.relativePixelRatio; auto top = shapedIcon.top - border; auto bottom = top + image.pos.h / image.relativePixelRatio; - vec2<float> tl{left, top}; - vec2<float> tr{right, top}; - vec2<float> br{right, bottom}; - vec2<float> bl{left, bottom}; + Point<float> tl{left, top}; + Point<float> tr{right, top}; + Point<float> br{right, bottom}; + Point<float> bl{left, bottom}; float angle = layout.iconRotate * util::DEG2RAD; if (alongLine) { assert(static_cast<unsigned int>(anchor.segment) < line.size()); const GeometryCoordinate &prev= line[anchor.segment]; - if (anchor.y == prev.y && anchor.x == prev.x && + if (anchor.point.y == prev.y && anchor.point.x == prev.x && static_cast<unsigned int>(anchor.segment + 1) < line.size()) { const GeometryCoordinate &next= line[anchor.segment + 1]; - angle += std::atan2(anchor.y - next.y, anchor.x - next.x) + M_PI; + angle += std::atan2(anchor.point.y - next.y, anchor.point.x - next.x) + M_PI; } else { - angle += std::atan2(anchor.y - prev.y, anchor.x - prev.x); + angle += std::atan2(anchor.point.y - prev.y, anchor.point.x - prev.x); } } @@ -48,24 +48,24 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, float angle_cos = std::cos(angle); std::array<float, 4> matrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}}; - tl = tl.matMul(matrix); - tr = tr.matMul(matrix); - bl = bl.matMul(matrix); - br = br.matMul(matrix); + tl = util::matrixMultiply(matrix, tl); + tr = util::matrixMultiply(matrix, tr); + bl = util::matrixMultiply(matrix, bl); + br = util::matrixMultiply(matrix, br); } SymbolQuads quads; - quads.emplace_back(tl, tr, bl, br, image.pos, 0, anchor, globalMinScale, std::numeric_limits<float>::infinity()); + quads.emplace_back(tl, tr, bl, br, image.pos, 0, anchor.point, globalMinScale, std::numeric_limits<float>::infinity()); return quads; } struct GlyphInstance { - explicit GlyphInstance(const vec2<float> &anchorPoint_) : anchorPoint(anchorPoint_) {} - explicit GlyphInstance(const vec2<float> &anchorPoint_, float offset_, float minScale_, float maxScale_, + explicit GlyphInstance(const Point<float> &anchorPoint_) : anchorPoint(anchorPoint_) {} + explicit GlyphInstance(const Point<float> &anchorPoint_, float offset_, float minScale_, float maxScale_, float angle_) : anchorPoint(anchorPoint_), offset(offset_), minScale(minScale_), maxScale(maxScale_), angle(angle_) {} - const vec2<float> anchorPoint; + const Point<float> anchorPoint; const float offset = 0.0f; const float minScale = globalMinScale; const float maxScale = std::numeric_limits<float>::infinity(); @@ -86,8 +86,8 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor & segment++; assert((int)line.size() > segment); - vec2<float> end = line[segment]; - vec2<float> newAnchorPoint = anchor; + Point<float> end = convertPoint<float>(line[segment]); + Point<float> newAnchorPoint = anchor.point; float prevscale = std::numeric_limits<float>::infinity(); offset = std::fabs(offset); @@ -122,10 +122,10 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor & anchor.scale = scale; return; } - end = line[segment]; + end = convertPoint<float>(line[segment]); } - vec2<float> normal = util::normal<float>(newAnchorPoint, end) * dist; + Point<float> normal = util::normal<float>(newAnchorPoint, end) * dist; newAnchorPoint = newAnchorPoint - normal; prevscale = scale; @@ -163,7 +163,7 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, getSegmentGlyphs(std::back_inserter(glyphInstances), anchor, centerX, line, anchor.segment, false); } else { - glyphInstances.emplace_back(GlyphInstance{anchor}); + glyphInstances.emplace_back(GlyphInstance{anchor.point}); } // The rects have an addditional buffer that is not included in their size; @@ -175,17 +175,17 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, const float x2 = x1 + rect.w; const float y2 = y1 + rect.h; - const vec2<float> otl{x1, y1}; - const vec2<float> otr{x2, y1}; - const vec2<float> obl{x1, y2}; - const vec2<float> obr{x2, y2}; + const Point<float> otl{x1, y1}; + const Point<float> otr{x2, y1}; + const Point<float> obl{x1, y2}; + const Point<float> obr{x2, y2}; for (const GlyphInstance &instance : glyphInstances) { - vec2<float> tl = otl; - vec2<float> tr = otr; - vec2<float> bl = obl; - vec2<float> br = obr; + Point<float> tl = otl; + Point<float> tr = otr; + Point<float> bl = obl; + Point<float> br = obr; const float angle = instance.angle + textRotate; if (angle) { @@ -194,10 +194,10 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, float angle_cos = std::cos(angle); std::array<float, 4> matrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}}; - tl = tl.matMul(matrix); - tr = tr.matMul(matrix); - bl = bl.matMul(matrix); - br = br.matMul(matrix); + tl = util::matrixMultiply(matrix, tl); + tr = util::matrixMultiply(matrix, tr); + bl = util::matrixMultiply(matrix, bl); + br = util::matrixMultiply(matrix, br); } // Prevent label from extending past the end of the line diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp index 12b8893503..03f86e1df9 100644 --- a/src/mbgl/text/quads.hpp +++ b/src/mbgl/text/quads.hpp @@ -3,16 +3,15 @@ #include <mbgl/text/glyph.hpp> #include <mbgl/tile/geometry_tile.hpp> -#include <mbgl/util/vec.hpp> #include <vector> namespace mbgl { struct SymbolQuad { - explicit SymbolQuad(const vec2<float> &tl_, const vec2<float> &tr_, - const vec2<float> &bl_, const vec2<float> &br_, - const Rect<uint16_t> &tex_, float angle_, const vec2<float> &anchorPoint_, + explicit SymbolQuad(const Point<float> &tl_, const Point<float> &tr_, + const Point<float> &bl_, const Point<float> &br_, + const Rect<uint16_t> &tex_, float angle_, const Point<float> &anchorPoint_, float minScale_, float maxScale_) : tl(tl_), tr(tr_), @@ -24,10 +23,10 @@ namespace mbgl { minScale(minScale_), maxScale(maxScale_) {} - vec2<float> tl, tr, bl, br; + Point<float> tl, tr, bl, br; Rect<uint16_t> tex; float angle; - vec2<float> anchorPoint; + Point<float> anchorPoint; float minScale, maxScale; }; diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp index 5fbb433035..89249ee605 100644 --- a/src/mbgl/text/shaping.hpp +++ b/src/mbgl/text/shaping.hpp @@ -4,8 +4,6 @@ #include <mbgl/text/glyph.hpp> #include <mbgl/sprite/sprite_atlas.hpp> #include <mbgl/sprite/sprite_image.hpp> - -#include <mbgl/util/vec.hpp> #include <mbgl/util/optional.hpp> namespace mbgl { |