Files
pdf/engine/src/layout/spatial_index.cpp
T

49 lines
1.4 KiB
C++
Raw Normal View History

2026-08-03 11:26:44 +05:30
#include <pdfengine/spatial_index.hpp>
namespace pdfengine {
void MultiIndexSpatialIndex::buildFromTree(const PhysicalLayoutTree& tree) {
clear();
for (const auto& block : tree.allBlocks) {
if (!block) continue;
m_indexedBlocks.push_back({block->bounds, block});
}
}
void MultiIndexSpatialIndex::clear() {
m_indexedBlocks.clear();
m_indexedLines.clear();
}
std::vector<std::shared_ptr<LayoutBlock>> MultiIndexSpatialIndex::queryBlocksAtPoint(float x, float y) const {
std::vector<std::shared_ptr<LayoutBlock>> results;
for (const auto& entry : m_indexedBlocks) {
if (entry.bounds.contains(x, y)) {
results.push_back(entry.block);
}
}
return results;
}
std::vector<std::shared_ptr<LayoutBlock>> MultiIndexSpatialIndex::queryBlocksInRect(const geometry::Rect& rect) const {
std::vector<std::shared_ptr<LayoutBlock>> results;
for (const auto& entry : m_indexedBlocks) {
if (entry.bounds.intersects(rect)) {
results.push_back(entry.block);
}
}
return results;
}
std::vector<std::shared_ptr<LayoutBlock>> MultiIndexSpatialIndex::queryBlocksByType(LayoutBlockType type) const {
std::vector<std::shared_ptr<LayoutBlock>> results;
for (const auto& entry : m_indexedBlocks) {
if (entry.block && entry.block->type == type) {
results.push_back(entry.block);
}
}
return results;
}
} // namespace pdfengine