| 26 | } |
| 27 | |
| 28 | std::optional<CesiumGeometry::QuadtreeTileID> |
| 29 | QuadtreeTilingScheme::positionToTile(const glm::dvec2& position, uint32_t level) |
| 30 | const noexcept { |
| 31 | if (!this->getRectangle().contains(position)) { |
| 32 | // outside the bounds of the tiling scheme |
| 33 | return std::nullopt; |
| 34 | } |
| 35 | |
| 36 | const uint32_t xTiles = this->getNumberOfXTilesAtLevel(level); |
| 37 | const uint32_t yTiles = this->getNumberOfYTilesAtLevel(level); |
| 38 | |
| 39 | const double overallWidth = this->getRectangle().computeWidth(); |
| 40 | const double xTileWidth = overallWidth / xTiles; |
| 41 | const double overallHeight = this->getRectangle().computeHeight(); |
| 42 | const double yTileHeight = overallHeight / yTiles; |
| 43 | |
| 44 | const double distanceFromWest = position.x - this->getRectangle().minimumX; |
| 45 | const double distanceFromSouth = position.y - this->getRectangle().minimumY; |
| 46 | |
| 47 | uint32_t xTileCoordinate = |
| 48 | static_cast<uint32_t>(distanceFromWest / xTileWidth); |
| 49 | if (xTileCoordinate >= xTiles) { |
| 50 | xTileCoordinate = xTiles - 1; |
| 51 | } |
| 52 | uint32_t yTileCoordinate = |
| 53 | static_cast<uint32_t>(distanceFromSouth / yTileHeight); |
| 54 | if (yTileCoordinate >= yTiles) { |
| 55 | yTileCoordinate = yTiles - 1; |
| 56 | } |
| 57 | |
| 58 | return CesiumGeometry::QuadtreeTileID( |
| 59 | level, |
| 60 | xTileCoordinate, |
| 61 | yTileCoordinate); |
| 62 | } |
| 63 | |
| 64 | CesiumGeometry::Rectangle QuadtreeTilingScheme::tileToRectangle( |
| 65 | const CesiumGeometry::QuadtreeTileID& tileID) const noexcept { |
nothing calls this directly
no test coverage detected