Skip to content

Commit

Permalink
Fix render tests (maplibre#351)
Browse files Browse the repository at this point in the history
* Fix render tests

* Update src/mbgl/util/grid_index.cpp

Co-authored-by: Tadej Novak <[email protected]>

* Update src/mbgl/util/grid_index.cpp

Co-authored-by: Tadej Novak <[email protected]>

* Update src/mbgl/text/collision_index.cpp

Co-authored-by: Tadej Novak <[email protected]>

* Add static casts

* Remove unneeded static cast

Co-authored-by: Tadej Novak <[email protected]>
  • Loading branch information
wipfli and ntadej authored Jul 5, 2022
1 parent 5b3d936 commit 52b5f02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/mbgl/text/collision_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,22 @@ IntersectStatus CollisionIndex::intersectsTileEdges(const CollisionBox& box,
const float tileY2 = tileEdges[3];

// Check left border
float minSectionLength = std::min(tileX1 - x1, x2 - tileX1);
int minSectionLength = static_cast<int>(std::min(tileX1 - x1, x2 - tileX1));
if (minSectionLength <= 0) { // Check right border
minSectionLength = std::min(tileX2 - x1, x2 - tileX2);
minSectionLength = static_cast<int>(std::min(tileX2 - x1, x2 - tileX2));
}
if (minSectionLength > 0) {
result.flags |= IntersectStatus::VerticalBorders;
result.minSectionLength = static_cast<int>(minSectionLength);
result.minSectionLength = minSectionLength;
}
// Check top border
minSectionLength = std::min(tileY1 - y1, y2 - tileY1);
minSectionLength = static_cast<int>(std::min(tileY1 - y1, y2 - tileY1));
if (minSectionLength <= 0) { // Check bottom border
minSectionLength = std::min(tileY2 - y1, y2 - tileY2);
minSectionLength = static_cast<int>(std::min(tileY2 - y1, y2 - tileY2));
}
if (minSectionLength > 0) {
result.flags |= IntersectStatus::HorizontalBorders;
result.minSectionLength = std::min(result.minSectionLength, static_cast<int>(minSectionLength));
result.minSectionLength = std::min(result.minSectionLength, minSectionLength);
}
return result;
}
Expand Down Expand Up @@ -415,8 +415,8 @@ std::pair<Point<float>,float> CollisionIndex::projectAndGetPerspectiveRatio(cons
auto size = transformState.getSize();
return std::make_pair(
Point<float>(
static_cast<float>(((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding,
static_cast<float>(((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding
static_cast<float>(((p[0] / p[3] + 1) / 2) * size.width + viewportPadding),
static_cast<float>(((-p[1] / p[3] + 1) / 2) * size.height + viewportPadding)
),
// See perspective ratio comment in symbol_sdf.vertex
// We're doing collision detection in viewport space so we need
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/util/grid_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ void GridIndex<T>::query(const BCircle& queryBCircle, std::function<bool (const

template <class T>
std::size_t GridIndex<T>::convertToXCellCoord(const float x) const {
return util::max(size_t(0), util::min(xCellCount - 1, static_cast<size_t>(std::floor(x * xScale))));
return static_cast<size_t>(util::max(0.0, util::min(xCellCount - 1.0, std::floor(x * xScale))));
}

template <class T>
std::size_t GridIndex<T>::convertToYCellCoord(const float y) const {
return util::max(size_t(0), util::min(yCellCount - 1, static_cast<size_t>(std::floor(y * yScale))));
return static_cast<size_t>(util::max(0.0, util::min(yCellCount - 1.0, std::floor(y * yScale))));
}

template <class T>
Expand Down

0 comments on commit 52b5f02

Please sign in to comment.