mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 14:50:05 +00:00
Search for hovered lines in parallel
This commit is contained in:
parent
2c3de1a28f
commit
24c919afb6
1 changed files with 37 additions and 30 deletions
|
|
@ -4,6 +4,8 @@
|
||||||
#include <scwx/qt/util/maplibre.hpp>
|
#include <scwx/qt/util/maplibre.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
|
#include <execution>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace qt
|
namespace qt
|
||||||
|
|
@ -255,37 +257,42 @@ bool PlacefileLines::RunMousePicking(
|
||||||
glm::vec3(0.0f, 0.0f, 1.0f));
|
glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
// For each pickable line
|
// For each pickable line
|
||||||
for (auto& line : p->currentHoverLines_)
|
auto it = std::find_if(
|
||||||
{
|
std::execution::par_unseq,
|
||||||
// Initialize vertices
|
p->currentHoverLines_.cbegin(),
|
||||||
glm::vec2 bl = line.p1_;
|
p->currentHoverLines_.cend(),
|
||||||
glm::vec2 br = bl;
|
[&mapMatrix, &mousePos](const auto& line)
|
||||||
glm::vec2 tl = line.p2_;
|
|
||||||
glm::vec2 tr = tl;
|
|
||||||
|
|
||||||
// Calculate offsets
|
|
||||||
// - Pre-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};
|
|
||||||
const glm::vec2 obr = mapMatrix * glm::vec4 {line.obr_, 0.0f, 1.0f};
|
|
||||||
const glm::vec2 otr = mapMatrix * glm::vec4 {line.otr_, 0.0f, 1.0f};
|
|
||||||
|
|
||||||
// Offset vertices
|
|
||||||
tl += otl;
|
|
||||||
bl += obl;
|
|
||||||
br += obr;
|
|
||||||
tr += otr;
|
|
||||||
|
|
||||||
// TODO: X/Y offsets
|
|
||||||
|
|
||||||
// Test point against polygon bounds
|
|
||||||
if (util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mousePos))
|
|
||||||
{
|
{
|
||||||
itemPicked = true;
|
// Initialize vertices
|
||||||
util::ImGui::Instance().DrawTooltip(line.di_->hoverText_);
|
glm::vec2 bl = line.p1_;
|
||||||
break;
|
glm::vec2 br = bl;
|
||||||
}
|
glm::vec2 tl = line.p2_;
|
||||||
|
glm::vec2 tr = tl;
|
||||||
|
|
||||||
|
// Calculate offsets
|
||||||
|
// - 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};
|
||||||
|
const glm::vec2 obr = mapMatrix * glm::vec4 {line.obr_, 0.0f, 1.0f};
|
||||||
|
const glm::vec2 otr = mapMatrix * glm::vec4 {line.otr_, 0.0f, 1.0f};
|
||||||
|
|
||||||
|
// Offset vertices
|
||||||
|
tl += otl;
|
||||||
|
bl += obl;
|
||||||
|
br += obr;
|
||||||
|
tr += otr;
|
||||||
|
|
||||||
|
// TODO: X/Y offsets
|
||||||
|
|
||||||
|
// Test point against polygon bounds
|
||||||
|
return util::maplibre::IsPointInPolygon({tl, bl, br, tr}, mousePos);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != p->currentHoverLines_.cend())
|
||||||
|
{
|
||||||
|
itemPicked = true;
|
||||||
|
util::ImGui::Instance().DrawTooltip(it->di_->hoverText_);
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemPicked;
|
return itemPicked;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue