[core] Use numeric_limits<>::max() for checking element groups
This commit is contained in:
@@ -418,6 +418,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
|
||||
|
||||
template <typename Buffer>
|
||||
void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle) {
|
||||
constexpr const uint16_t vertexLength = 4;
|
||||
const float placementZoom = util::max(util::log2(scale) + zoom, 0.0f);
|
||||
|
||||
for (const auto& symbol : symbols) {
|
||||
@@ -447,16 +448,15 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
|
||||
minZoom = 0;
|
||||
}
|
||||
|
||||
const int glyph_vertex_length = 4;
|
||||
|
||||
if (buffer.segments.empty() || buffer.segments.back().vertexLength + glyph_vertex_length > 65535) {
|
||||
if (buffer.segments.back().vertexLength + vertexLength > std::numeric_limits<uint16_t>::max()) {
|
||||
buffer.segments.emplace_back(buffer.vertices.size(), buffer.triangles.size());
|
||||
}
|
||||
|
||||
// We're generating triangle fans, so we always start with the first
|
||||
// coordinate in this polygon.
|
||||
auto& segment = buffer.segments.back();
|
||||
size_t index = segment.vertexLength;
|
||||
assert(segment.vertexLength <= std::numeric_limits<uint16_t>::max());
|
||||
uint16_t index = segment.vertexLength;
|
||||
|
||||
// Encode angle of glyph
|
||||
uint8_t glyphAngle = std::round((symbol.glyphAngle / (M_PI * 2)) * 256);
|
||||
@@ -472,14 +472,10 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
|
||||
minZoom, maxZoom, placementZoom, glyphAngle);
|
||||
|
||||
// add the two triangles, referencing the four coordinates we just inserted.
|
||||
buffer.triangles.emplace_back(static_cast<uint16_t>(index + 0),
|
||||
static_cast<uint16_t>(index + 1),
|
||||
static_cast<uint16_t>(index + 2));
|
||||
buffer.triangles.emplace_back(static_cast<uint16_t>(index + 1),
|
||||
static_cast<uint16_t>(index + 2),
|
||||
static_cast<uint16_t>(index + 3));
|
||||
buffer.triangles.emplace_back(index + 0, index + 1, index + 2);
|
||||
buffer.triangles.emplace_back(index + 1, index + 2, index + 3);
|
||||
|
||||
segment.vertexLength += glyph_vertex_length;
|
||||
segment.vertexLength += vertexLength;
|
||||
segment.primitiveLength += 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ bool CircleBucket::hasData() const {
|
||||
}
|
||||
|
||||
void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
|
||||
constexpr const uint16_t vertexLength = 4;
|
||||
|
||||
for (auto& circle : geometryCollection) {
|
||||
for(auto & geometry : circle) {
|
||||
auto x = geometry.x;
|
||||
@@ -42,7 +44,7 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
|
||||
if ((mode != MapMode::Still) &&
|
||||
(x < 0 || x >= util::EXTENT || y < 0 || y >= util::EXTENT)) continue;
|
||||
|
||||
if (!segments.size() || segments.back().vertexLength + 4 > 65535) {
|
||||
if (segments.back().vertexLength + vertexLength > std::numeric_limits<uint16_t>::max()) {
|
||||
// Move to a new segments because the old one can't hold the geometry.
|
||||
segments.emplace_back(vertices.size(), triangles.size());
|
||||
}
|
||||
@@ -62,18 +64,15 @@ void CircleBucket::addGeometry(const GeometryCollection& geometryCollection) {
|
||||
vertices.emplace_back(x, y, -1, 1); // 4
|
||||
|
||||
auto& segment = segments.back();
|
||||
assert(segment.vertexLength <= std::numeric_limits<uint16_t>::max());
|
||||
uint16_t index = segment.vertexLength;
|
||||
|
||||
// 1, 2, 3
|
||||
// 1, 4, 3
|
||||
triangles.emplace_back(index,
|
||||
static_cast<uint16_t>(index + 1),
|
||||
static_cast<uint16_t>(index + 2));
|
||||
triangles.emplace_back(index,
|
||||
static_cast<uint16_t>(index + 3),
|
||||
static_cast<uint16_t>(index + 2));
|
||||
triangles.emplace_back(index, index + 1, index + 2);
|
||||
triangles.emplace_back(index, index + 3, index + 2);
|
||||
|
||||
segment.vertexLength += 4;
|
||||
segment.vertexLength += vertexLength;
|
||||
segment.primitiveLength += 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
std::vector<CircleVertex> vertices;
|
||||
std::vector<gl::Triangle> triangles;
|
||||
std::vector<gl::Segment> segments;
|
||||
std::vector<gl::Segment> segments { { 0, 0 } };
|
||||
|
||||
optional<gl::VertexBuffer<CircleVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
|
||||
|
||||
@@ -39,7 +39,7 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
|
||||
|
||||
for (const auto& ring : polygon) {
|
||||
totalVertices += ring.size();
|
||||
if (totalVertices > 65535)
|
||||
if (totalVertices > std::numeric_limits<uint16_t>::max())
|
||||
throw GeometryTooLongException();
|
||||
}
|
||||
|
||||
@@ -51,21 +51,20 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
|
||||
if (nVertices == 0)
|
||||
continue;
|
||||
|
||||
if (lineSegments.empty() || lineSegments.back().vertexLength + nVertices > 65535) {
|
||||
if (lineSegments.back().vertexLength + nVertices > std::numeric_limits<uint16_t>::max()) {
|
||||
lineSegments.emplace_back(vertices.size(), lines.size());
|
||||
}
|
||||
|
||||
auto& lineSegment = lineSegments.back();
|
||||
assert(lineSegment.vertexLength <= std::numeric_limits<uint16_t>::max());
|
||||
uint16_t lineIndex = lineSegment.vertexLength;
|
||||
|
||||
vertices.emplace_back(ring[0].x, ring[0].y);
|
||||
lines.emplace_back(static_cast<uint16_t>(lineIndex + nVertices - 1),
|
||||
static_cast<uint16_t>(lineIndex));
|
||||
lines.emplace_back(lineIndex + nVertices - 1, lineIndex);
|
||||
|
||||
for (uint32_t i = 1; i < nVertices; i++) {
|
||||
vertices.emplace_back(ring[i].x, ring[i].y);
|
||||
lines.emplace_back(static_cast<uint16_t>(lineIndex + i - 1),
|
||||
static_cast<uint16_t>(lineIndex + i));
|
||||
lines.emplace_back(lineIndex + i - 1, lineIndex + i);
|
||||
}
|
||||
|
||||
lineSegment.vertexLength += nVertices;
|
||||
@@ -77,17 +76,18 @@ void FillBucket::addGeometry(const GeometryCollection& geometry) {
|
||||
std::size_t nIndicies = indices.size();
|
||||
assert(nIndicies % 3 == 0);
|
||||
|
||||
if (triangleSegments.empty() || triangleSegments.back().vertexLength + totalVertices > 65535) {
|
||||
if (triangleSegments.back().vertexLength + totalVertices > std::numeric_limits<uint16_t>::max()) {
|
||||
triangleSegments.emplace_back(startVertices, triangles.size());
|
||||
}
|
||||
|
||||
auto& triangleSegment = triangleSegments.back();
|
||||
assert(triangleSegment.vertexLength <= std::numeric_limits<uint16_t>::max());
|
||||
uint16_t triangleIndex = triangleSegment.vertexLength;
|
||||
|
||||
for (uint32_t i = 0; i < nIndicies; i += 3) {
|
||||
triangles.emplace_back(static_cast<uint16_t>(triangleIndex + indices[i]),
|
||||
static_cast<uint16_t>(triangleIndex + indices[i + 1]),
|
||||
static_cast<uint16_t>(triangleIndex + indices[i + 2]));
|
||||
triangles.emplace_back(triangleIndex + indices[i],
|
||||
triangleIndex + indices[i + 1],
|
||||
triangleIndex + indices[i + 2]);
|
||||
}
|
||||
|
||||
triangleSegment.vertexLength += totalVertices;
|
||||
|
||||
@@ -22,8 +22,8 @@ public:
|
||||
std::vector<FillVertex> vertices;
|
||||
std::vector<gl::Line> lines;
|
||||
std::vector<gl::Triangle> triangles;
|
||||
std::vector<gl::Segment> lineSegments;
|
||||
std::vector<gl::Segment> triangleSegments;
|
||||
std::vector<gl::Segment> lineSegments { { 0, 0 } };
|
||||
std::vector<gl::Segment> triangleSegments { { 0, 0 } };
|
||||
|
||||
optional<gl::VertexBuffer<FillVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Line>> lineIndexBuffer;
|
||||
|
||||
@@ -348,17 +348,17 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
|
||||
const std::size_t endVertex = vertices.size();
|
||||
const std::size_t vertexCount = endVertex - startVertex;
|
||||
|
||||
if (segments.empty() || segments.back().vertexLength + vertexCount > 65535) {
|
||||
if (segments.back().vertexLength + vertexCount > std::numeric_limits<uint16_t>::max()) {
|
||||
// Move to a new group because the old one can't hold the geometry.
|
||||
segments.emplace_back(startVertex, triangles.size());
|
||||
}
|
||||
|
||||
auto& segment = segments.back();
|
||||
assert(segment.vertexLength <= std::numeric_limits<uint16_t>::max());
|
||||
uint16_t index = segment.vertexLength;
|
||||
|
||||
for (const auto& triangle : triangleStore) {
|
||||
triangles.emplace_back(static_cast<uint16_t>(index + triangle.a),
|
||||
static_cast<uint16_t>(index + triangle.b),
|
||||
static_cast<uint16_t>(index + triangle.c));
|
||||
triangles.emplace_back(index + triangle.a, index + triangle.b, index + triangle.c);
|
||||
}
|
||||
|
||||
segment.vertexLength += vertexCount;
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
std::vector<LineVertex> vertices;
|
||||
std::vector<gl::Triangle> triangles;
|
||||
std::vector<gl::Segment> segments;
|
||||
std::vector<gl::Segment> segments { { 0, 0 } };
|
||||
|
||||
optional<gl::VertexBuffer<LineVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
struct TextBuffer {
|
||||
std::vector<SymbolVertex> vertices;
|
||||
std::vector<gl::Triangle> triangles;
|
||||
std::vector<gl::Segment> segments;
|
||||
std::vector<gl::Segment> segments { { 0, 0 } };
|
||||
|
||||
optional<gl::VertexBuffer<SymbolVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
struct IconBuffer {
|
||||
std::vector<SymbolVertex> vertices;
|
||||
std::vector<gl::Triangle> triangles;
|
||||
std::vector<gl::Segment> segments;
|
||||
std::vector<gl::Segment> segments { { 0, 0 } };
|
||||
|
||||
optional<gl::VertexBuffer<SymbolVertex>> vertexBuffer;
|
||||
optional<gl::IndexBuffer<gl::Triangle>> indexBuffer;
|
||||
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
void _setSprite(const std::string&, const std::shared_ptr<const SpriteImage>& = nullptr);
|
||||
void emitSpriteLoadedIfComplete();
|
||||
|
||||
const uint16_t width, height;
|
||||
const dimension width, height;
|
||||
const dimension pixelWidth, pixelHeight;
|
||||
const float pixelRatio;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user