49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#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
|