Search for hovered lines in parallel

This commit is contained in:
Dan Paulat 2023-08-28 23:51:24 -05:00
parent 2c3de1a28f
commit 24c919afb6

View file

@ -4,6 +4,8 @@
#include <scwx/qt/util/maplibre.hpp>
#include <scwx/util/logger.hpp>
#include <execution>
namespace scwx
{
namespace qt
@ -255,7 +257,11 @@ bool PlacefileLines::RunMousePicking(
glm::vec3(0.0f, 0.0f, 1.0f));
// For each pickable line
for (auto& line : p->currentHoverLines_)
auto it = std::find_if(
std::execution::par_unseq,
p->currentHoverLines_.cbegin(),
p->currentHoverLines_.cend(),
[&mapMatrix, &mousePos](const auto& line)
{
// Initialize vertices
glm::vec2 bl = line.p1_;
@ -264,7 +270,7 @@ bool PlacefileLines::RunMousePicking(
glm::vec2 tr = tl;
// Calculate offsets
// - Pre-rotated offset is half the line width (pixels) in each direction
// - Rotated offset is half the line width (pixels) in each direction
// - Multiply the offset by the scaled and rotated map matrix
const glm::vec2 otl = mapMatrix * glm::vec4 {line.otl_, 0.0f, 1.0f};
const glm::vec2 obl = mapMatrix * glm::vec4 {line.obl_, 0.0f, 1.0f};
@ -280,12 +286,13 @@ bool PlacefileLines::RunMousePicking(
// TODO: X/Y offsets
// Test point against polygon bounds
if (util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mousePos))
return util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mousePos);
});
if (it != p->currentHoverLines_.cend())
{
itemPicked = true;
util::ImGui::Instance().DrawTooltip(line.di_->hoverText_);
break;
}
util::ImGui::Instance().DrawTooltip(it->di_->hoverText_);
}
return itemPicked;