[core] Use mapbox::geometry::{box,envelope}
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <mbgl/util/math.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
|
||||
#include <mapbox/geometry/envelope.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
@@ -21,23 +23,8 @@ void FeatureIndex::insert(const GeometryCollection& geometries,
|
||||
const std::string& sourceLayerName,
|
||||
const std::string& bucketName) {
|
||||
for (const auto& ring : geometries) {
|
||||
float minX = std::numeric_limits<float>::infinity();
|
||||
float minY = std::numeric_limits<float>::infinity();
|
||||
float maxX = -std::numeric_limits<float>::infinity();
|
||||
float maxY = -std::numeric_limits<float>::infinity();
|
||||
|
||||
for (const auto& p : ring) {
|
||||
const float x = p.x;
|
||||
const float y = p.y;
|
||||
minX = util::min(minX, x);
|
||||
minY = util::min(minY, y);
|
||||
maxX = util::max(maxX, x);
|
||||
maxY = util::max(maxY, y);
|
||||
}
|
||||
|
||||
grid.insert(
|
||||
IndexedSubfeature { index, sourceLayerName, bucketName, sortIndex++ },
|
||||
{ int32_t(minX), int32_t(minY), int32_t(maxX), int32_t(maxY) });
|
||||
grid.insert(IndexedSubfeature { index, sourceLayerName, bucketName, sortIndex++ },
|
||||
mapbox::geometry::envelope<GeometryCoordinates, int16_t>(ring));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,30 +59,11 @@ void FeatureIndex::query(
|
||||
const GeometryTile& geometryTile,
|
||||
const Style& style) const {
|
||||
|
||||
mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope<GeometryCollection, int16_t>(queryGeometry);
|
||||
|
||||
const float pixelsToTileUnits = util::EXTENT / tileSize / scale;
|
||||
|
||||
float additionalRadius = style.getQueryRadius() * pixelsToTileUnits;
|
||||
|
||||
float minX = std::numeric_limits<float>::infinity();
|
||||
float minY = std::numeric_limits<float>::infinity();
|
||||
float maxX = -std::numeric_limits<float>::infinity();
|
||||
float maxY = -std::numeric_limits<float>::infinity();
|
||||
|
||||
for (const auto& ring : queryGeometry) {
|
||||
for (const auto& p : ring) {
|
||||
minX = util::min<float>(minX, p.x);
|
||||
minY = util::min<float>(minY, p.y);
|
||||
maxX = util::max<float>(maxX, p.x);
|
||||
maxY = util::max<float>(maxY, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<IndexedSubfeature> features = grid.query({
|
||||
int(minX - additionalRadius),
|
||||
int(minY - additionalRadius),
|
||||
int(maxX + additionalRadius),
|
||||
int(maxY + additionalRadius)
|
||||
});
|
||||
const int16_t additionalRadius = std::min<int16_t>(util::EXTENT, std::ceil(style.getQueryRadius() * pixelsToTileUnits));
|
||||
std::vector<IndexedSubfeature> features = grid.query({ box.min - additionalRadius, box.max + additionalRadius });
|
||||
|
||||
std::sort(features.begin(), features.end(), topDown);
|
||||
size_t previousSortIndex = std::numeric_limits<size_t>::max();
|
||||
@@ -110,7 +78,7 @@ void FeatureIndex::query(
|
||||
|
||||
// query symbol features
|
||||
assert(collisionTile);
|
||||
std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(minX, minY, maxX, maxY, scale);
|
||||
std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(box, scale);
|
||||
std::sort(symbolFeatures.begin(), symbolFeatures.end(), topDownSymbols);
|
||||
for (const auto& symbolFeature : symbolFeatures) {
|
||||
addFeature(result, symbolFeature, queryGeometry, filterLayerIDs, geometryTile, style, bearing, pixelsToTileUnits);
|
||||
|
||||
@@ -153,13 +153,13 @@ Box CollisionTile::getTreeBox(const Point<float>& anchor, const CollisionBox& bo
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float minX, const float minY, const float maxX, const float maxY, const float scale) {
|
||||
std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const mapbox::geometry::box<int16_t>& box, const float scale) {
|
||||
|
||||
std::vector<IndexedSubfeature> result;
|
||||
std::unordered_map<std::string, std::set<std::size_t>> sourceLayerFeatures;
|
||||
|
||||
auto anchor = util::matrixMultiply(rotationMatrix, Point<float>(minX, minY));
|
||||
CollisionBox queryBox(anchor, 0, 0, maxX - minX, maxY - minY, scale);
|
||||
auto anchor = util::matrixMultiply(rotationMatrix, convertPoint<float>(box.min));
|
||||
CollisionBox queryBox(anchor, 0, 0, box.max.x - box.min.x, box.max.y - box.min.y, scale);
|
||||
auto predicates = bgi::intersects(getTreeBox(anchor, queryBox));
|
||||
|
||||
auto fn = [&] (const Tree& tree_) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
float placeFeature(const CollisionFeature&, const bool allowOverlap, const bool avoidEdges);
|
||||
void insertFeature(CollisionFeature&, const float minPlacementScale, const bool ignorePlacement);
|
||||
|
||||
std::vector<IndexedSubfeature> queryRenderedSymbols(const float minX, const float minY, const float maxX, const float maxY, const float scale);
|
||||
std::vector<IndexedSubfeature> queryRenderedSymbols(const mapbox::geometry::box<int16_t>&, const float scale);
|
||||
|
||||
const PlacementConfig config;
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ GridIndex<T>::GridIndex(int32_t extent_, int32_t n_, int32_t padding_) :
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void GridIndex<T>::insert(T&& t, BBox&& bbox) {
|
||||
void GridIndex<T>::insert(T&& t, const BBox& bbox) {
|
||||
size_t uid = elements.size();
|
||||
|
||||
auto cx1 = convertToCellCoord(bbox.x1);
|
||||
auto cy1 = convertToCellCoord(bbox.y1);
|
||||
auto cx2 = convertToCellCoord(bbox.x2);
|
||||
auto cy2 = convertToCellCoord(bbox.y2);
|
||||
auto cx1 = convertToCellCoord(bbox.min.x);
|
||||
auto cy1 = convertToCellCoord(bbox.min.y);
|
||||
auto cx2 = convertToCellCoord(bbox.max.x);
|
||||
auto cy2 = convertToCellCoord(bbox.max.y);
|
||||
|
||||
for (int32_t x = cx1; x <= cx2; x++) {
|
||||
for (int32_t y = cy1; y <= cy2; y++) {
|
||||
@@ -43,10 +43,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const {
|
||||
std::vector<T> result;
|
||||
std::unordered_set<size_t> seenUids;
|
||||
|
||||
auto cx1 = convertToCellCoord(queryBBox.x1);
|
||||
auto cy1 = convertToCellCoord(queryBBox.y1);
|
||||
auto cx2 = convertToCellCoord(queryBBox.x2);
|
||||
auto cy2 = convertToCellCoord(queryBBox.y2);
|
||||
auto cx1 = convertToCellCoord(queryBBox.min.x);
|
||||
auto cy1 = convertToCellCoord(queryBBox.min.y);
|
||||
auto cx2 = convertToCellCoord(queryBBox.max.x);
|
||||
auto cy2 = convertToCellCoord(queryBBox.max.y);
|
||||
|
||||
for (int32_t x = cx1; x <= cx2; x++) {
|
||||
for (int32_t y = cy1; y <= cy2; y++) {
|
||||
@@ -57,10 +57,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const {
|
||||
|
||||
auto& pair = elements.at(uid);
|
||||
auto& bbox = pair.second;
|
||||
if (queryBBox.x1 <= bbox.x2 &&
|
||||
queryBBox.y1 <= bbox.y2 &&
|
||||
queryBBox.x2 >= bbox.x1 &&
|
||||
queryBBox.y2 >= bbox.y1) {
|
||||
if (queryBBox.min.x <= bbox.max.x &&
|
||||
queryBBox.min.y <= bbox.max.y &&
|
||||
queryBBox.max.x >= bbox.min.x &&
|
||||
queryBBox.max.y >= bbox.min.y) {
|
||||
|
||||
result.push_back(pair.first);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <mapbox/geometry/point.hpp>
|
||||
#include <mapbox/geometry/box.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
@@ -8,22 +11,15 @@ namespace mbgl {
|
||||
|
||||
template <class T>
|
||||
class GridIndex {
|
||||
public:
|
||||
|
||||
public:
|
||||
GridIndex(int32_t extent_, int32_t n_, int32_t padding_);
|
||||
|
||||
struct BBox {
|
||||
int32_t x1;
|
||||
int32_t y1;
|
||||
int32_t x2;
|
||||
int32_t y2;
|
||||
};
|
||||
using BBox = mapbox::geometry::box<int16_t>;
|
||||
|
||||
void insert(T&& t, BBox&& bbox);
|
||||
std::vector<T> query(const BBox& bbox) const;
|
||||
|
||||
private:
|
||||
void insert(T&& t, const BBox&);
|
||||
std::vector<T> query(const BBox&) const;
|
||||
|
||||
private:
|
||||
int32_t convertToCellCoord(int32_t x) const;
|
||||
|
||||
const int32_t extent;
|
||||
|
||||
Reference in New Issue
Block a user