21 lines
788 B
C++
21 lines
788 B
C++
#pragma once
|
|
#include <algorithm>
|
|
#include <optional>
|
|
#include <vector>
|
|
|
|
namespace aethera::render_2d::detail {
|
|
/* 保留无评分接收者的绘制层级顺序,再将有评分的候选者按距离从近到远排列。 */
|
|
struct Nearest_Event_Target_Rule {
|
|
template <typename Target, typename Score>
|
|
static void apply(std::vector<Target>& targets, Score&& score) {
|
|
std::stable_sort(targets.begin(), targets.end(), [&](const Target& left, const Target& right) {
|
|
const std::optional<double> left_score = score(left);
|
|
const std::optional<double> right_score = score(right);
|
|
if (!left_score) return right_score.has_value();
|
|
if (!right_score) return false;
|
|
return *left_score < *right_score;
|
|
});
|
|
}
|
|
};
|
|
}
|