Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Fix rest of 'brace initialization' errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Apr 30, 2020
1 parent 0ed719e commit 30b4e57
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void main() {
mapbox::geometry::point<double>{oldParams.puckPosition.latitude(), oldParams.puckPosition.longitude()};
mapbox::geometry::linear_ring<int64_t> border;
for (const auto& v : puckGeometry) {
vec4 p{v.x, v.y, 0, 1};
vec4 p{{v.x, v.y, 0, 1}};
matrix::transformMat4(p, p, translation);
border.push_back(Point<int64_t>{int64_t(p[0]), int64_t(p[1])});
}
Expand Down
92 changes: 46 additions & 46 deletions src/mbgl/util/bounding_volumes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace mbgl {
namespace {

vec3 toVec3(const vec4& v) {
return vec3{v[0], v[1], v[2]};
return vec3{{v[0], v[1], v[2]}};
}

double vec4Dot(const vec4& a, const vec4& b) {
Expand All @@ -33,14 +33,14 @@ static Point<double> ProjectPointsToAxis(const std::array<vec3, N>& points, cons

namespace util {

AABB::AABB() : min({0, 0, 0}), max({0, 0, 0}) {}
AABB::AABB() : min({{0, 0, 0}}), max({{0, 0, 0}}) {}

AABB::AABB(const vec3& min_, const vec3& max_) : min(min_), max(max_) {}

vec3 AABB::closestPoint(const vec3& point) const {
return {std::max(std::min(max[0], point[0]), min[0]),
std::max(std::min(max[1], point[1]), min[1]),
std::max(std::min(max[2], point[2]), min[2])};
return {{std::max(std::min(max[0], point[0]), min[0]),
std::max(std::min(max[1], point[1]), min[1]),
std::max(std::min(max[2], point[2]), min[2])}};
}

vec3 AABB::distanceXYZ(const vec3& point) const {
Expand All @@ -62,8 +62,8 @@ AABB AABB::quadrant(int idx) const {

// This aabb is split into 4 quadrants. For each axis define in which side of the split "idx" is
// The result for indices 0, 1, 2, 3 is: { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 }
const std::array<int, 4> xSplit = {0, 1, 0, 1};
const std::array<int, 4> ySplit = {0, 0, 1, 1};
const std::array<int, 4> xSplit = {{0, 1, 0, 1}};
const std::array<int, 4> ySplit = {{0, 0, 1, 1}};

quadrantMin[0] = xSplit[idx] ? xCenter : quadrantMin[0];
quadrantMax[0] = xSplit[idx] ? quadrantMax[0] : xCenter;
Expand Down Expand Up @@ -103,26 +103,26 @@ enum {

Frustum::Frustum(const std::array<vec3, 8>& points_, const std::array<vec4, 6>& planes_)
: points(points_), planes(planes_) {
const Point<double> xBounds = ProjectPointsToAxis(points, {0, 0, 0}, {1, 0, 0});
const Point<double> yBounds = ProjectPointsToAxis(points, {0, 0, 0}, {0, 1, 0});
const Point<double> zBounds = ProjectPointsToAxis(points, {0, 0, 0}, {0, 0, 1});
const Point<double> xBounds = ProjectPointsToAxis(points, {{0, 0, 0}}, {{1, 0, 0}});
const Point<double> yBounds = ProjectPointsToAxis(points, {{0, 0, 0}}, {{0, 1, 0}});
const Point<double> zBounds = ProjectPointsToAxis(points, {{0, 0, 0}}, {{0, 0, 1}});

bounds = AABB({xBounds.x, yBounds.x, zBounds.x}, {xBounds.y, yBounds.y, zBounds.y});
bounds = AABB({{xBounds.x, yBounds.x, zBounds.x}}, {{xBounds.y, yBounds.y, zBounds.y}});

// Precompute a set of separating axis candidates for precise intersection tests.
// Remaining axes not covered in basic intersection tests are: axis[] = (edges of aabb) x (edges of frustum)
std::array<vec3, 6> frustumEdges = {vec3Sub(points[near_br], points[near_bl]),
vec3Sub(points[near_tl], points[near_bl]),
vec3Sub(points[far_tl], points[near_tl]),
vec3Sub(points[far_tr], points[near_tr]),
vec3Sub(points[far_br], points[near_br]),
vec3Sub(points[far_bl], points[near_bl])};
std::array<vec3, 6> frustumEdges = {{vec3Sub(points[near_br], points[near_bl]),
vec3Sub(points[near_tl], points[near_bl]),
vec3Sub(points[far_tl], points[near_tl]),
vec3Sub(points[far_tr], points[near_tr]),
vec3Sub(points[far_br], points[near_br]),
vec3Sub(points[far_bl], points[near_bl])}};

for (size_t i = 0; i < frustumEdges.size(); i++) {
// Cross product [1, 0, 0] x [a, b, c] == [0, -c, b]
// Cross product [0, 1, 0] x [a, b, c] == [c, 0, -a]
const vec3 axis0 = {0.0, -frustumEdges[i][2], frustumEdges[i][1]};
const vec3 axis1 = {frustumEdges[i][2], 0.0, -frustumEdges[i][0]};
const vec3 axis0 = {{0.0, -frustumEdges[i][2], frustumEdges[i][1]}};
const vec3 axis1 = {{frustumEdges[i][2], 0.0, -frustumEdges[i][0]}};

projections[i * 2] = {axis0, ProjectPointsToAxis(points, points[0], axis0)};
projections[i * 2 + 1] = {axis1, ProjectPointsToAxis(points, points[0], axis1)};
Expand All @@ -131,14 +131,14 @@ Frustum::Frustum(const std::array<vec3, 8>& points_, const std::array<vec4, 6>&

Frustum Frustum::fromInvProjMatrix(const mat4& invProj, double worldSize, double zoom, bool flippedY) {
// Define frustum corner points in normalized clip space
std::array<vec4, 8> cornerCoords = {vec4{-1.0, 1.0, -1.0, 1.0},
vec4{1.0, 1.0, -1.0, 1.0},
vec4{1.0, -1.0, -1.0, 1.0},
vec4{-1.0, -1.0, -1.0, 1.0},
vec4{-1.0, 1.0, 1.0, 1.0},
vec4{1.0, 1.0, 1.0, 1.0},
vec4{1.0, -1.0, 1.0, 1.0},
vec4{-1.0, -1.0, 1.0, 1.0}};
std::array<vec4, 8> cornerCoords = {{vec4{{-1.0, 1.0, -1.0, 1.0}},
vec4{{1.0, 1.0, -1.0, 1.0}},
vec4{{1.0, -1.0, -1.0, 1.0}},
vec4{{-1.0, -1.0, -1.0, 1.0}},
vec4{{-1.0, 1.0, 1.0, 1.0}},
vec4{{1.0, 1.0, 1.0, 1.0}},
vec4{{1.0, -1.0, 1.0, 1.0}},
vec4{{-1.0, -1.0, 1.0, 1.0}}}};

const double scale = std::pow(2.0, zoom);

Expand All @@ -148,14 +148,14 @@ Frustum Frustum::fromInvProjMatrix(const mat4& invProj, double worldSize, double
for (auto& component : coord) component *= 1.0 / coord[3] / worldSize * scale;
}

std::array<vec3i, 6> frustumPlanePointIndices = {
vec3i{near_bl, near_br, far_br}, // bottom
vec3i{near_tl, near_bl, far_bl}, // left
vec3i{near_br, near_tr, far_tr}, // right
vec3i{near_tl, far_tl, far_tr}, // top
vec3i{near_tl, near_tr, near_br}, // near
vec3i{far_br, far_tr, far_tl} // far
};
std::array<vec3i, 6> frustumPlanePointIndices = {{
vec3i{{near_bl, near_br, far_br}}, // bottom
vec3i{{near_tl, near_bl, far_bl}}, // left
vec3i{{near_br, near_tr, far_tr}}, // right
vec3i{{near_tl, far_tl, far_tr}}, // top
vec3i{{near_tl, near_tr, near_br}}, // near
vec3i{{far_br, far_tr, far_tl}} // far
}};

if (flippedY) {
std::for_each(frustumPlanePointIndices.begin(), frustumPlanePointIndices.end(), [](vec3i& tri) {
Expand All @@ -177,7 +177,7 @@ Frustum Frustum::fromInvProjMatrix(const mat4& invProj, double worldSize, double
const vec3 b = vec3Sub(p2, p1);
const vec3 n = vec3Normalize(vec3Cross(a, b));

frustumPlanes[i] = {n[0], n[1], n[2], -vec3Dot(n, p1)};
frustumPlanes[i] = {{n[0], n[1], n[2], -vec3Dot(n, p1)}};
}

std::array<vec3, 8> frustumPoints;
Expand All @@ -197,12 +197,12 @@ IntersectionResult Frustum::intersects(const AABB& aabb) const {

if (!bounds.intersects(aabb)) return IntersectionResult::Separate;

const std::array<vec4, 4> aabbPoints = {
vec4{aabb.min[0], aabb.min[1], 0.0, 1.0},
vec4{aabb.max[0], aabb.min[1], 0.0, 1.0},
vec4{aabb.max[0], aabb.max[1], 0.0, 1.0},
vec4{aabb.min[0], aabb.max[1], 0.0, 1.0},
};
const std::array<vec4, 4> aabbPoints = {{
vec4{{aabb.min[0], aabb.min[1], 0.0, 1.0}},
vec4{{aabb.max[0], aabb.min[1], 0.0, 1.0}},
vec4{{aabb.max[0], aabb.max[1], 0.0, 1.0}},
vec4{{aabb.min[0], aabb.max[1], 0.0, 1.0}},
}};

bool fullyInside = true;

Expand Down Expand Up @@ -232,10 +232,10 @@ IntersectionResult Frustum::intersectsPrecise(const AABB& aabb, bool edgeCasesOn
if (result == IntersectionResult::Separate) return result;
}

const std::array<vec3, 4> aabbPoints = {vec3{aabb.min[0], aabb.min[1], 0.0},
vec3{aabb.max[0], aabb.min[1], 0.0},
vec3{aabb.max[0], aabb.max[1], 0.0},
vec3{aabb.min[0], aabb.max[1], 0.0}};
const std::array<vec3, 4> aabbPoints = {{vec3{{aabb.min[0], aabb.min[1], 0.0}},
vec3{{aabb.max[0], aabb.min[1], 0.0}},
vec3{{aabb.max[0], aabb.max[1], 0.0}},
vec3{{aabb.min[0], aabb.max[1], 0.0}}}};

// For a precise SAT-test all edge cases needs to be covered
// Projections of the frustum on separating axis candidates have been precomputed already
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/util/mat3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using vec3i = std::array<int, 3>;
using mat3 = std::array<double, 9>;

inline vec3 vec3Cross(const vec3& a, const vec3& b) {
return vec3{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]};
return vec3{{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]}};
}

inline double vec3Dot(const vec3& a, const vec3& b) {
Expand All @@ -49,15 +49,15 @@ inline double vec3Length(const vec3& a) {
}

inline vec3 vec3Scale(const vec3& a, double s) {
return vec3{a[0] * s, a[1] * s, a[2] * s};
return vec3{{a[0] * s, a[1] * s, a[2] * s}};
}

inline vec3 vec3Normalize(const vec3& a) {
return vec3Scale(a, 1.0 / vec3Length(a));
}

inline vec3 vec3Sub(const vec3& a, const vec3& b) {
return vec3{a[0] - b[0], a[1] - b[1], a[2] - b[2]};
return vec3{{a[0] - b[0], a[1] - b[1], a[2] - b[2]}};
}

namespace matrix {
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/util/tile_cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ std::vector<OverscaledTileID> tileCover(const TransformState& state, uint8_t z,
auto centerPoint =
TileCoordinate::fromScreenCoordinate(state, z, {state.getSize().width / 2.0, state.getSize().height / 2.0}).p;

vec3 centerCoord = {centerPoint.x, centerPoint.y, 0.0};
vec3 centerCoord = {{centerPoint.x, centerPoint.y, 0.0}};

const Frustum frustum = Frustum::fromInvProjMatrix(state.getInvProjectionMatrix(), worldSize, z, flippedY);

// There should always be a certain number of maximum zoom level tiles surrounding the center location
const double radiusOfMaxLvlLodInTiles = 3;

const auto newRootTile = [&](int16_t wrap) -> Node {
return {AABB({wrap * numTiles, 0.0, 0.0}, {(wrap + 1) * numTiles, numTiles, 0.0}),
return {AABB({{wrap * numTiles, 0.0, 0.0}}, {{(wrap + 1) * numTiles, numTiles, 0.0}}),
uint8_t(0),
uint16_t(0),
uint16_t(0),
Expand Down

0 comments on commit 30b4e57

Please sign in to comment.