summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-24 14:12:04 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-24 21:04:56 +0300
commita242bd107041bc740788ee8298fd7848c923442f (patch)
tree927a37194c4f7fd13bb25bf589e63285151f27c7
parentec6650d3c0db8bff7e425518176261a8e6ed4e79 (diff)
downloadqtlocation-mapboxgl-a242bd107041bc740788ee8298fd7848c923442f.tar.gz
[core] Optimize RenderLineLayer::queryIntersectsFeature
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index 5c56826bd7..fcd52b21df 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -214,16 +214,22 @@ void RenderLineLayer::render(PaintParameters& parameters) {
}
}
-optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const double offset) {
- if (offset == 0) return {};
+namespace {
+
+GeometryCollection offsetLine(const GeometryCollection& rings, double offset) {
+ assert(offset != 0.0f);
+ assert(!rings.empty());
GeometryCollection newRings;
- Point<double> zero(0, 0);
+ newRings.reserve(rings.size());
+
+ const Point<double> zero(0, 0);
for (const auto& ring : rings) {
newRings.emplace_back();
auto& newRing = newRings.back();
+ newRing.reserve(ring.size());
- for (auto i = ring.begin(); i != ring.end(); i++) {
+ for (auto i = ring.begin(); i != ring.end(); ++i) {
auto& p = *i;
Point<double> aToB = i == ring.begin() ?
@@ -237,13 +243,15 @@ optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const d
const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
extrude *= (1.0 / cosHalfAngle);
- newRing.push_back(convertPoint<int16_t>(extrude * offset) + p);
+ newRing.emplace_back(convertPoint<int16_t>(extrude * offset) + p);
}
}
return newRings;
}
+} // namespace
+
bool RenderLineLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
@@ -263,16 +271,21 @@ bool RenderLineLayer::queryIntersectsFeature(
// Evaluate function
auto offset = evaluated.get<style::LineOffset>()
.evaluate(feature, zoom, style::LineOffset::defaultValue()) * pixelsToTileUnits;
+ // Test intersection
+ const float halfWidth = getLineWidth(feature, zoom) / 2.0 * pixelsToTileUnits;
// Apply offset to geometry
- auto offsetGeometry = offsetLine(feature.getGeometries(), offset);
+ if (offset != 0.0f && !feature.getGeometries().empty()) {
+ return util::polygonIntersectsBufferedMultiLine(
+ translatedQueryGeometry.value_or(queryGeometry),
+ offsetLine(feature.getGeometries(), offset),
+ halfWidth);
+ }
- // Test intersection
- const float halfWidth = getLineWidth(feature, zoom) / 2.0 * pixelsToTileUnits;
return util::polygonIntersectsBufferedMultiLine(
- translatedQueryGeometry.value_or(queryGeometry),
- offsetGeometry.value_or(feature.getGeometries()),
- halfWidth);
+ translatedQueryGeometry.value_or(queryGeometry),
+ feature.getGeometries(),
+ halfWidth);
}
void RenderLineLayer::updateColorRamp() {