[core] code style cleanups
- puts function definitions in a namespace ... {} rather than using namespace ...;
- remove trailing whitespace
- add trailing newline
- protect SQL statements from being formatted by clang-format
This commit is contained in:
@@ -45,9 +45,9 @@ namespace gl {
|
||||
GLsizei length,
|
||||
const GLchar *message,
|
||||
const void *userParam);
|
||||
|
||||
|
||||
template <class... Args> void mbx_trapExtension(const char *name, Args... args);
|
||||
|
||||
|
||||
void mbx_trapExtension(const char *);
|
||||
void mbx_trapExtension(const char *, GLint, const char *);
|
||||
void mbx_trapExtension(const char *, GLsizei, GLuint *);
|
||||
@@ -58,7 +58,7 @@ namespace gl {
|
||||
void mbx_trapExtension(const char *, GLuint, GLuint, GLuint, GLuint, GLint, const char *, const void*);
|
||||
void mbx_trapExtension(const char *name, GLuint array);
|
||||
#endif
|
||||
|
||||
|
||||
struct Error : ::std::runtime_error {
|
||||
Error(GLenum err, const std::string &msg) : ::std::runtime_error(msg), code(err) {};
|
||||
const GLenum code;
|
||||
|
||||
@@ -14,23 +14,23 @@ namespace mbgl {
|
||||
struct CameraOptions {
|
||||
/** Coordinate at the center of the map. */
|
||||
optional<LatLng> center;
|
||||
|
||||
|
||||
/** Padding around the interior of the view that affects the frame of
|
||||
reference for `center`. */
|
||||
optional<EdgeInsets> padding;
|
||||
|
||||
|
||||
/** Point of reference for `zoom` and `angle`, assuming an origin at the
|
||||
top-left corner of the view. */
|
||||
optional<ScreenCoordinate> anchor;
|
||||
|
||||
|
||||
/** Zero-based zoom level. Constrained to the minimum and maximum zoom
|
||||
levels. */
|
||||
optional<double> zoom;
|
||||
|
||||
|
||||
/** Bearing, measured in radians counterclockwise from true north. Wrapped
|
||||
to [−π rad, π rad). */
|
||||
optional<double> angle;
|
||||
|
||||
|
||||
/** Pitch toward the horizon measured in radians, with 0 rad resulting in a
|
||||
two-dimensional map. */
|
||||
optional<double> pitch;
|
||||
@@ -42,33 +42,33 @@ struct CameraOptions {
|
||||
struct AnimationOptions {
|
||||
/** Time to animate to the viewpoint defined herein. */
|
||||
optional<Duration> duration;
|
||||
|
||||
|
||||
/** Average velocity of a flyTo() transition, measured in screenfuls per
|
||||
second, assuming a linear timing curve.
|
||||
|
||||
|
||||
A <i>screenful</i> is the visible span in pixels. It does not correspond
|
||||
to a fixed physical distance but rather varies by zoom level. */
|
||||
optional<double> velocity;
|
||||
|
||||
|
||||
/** Zero-based zoom level at the peak of the flyTo() transition’s flight
|
||||
path. */
|
||||
optional<double> minZoom;
|
||||
|
||||
|
||||
/** The easing timing curve of the transition. */
|
||||
optional<mbgl::util::UnitBezier> easing;
|
||||
|
||||
|
||||
/** A function that is called on each frame of the transition, just before a
|
||||
screen update, except on the last frame. The first parameter indicates
|
||||
the elapsed time as a percentage of the duration. */
|
||||
std::function<void(double)> transitionFrameFn;
|
||||
|
||||
|
||||
/** A function that is called once on the last frame of the transition, just
|
||||
before the corresponding screen update. */
|
||||
std::function<void()> transitionFinishFn;
|
||||
|
||||
|
||||
/** Creates an animation with no options specified. */
|
||||
AnimationOptions() {}
|
||||
|
||||
|
||||
/** Creates an animation with the specified duration. */
|
||||
AnimationOptions(Duration d)
|
||||
: duration(d) {}
|
||||
|
||||
@@ -191,12 +191,12 @@ public:
|
||||
double left = 0; ///< Number of pixels inset from the left edge.
|
||||
double bottom = 0; ///< Number of pixels inset from the bottom edge.
|
||||
double right = 0; ///< Number of pixels inset from the right edge.
|
||||
|
||||
|
||||
EdgeInsets() {}
|
||||
|
||||
|
||||
EdgeInsets(const double t, const double l, const double b, const double r)
|
||||
: top(t), left(l), bottom(b), right(r) {}
|
||||
|
||||
|
||||
explicit operator bool() const {
|
||||
return !(std::isnan(top) || std::isnan(left) || std::isnan(bottom) || std::isnan(right))
|
||||
&& (top || left || bottom || right);
|
||||
@@ -214,7 +214,7 @@ public:
|
||||
top + o.top, left + o.left, bottom + o.bottom, right + o.right,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
ScreenCoordinate getCenter(uint16_t width, uint16_t height) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using namespace mapbox::sqlite;
|
||||
|
||||
OfflineDatabase::Statement::~Statement() {
|
||||
stmt.reset();
|
||||
stmt.clearBindings();
|
||||
@@ -36,7 +34,7 @@ OfflineDatabase::~OfflineDatabase() {
|
||||
}
|
||||
|
||||
void OfflineDatabase::connect(int flags) {
|
||||
db = std::make_unique<Database>(path.c_str(), flags);
|
||||
db = std::make_unique<mapbox::sqlite::Database>(path.c_str(), flags);
|
||||
db->setBusyTimeout(Milliseconds::max());
|
||||
db->exec("PRAGMA foreign_keys = ON");
|
||||
}
|
||||
@@ -44,7 +42,7 @@ void OfflineDatabase::connect(int flags) {
|
||||
void OfflineDatabase::ensureSchema() {
|
||||
if (path != ":memory:") {
|
||||
try {
|
||||
connect(ReadWrite);
|
||||
connect(mapbox::sqlite::ReadWrite);
|
||||
|
||||
switch (userVersion()) {
|
||||
case 0: break; // cache-only database; ok to delete
|
||||
@@ -55,7 +53,7 @@ void OfflineDatabase::ensureSchema() {
|
||||
}
|
||||
|
||||
removeExisting();
|
||||
connect(ReadWrite | Create);
|
||||
connect(mapbox::sqlite::ReadWrite | mapbox::sqlite::Create);
|
||||
} catch (mapbox::sqlite::Exception& ex) {
|
||||
if (ex.code != SQLITE_CANTOPEN && ex.code != SQLITE_NOTADB) {
|
||||
Log::Error(Event::Database, "Unexpected error connecting to database: %s", ex.what());
|
||||
@@ -66,7 +64,7 @@ void OfflineDatabase::ensureSchema() {
|
||||
if (ex.code == SQLITE_NOTADB) {
|
||||
removeExisting();
|
||||
}
|
||||
connect(ReadWrite | Create);
|
||||
connect(mapbox::sqlite::ReadWrite | mapbox::sqlite::Create);
|
||||
} catch (...) {
|
||||
Log::Error(Event::Database, "Unexpected error creating database: %s", util::toString(std::current_exception()).c_str());
|
||||
throw;
|
||||
@@ -77,7 +75,7 @@ void OfflineDatabase::ensureSchema() {
|
||||
try {
|
||||
#include "offline_schema.cpp.include"
|
||||
|
||||
connect(ReadWrite | Create);
|
||||
connect(mapbox::sqlite::ReadWrite | mapbox::sqlite::Create);
|
||||
|
||||
// If you change the schema you must write a migration from the previous version.
|
||||
db->exec("PRAGMA auto_vacuum = INCREMENTAL");
|
||||
@@ -178,18 +176,22 @@ std::pair<bool, uint64_t> OfflineDatabase::putInternal(const Resource& resource,
|
||||
}
|
||||
|
||||
optional<std::pair<Response, uint64_t>> OfflineDatabase::getResource(const Resource& resource) {
|
||||
// clang-format off
|
||||
Statement accessedStmt = getStatement(
|
||||
"UPDATE resources SET accessed = ?1 WHERE url = ?2");
|
||||
// clang-format on
|
||||
|
||||
accessedStmt->bind(1, util::now());
|
||||
accessedStmt->bind(2, resource.url);
|
||||
accessedStmt->run();
|
||||
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
// 0 1 2 3 4
|
||||
"SELECT etag, expires, modified, data, compressed "
|
||||
"FROM resources "
|
||||
"WHERE url = ?");
|
||||
// clang-format on
|
||||
|
||||
stmt->bind(1, resource.url);
|
||||
|
||||
@@ -223,11 +225,13 @@ bool OfflineDatabase::putResource(const Resource& resource,
|
||||
const std::string& data,
|
||||
bool compressed) {
|
||||
if (response.notModified) {
|
||||
// clang-format off
|
||||
Statement update = getStatement(
|
||||
"UPDATE resources "
|
||||
"SET accessed = ?1, "
|
||||
" expires = ?2 "
|
||||
"WHERE url = ?3 ");
|
||||
// clang-format on
|
||||
|
||||
update->bind(1, util::now());
|
||||
update->bind(2, response.expires);
|
||||
@@ -240,8 +244,9 @@ bool OfflineDatabase::putResource(const Resource& resource,
|
||||
|
||||
// Begin an immediate-mode transaction to ensure that two writers do not attempt
|
||||
// to INSERT a resource at the same moment.
|
||||
Transaction transaction(*db, Transaction::Immediate);
|
||||
mapbox::sqlite::Transaction transaction(*db, mapbox::sqlite::Transaction::Immediate);
|
||||
|
||||
// clang-format off
|
||||
Statement update = getStatement(
|
||||
"UPDATE resources "
|
||||
"SET kind = ?1, "
|
||||
@@ -252,6 +257,7 @@ bool OfflineDatabase::putResource(const Resource& resource,
|
||||
" data = ?6, "
|
||||
" compressed = ?7 "
|
||||
"WHERE url = ?8 ");
|
||||
// clang-format on
|
||||
|
||||
update->bind(1, int(resource.kind));
|
||||
update->bind(2, response.etag);
|
||||
@@ -274,9 +280,11 @@ bool OfflineDatabase::putResource(const Resource& resource,
|
||||
return false;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Statement insert = getStatement(
|
||||
"INSERT INTO resources (url, kind, etag, expires, modified, accessed, data, compressed) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8) ");
|
||||
// clang-format on
|
||||
|
||||
insert->bind(1, resource.url);
|
||||
insert->bind(2, int(resource.kind));
|
||||
@@ -300,6 +308,7 @@ bool OfflineDatabase::putResource(const Resource& resource,
|
||||
}
|
||||
|
||||
optional<std::pair<Response, uint64_t>> OfflineDatabase::getTile(const Resource::TileData& tile) {
|
||||
// clang-format off
|
||||
Statement accessedStmt = getStatement(
|
||||
"UPDATE tiles "
|
||||
"SET accessed = ?1 "
|
||||
@@ -308,6 +317,7 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getTile(const Resource:
|
||||
" AND x = ?4 "
|
||||
" AND y = ?5 "
|
||||
" AND z = ?6 ");
|
||||
// clang-format on
|
||||
|
||||
accessedStmt->bind(1, util::now());
|
||||
accessedStmt->bind(2, tile.urlTemplate);
|
||||
@@ -317,6 +327,7 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getTile(const Resource:
|
||||
accessedStmt->bind(6, tile.z);
|
||||
accessedStmt->run();
|
||||
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
// 0 1 2 3 4
|
||||
"SELECT etag, expires, modified, data, compressed "
|
||||
@@ -326,6 +337,7 @@ optional<std::pair<Response, uint64_t>> OfflineDatabase::getTile(const Resource:
|
||||
" AND x = ?3 "
|
||||
" AND y = ?4 "
|
||||
" AND z = ?5 ");
|
||||
// clang-format on
|
||||
|
||||
stmt->bind(1, tile.urlTemplate);
|
||||
stmt->bind(2, tile.pixelRatio);
|
||||
@@ -363,6 +375,7 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
|
||||
const std::string& data,
|
||||
bool compressed) {
|
||||
if (response.notModified) {
|
||||
// clang-format off
|
||||
Statement update = getStatement(
|
||||
"UPDATE tiles "
|
||||
"SET accessed = ?1, "
|
||||
@@ -372,6 +385,7 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
|
||||
" AND x = ?5 "
|
||||
" AND y = ?6 "
|
||||
" AND z = ?7 ");
|
||||
// clang-format on
|
||||
|
||||
update->bind(1, util::now());
|
||||
update->bind(2, response.expires);
|
||||
@@ -388,8 +402,9 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
|
||||
|
||||
// Begin an immediate-mode transaction to ensure that two writers do not attempt
|
||||
// to INSERT a resource at the same moment.
|
||||
Transaction transaction(*db, Transaction::Immediate);
|
||||
mapbox::sqlite::Transaction transaction(*db, mapbox::sqlite::Transaction::Immediate);
|
||||
|
||||
// clang-format off
|
||||
Statement update = getStatement(
|
||||
"UPDATE tiles "
|
||||
"SET modified = ?1, "
|
||||
@@ -403,6 +418,7 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
|
||||
" AND x = ?9 "
|
||||
" AND y = ?10 "
|
||||
" AND z = ?11 ");
|
||||
// clang-format on
|
||||
|
||||
update->bind(1, response.modified);
|
||||
update->bind(2, response.etag);
|
||||
@@ -428,9 +444,11 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
|
||||
return false;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Statement insert = getStatement(
|
||||
"INSERT INTO tiles (url_template, pixel_ratio, x, y, z, modified, etag, expires, accessed, data, compressed) "
|
||||
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11) ");
|
||||
// clang-format on
|
||||
|
||||
insert->bind(1, tile.urlTemplate);
|
||||
insert->bind(2, tile.pixelRatio);
|
||||
@@ -457,8 +475,10 @@ bool OfflineDatabase::putTile(const Resource::TileData& tile,
|
||||
}
|
||||
|
||||
std::vector<OfflineRegion> OfflineDatabase::listRegions() {
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"SELECT id, definition, description FROM regions");
|
||||
// clang-format on
|
||||
|
||||
std::vector<OfflineRegion> result;
|
||||
|
||||
@@ -474,9 +494,11 @@ std::vector<OfflineRegion> OfflineDatabase::listRegions() {
|
||||
|
||||
OfflineRegion OfflineDatabase::createRegion(const OfflineRegionDefinition& definition,
|
||||
const OfflineRegionMetadata& metadata) {
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"INSERT INTO regions (definition, description) "
|
||||
"VALUES (?1, ?2) ");
|
||||
// clang-format on
|
||||
|
||||
stmt->bind(1, encodeOfflineRegionDefinition(definition));
|
||||
stmt->bindBlob(2, metadata);
|
||||
@@ -486,8 +508,10 @@ OfflineRegion OfflineDatabase::createRegion(const OfflineRegionDefinition& defin
|
||||
}
|
||||
|
||||
void OfflineDatabase::deleteRegion(OfflineRegion&& region) {
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"DELETE FROM regions WHERE id = ?");
|
||||
// clang-format on
|
||||
|
||||
stmt->bind(1, region.getID());
|
||||
stmt->run();
|
||||
@@ -525,6 +549,7 @@ uint64_t OfflineDatabase::putRegionResource(int64_t regionID, const Resource& re
|
||||
|
||||
bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
if (resource.kind == Resource::Kind::Tile) {
|
||||
// clang-format off
|
||||
Statement insert = getStatement(
|
||||
"INSERT OR IGNORE INTO region_tiles (region_id, tile_id) "
|
||||
"SELECT ?1, tiles.id "
|
||||
@@ -534,6 +559,7 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
" AND x = ?4 "
|
||||
" AND y = ?5 "
|
||||
" AND z = ?6 ");
|
||||
// clang-format on
|
||||
|
||||
const Resource::TileData& tile = *resource.tileData;
|
||||
insert->bind(1, regionID);
|
||||
@@ -548,6 +574,7 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Statement select = getStatement(
|
||||
"SELECT region_id "
|
||||
"FROM region_tiles, tiles "
|
||||
@@ -558,6 +585,7 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
" AND y = ?5 "
|
||||
" AND z = ?6 "
|
||||
"LIMIT 1 ");
|
||||
// clang-format on
|
||||
|
||||
select->bind(1, regionID);
|
||||
select->bind(2, tile.urlTemplate);
|
||||
@@ -567,11 +595,13 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
select->bind(6, tile.z);
|
||||
return !select->run();
|
||||
} else {
|
||||
// clang-format off
|
||||
Statement insert = getStatement(
|
||||
"INSERT OR IGNORE INTO region_resources (region_id, resource_id) "
|
||||
"SELECT ?1, resources.id "
|
||||
"FROM resources "
|
||||
"WHERE resources.url = ?2 ");
|
||||
// clang-format on
|
||||
|
||||
insert->bind(1, regionID);
|
||||
insert->bind(2, resource.url);
|
||||
@@ -581,12 +611,14 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Statement select = getStatement(
|
||||
"SELECT region_id "
|
||||
"FROM region_resources, resources "
|
||||
"WHERE region_id != ?1 "
|
||||
" AND resources.url = ?2 "
|
||||
"LIMIT 1 ");
|
||||
// clang-format on
|
||||
|
||||
select->bind(1, regionID);
|
||||
select->bind(2, resource.url);
|
||||
@@ -595,8 +627,10 @@ bool OfflineDatabase::markUsed(int64_t regionID, const Resource& resource) {
|
||||
}
|
||||
|
||||
OfflineRegionDefinition OfflineDatabase::getRegionDefinition(int64_t regionID) {
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"SELECT definition FROM regions WHERE id = ?1");
|
||||
// clang-format on
|
||||
|
||||
stmt->bind(1, regionID);
|
||||
stmt->run();
|
||||
@@ -619,22 +653,26 @@ OfflineRegionStatus OfflineDatabase::getRegionCompletedStatus(int64_t regionID)
|
||||
}
|
||||
|
||||
std::pair<int64_t, int64_t> OfflineDatabase::getCompletedResourceCountAndSize(int64_t regionID) {
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"SELECT COUNT(*), SUM(LENGTH(data)) "
|
||||
"FROM region_resources, resources "
|
||||
"WHERE region_id = ?1 "
|
||||
"AND resource_id = resources.id ");
|
||||
// clang-format on
|
||||
stmt->bind(1, regionID);
|
||||
stmt->run();
|
||||
return { stmt->get<int64_t>(0), stmt->get<int64_t>(1) };
|
||||
}
|
||||
|
||||
std::pair<int64_t, int64_t> OfflineDatabase::getCompletedTileCountAndSize(int64_t regionID) {
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"SELECT COUNT(*), SUM(LENGTH(data)) "
|
||||
"FROM region_tiles, tiles "
|
||||
"WHERE region_id = ?1 "
|
||||
"AND tile_id = tiles.id ");
|
||||
// clang-format on
|
||||
stmt->bind(1, regionID);
|
||||
stmt->run();
|
||||
return { stmt->get<int64_t>(0), stmt->get<int64_t>(1) };
|
||||
@@ -668,6 +706,7 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize) {
|
||||
// The addition of pageSize is a fudge factor to account for non `data` column
|
||||
// size, and because pages can get fragmented on the database.
|
||||
while (usedSize() + neededFreeSize + pageSize > maximumCacheSize) {
|
||||
// clang-format off
|
||||
Statement stmt1 = getStatement(
|
||||
"DELETE FROM resources "
|
||||
"WHERE id IN ( "
|
||||
@@ -677,10 +716,12 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize) {
|
||||
" WHERE resource_id IS NULL "
|
||||
" ORDER BY accessed ASC LIMIT ?1 "
|
||||
") ");
|
||||
// clang-format on
|
||||
stmt1->bind(1, 50);
|
||||
stmt1->run();
|
||||
uint64_t changes1 = db->changes();
|
||||
|
||||
// clang-format off
|
||||
Statement stmt2 = getStatement(
|
||||
"DELETE FROM tiles "
|
||||
"WHERE id IN ( "
|
||||
@@ -690,6 +731,7 @@ bool OfflineDatabase::evict(uint64_t neededFreeSize) {
|
||||
" WHERE tile_id IS NULL "
|
||||
" ORDER BY accessed ASC LIMIT ?1 "
|
||||
") ");
|
||||
// clang-format on
|
||||
stmt2->bind(1, 50);
|
||||
stmt2->run();
|
||||
uint64_t changes2 = db->changes();
|
||||
@@ -727,11 +769,13 @@ uint64_t OfflineDatabase::getOfflineMapboxTileCount() {
|
||||
return *offlineMapboxTileCount;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
Statement stmt = getStatement(
|
||||
"SELECT COUNT(DISTINCT id) "
|
||||
"FROM region_tiles, tiles "
|
||||
"WHERE tile_id = tiles.id "
|
||||
"AND url_template LIKE 'mapbox://%' ");
|
||||
// clang-format on
|
||||
|
||||
stmt->run();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <mbgl/platform/default/settings_json.hpp>
|
||||
#include <fstream>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
Settings_JSON::Settings_JSON() { load(); }
|
||||
|
||||
@@ -37,3 +37,5 @@ void Settings_JSON::clear() {
|
||||
pitch = 0;
|
||||
debug = 0;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -6,4 +6,4 @@ extern NSString * const MBXMapboxAccessTokenDefaultsKey;
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
@@ -6,4 +6,4 @@ extern NSString * const MBXMapboxAccessTokenDefaultsKey;
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace CSSColorParser;
|
||||
namespace CSSColorParser {
|
||||
|
||||
// http://www.w3.org/TR/css3-color/
|
||||
struct NamedColor { const char *const name; const Color color; };
|
||||
@@ -180,7 +180,7 @@ std::vector<std::string> split(const std::string& s, char delim) {
|
||||
return elems;
|
||||
}
|
||||
|
||||
Color CSSColorParser::parse(const std::string& css_str) {
|
||||
Color parse(const std::string& css_str) {
|
||||
std::string str = css_str;
|
||||
|
||||
// Remove all whitespace, not compliant, but should just be more accepting.
|
||||
@@ -288,3 +288,5 @@ Color CSSColorParser::parse(const std::string& css_str) {
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace CSSColorParser
|
||||
|
||||
@@ -200,7 +200,7 @@ void AnnotationManager::addIcon(const std::string& name, std::shared_ptr<const S
|
||||
spriteStore.setSprite(name, sprite);
|
||||
spriteAtlas.updateDirty();
|
||||
}
|
||||
|
||||
|
||||
void AnnotationManager::removeIcon(const std::string& name) {
|
||||
spriteStore.removeSprite(name);
|
||||
spriteAtlas.updateDirty();
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#include <climits>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void CircleVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey) {
|
||||
vertex_type *vertices = static_cast<vertex_type *>(addElement());
|
||||
vertices[0] = (x * 2) + ((ex + 1) / 2);
|
||||
vertices[1] = (y * 2) + ((ey + 1) / 2);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) {
|
||||
uint16_t *coords = nullptr;
|
||||
@@ -40,3 +40,5 @@ void DebugFontBuffer::addText(const char *text, double left, double baseline, do
|
||||
left += glyph.width * scale;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <mbgl/geometry/elements_buffer.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void TriangleElementsBuffer::add(element_type a, element_type b, element_type c) {
|
||||
element_type *elements = static_cast<element_type *>(addElement());
|
||||
@@ -14,3 +14,5 @@ void LineElementsBuffer::add(element_type a, element_type b) {
|
||||
elements[0] = a;
|
||||
elements[1] = b;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#include <climits>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void FillVertexBuffer::add(vertex_type x, vertex_type y) {
|
||||
vertex_type *vertices = static_cast<vertex_type *>(addElement());
|
||||
vertices[0] = x;
|
||||
vertices[1] = y;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_)
|
||||
: width(width_),
|
||||
@@ -197,3 +197,5 @@ void GlyphAtlas::bind(gl::ObjectStore& store) {
|
||||
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
LineAtlas::LineAtlas(GLsizei w, GLsizei h)
|
||||
: width(w),
|
||||
@@ -171,3 +171,5 @@ void LineAtlas::bind(gl::ObjectStore& store) {
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
GLsizei LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, bool tx, bool ty, int8_t dir, int32_t linesofar) {
|
||||
GLsizei idx = index();
|
||||
@@ -34,3 +34,5 @@ GLsizei LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey,
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace mbgl {
|
||||
void mbx_trapExtension(const char *, GLenum, GLuint, GLsizei, const GLchar *) { }
|
||||
void mbx_trapExtension(const char *, GLDEBUGPROC, const void *) { }
|
||||
void mbx_trapExtension(const char *, GLuint, GLuint, GLuint, GLuint, GLint, const char *, const void*) { }
|
||||
|
||||
|
||||
void mbx_trapExtension(const char *name, GLuint array) {
|
||||
if(strncasecmp(name, "glBindVertexArray", 17) == 0) {
|
||||
currentVertexArray = array;
|
||||
@@ -188,7 +188,7 @@ void mbx_glBufferData(GLenum target,
|
||||
}
|
||||
std::cout << "GL glBufferData: " << currentBinding << " using " << bufferBindingToSizeMap[currentBinding] << " bytes current total " << currentUsedBufferBytes << " high water mark " << largestAmountUsedSoFar << "\n";
|
||||
lock.unlock();
|
||||
|
||||
|
||||
glBufferData(target, size, data, usage);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ bool Map::isPanning() const {
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
||||
CameraOptions Map::getCameraOptions(optional<EdgeInsets> padding) const {
|
||||
return impl->transform.getCameraOptions(padding);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
/** Converts the given angle (in radians) to be numerically close to the anchor angle, allowing it to be interpolated properly without sudden jumps. */
|
||||
static double _normalizeAngle(double angle, double anchorAngle)
|
||||
@@ -117,24 +117,24 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
|
||||
|
||||
ScreenCoordinate center = getScreenCoordinate(padding);
|
||||
center.y = state.height - center.y;
|
||||
|
||||
|
||||
// Constrain camera options.
|
||||
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
|
||||
const double scale = state.zoomScale(zoom);
|
||||
pitch = util::clamp(pitch, 0., util::PITCH_MAX);
|
||||
|
||||
|
||||
Update update = state.getZoom() == zoom ? Update::Repaint : Update::RecalculateStyle;
|
||||
|
||||
|
||||
// Minimize rotation by taking the shorter path around the circle.
|
||||
angle = _normalizeAngle(angle, state.angle);
|
||||
state.angle = _normalizeAngle(state.angle, angle);
|
||||
|
||||
Duration duration = animation.duration ? *animation.duration : Duration::zero();
|
||||
|
||||
|
||||
const double startWorldSize = state.worldSize();
|
||||
state.Bc = startWorldSize / util::DEGREES_MAX;
|
||||
state.Cc = startWorldSize / util::M2PI;
|
||||
|
||||
|
||||
const double startScale = state.scale;
|
||||
const double startAngle = state.angle;
|
||||
const double startPitch = state.pitch;
|
||||
@@ -147,14 +147,14 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
|
||||
LatLng frameLatLng = state.unproject(framePoint, startWorldSize);
|
||||
double frameScale = util::interpolate(startScale, scale, t);
|
||||
state.setLatLngZoom(frameLatLng, state.scaleZoom(frameScale));
|
||||
|
||||
|
||||
if (angle != startAngle) {
|
||||
state.angle = util::wrap(util::interpolate(startAngle, angle, t), -M_PI, M_PI);
|
||||
}
|
||||
if (pitch != startPitch) {
|
||||
state.pitch = util::interpolate(startPitch, pitch, t);
|
||||
}
|
||||
|
||||
|
||||
if (padding) {
|
||||
state.moveLatLng(frameLatLng, center);
|
||||
}
|
||||
@@ -163,11 +163,11 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
|
||||
}
|
||||
|
||||
/** This method implements an “optimal path” animation, as detailed in:
|
||||
|
||||
|
||||
Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and
|
||||
panning.” INFOVIS ’03. pp. 15–22.
|
||||
<https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5>.
|
||||
|
||||
|
||||
Where applicable, local variable documentation begins with the associated
|
||||
variable or function in van Wijk (2003). */
|
||||
void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &animation) {
|
||||
@@ -179,7 +179,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
if (!latLng || std::isnan(zoom)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Determine endpoints.
|
||||
EdgeInsets padding;
|
||||
if (camera.padding) padding = *camera.padding;
|
||||
@@ -191,19 +191,19 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
|
||||
ScreenCoordinate center = getScreenCoordinate(padding);
|
||||
center.y = state.height - center.y;
|
||||
|
||||
|
||||
// Constrain camera options.
|
||||
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
|
||||
pitch = util::clamp(pitch, 0., util::PITCH_MAX);
|
||||
|
||||
|
||||
// Minimize rotation by taking the shorter path around the circle.
|
||||
angle = _normalizeAngle(angle, state.angle);
|
||||
state.angle = _normalizeAngle(state.angle, angle);
|
||||
|
||||
|
||||
const double startZoom = state.scaleZoom(state.scale);
|
||||
const double startAngle = state.angle;
|
||||
const double startPitch = state.pitch;
|
||||
|
||||
|
||||
/// w₀: Initial visible span, measured in pixels at the initial scale.
|
||||
/// Known henceforth as a <i>screenful</i>.
|
||||
double w0 = padding ? std::max(state.width, state.height)
|
||||
@@ -215,11 +215,11 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
/// Length of the flight path as projected onto the ground plane, measured
|
||||
/// in pixels from the world image origin at the initial scale.
|
||||
double u1 = ::hypot((endPoint - startPoint).x, (endPoint - startPoint).y);
|
||||
|
||||
|
||||
/** ρ: The relative amount of zooming that takes place along the flight
|
||||
path. A high value maximizes zooming for an exaggerated animation, while
|
||||
a low value minimizes zooming for something closer to easeTo().
|
||||
|
||||
|
||||
1.42 is the average value selected by participants in the user study in
|
||||
van Wijk (2003). A value of 6<sup>¼</sup> would be equivalent to the
|
||||
root mean squared average velocity, V<sub>RMS</sub>. A value of 1 would
|
||||
@@ -235,16 +235,16 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
}
|
||||
/// ρ²
|
||||
double rho2 = rho * rho;
|
||||
|
||||
|
||||
/** rᵢ: Returns the zoom-out factor at one end of the animation.
|
||||
|
||||
|
||||
@param i 0 for the ascent or 1 for the descent. */
|
||||
auto r = [=](double i) {
|
||||
/// bᵢ
|
||||
double b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
|
||||
return std::log(std::sqrt(b * b + 1) - b);
|
||||
};
|
||||
|
||||
|
||||
// When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
|
||||
bool isClose = std::abs(u1) < 0.000001;
|
||||
// Perform a more or less instantaneous transition if the path is too short.
|
||||
@@ -252,12 +252,12 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
easeTo(camera, animation);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/// r₀: Zoom-out factor during ascent.
|
||||
double r0 = r(0);
|
||||
/** w(s): Returns the visible span on the ground, measured in pixels with
|
||||
respect to the initial scale.
|
||||
|
||||
|
||||
Assumes an angular field of view of 2 arctan ½ ≈ 53°. */
|
||||
auto w = [=](double s) {
|
||||
return (isClose ? std::exp((w1 < w0 ? -1 : 1) * rho * s)
|
||||
@@ -273,7 +273,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
/// S: Total length of the flight path, measured in ρ-screenfuls.
|
||||
double S = (isClose ? (std::abs(std::log(w1 / w0)) / rho)
|
||||
: ((r(1) - r0) / rho));
|
||||
|
||||
|
||||
Duration duration;
|
||||
if (animation.duration) {
|
||||
duration = *animation.duration;
|
||||
@@ -290,36 +290,36 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
|
||||
jumpTo(camera);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const double startWorldSize = state.worldSize();
|
||||
state.Bc = startWorldSize / util::DEGREES_MAX;
|
||||
state.Cc = startWorldSize / util::M2PI;
|
||||
|
||||
|
||||
state.panning = true;
|
||||
state.scaling = true;
|
||||
state.rotating = angle != startAngle;
|
||||
|
||||
|
||||
startTransition(camera, animation, [=](double k) {
|
||||
/// s: The distance traveled along the flight path, measured in
|
||||
/// ρ-screenfuls.
|
||||
double s = k * S;
|
||||
double us = u(s);
|
||||
|
||||
|
||||
// Calculate the current point and zoom level along the flight path.
|
||||
Point<double> framePoint = util::interpolate(startPoint, endPoint, us);
|
||||
double frameZoom = startZoom + state.scaleZoom(1 / w(s));
|
||||
|
||||
|
||||
// Convert to geographic coordinates and set the new viewpoint.
|
||||
LatLng frameLatLng = state.unproject(framePoint, startWorldSize);
|
||||
state.setLatLngZoom(frameLatLng, frameZoom);
|
||||
|
||||
|
||||
if (angle != startAngle) {
|
||||
state.angle = util::wrap(util::interpolate(startAngle, angle, k), -M_PI, M_PI);
|
||||
}
|
||||
if (pitch != startPitch) {
|
||||
state.pitch = util::interpolate(startPitch, pitch, k);
|
||||
}
|
||||
|
||||
|
||||
if (padding) {
|
||||
state.moveLatLng(frameLatLng, center);
|
||||
}
|
||||
@@ -474,7 +474,7 @@ void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate&
|
||||
center.x = first.x + std::cos(rotateAngle) * heightOffset;
|
||||
center.y = first.y + std::sin(rotateAngle) * heightOffset;
|
||||
}
|
||||
|
||||
|
||||
CameraOptions camera;
|
||||
camera.angle = state.angle + util::angle_between(first - center, second - center);
|
||||
easeTo(camera, duration);
|
||||
@@ -561,7 +561,7 @@ void Transform::startTransition(const CameraOptions& camera,
|
||||
if (transitionFinishFn) {
|
||||
transitionFinishFn();
|
||||
}
|
||||
|
||||
|
||||
bool isAnimated = duration != Duration::zero();
|
||||
if (callback) {
|
||||
callback(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange);
|
||||
@@ -587,9 +587,9 @@ void Transform::startTransition(const CameraOptions& camera,
|
||||
util::UnitBezier ease = animation.easing ? *animation.easing : util::DEFAULT_TRANSITION_EASE;
|
||||
result = frame(ease.solve(t, 0.001));
|
||||
}
|
||||
|
||||
|
||||
if (anchor) state.moveLatLng(anchorLatLng, *anchor);
|
||||
|
||||
|
||||
// At t = 1.0, a DidChangeAnimated notification should be sent from finish().
|
||||
if (t < 1.0) {
|
||||
if (animation.transitionFrameFn) {
|
||||
@@ -620,7 +620,7 @@ void Transform::startTransition(const CameraOptions& camera,
|
||||
callback(isAnimated ? MapChangeRegionDidChangeAnimated : MapChangeRegionDidChange);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (!isAnimated) {
|
||||
transitionFrameFn(Clock::now());
|
||||
}
|
||||
@@ -665,3 +665,5 @@ LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const
|
||||
flippedPoint.y = state.height - flippedPoint.y;
|
||||
return state.screenCoordinateToLatLng(flippedPoint).wrapped();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
// Camera
|
||||
/** Returns the current camera options. */
|
||||
CameraOptions getCameraOptions(optional<EdgeInsets>) const;
|
||||
|
||||
|
||||
/** Instantaneously, synchronously applies the given camera options. */
|
||||
void jumpTo(const CameraOptions&);
|
||||
/** Asynchronously transitions all specified camera options linearly along
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
void flyTo(const CameraOptions&, const AnimationOptions& = {});
|
||||
|
||||
// Position
|
||||
|
||||
|
||||
/** Pans the map by the given amount.
|
||||
@param offset The distance to pan the map by, measured in pixels from
|
||||
top to bottom and from left to right. */
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
bool isRotating() const { return state.isRotating(); }
|
||||
bool isScaling() const { return state.isScaling(); }
|
||||
bool isPanning() const { return state.isPanning(); }
|
||||
|
||||
|
||||
// Conversion and projection
|
||||
ScreenCoordinate latLngToScreenCoordinate(const LatLng&) const;
|
||||
LatLng screenCoordinateToLatLng(const ScreenCoordinate&) const;
|
||||
|
||||
@@ -336,10 +336,10 @@ void TransformState::setLatLngZoom(const LatLng &latLng, double zoom) {
|
||||
const double newWorldSize = newScale * util::tileSize;
|
||||
Bc = newWorldSize / util::DEGREES_MAX;
|
||||
Cc = newWorldSize / util::M2PI;
|
||||
|
||||
|
||||
const double m = 1 - 1e-15;
|
||||
const double f = util::clamp(std::sin(util::DEG2RAD * latLng.latitude), -m, m);
|
||||
|
||||
|
||||
ScreenCoordinate point = {
|
||||
-latLng.longitude * Bc,
|
||||
0.5 * Cc * std::log((1 + f) / (1 - f)),
|
||||
@@ -351,7 +351,7 @@ void TransformState::setScalePoint(const double newScale, const ScreenCoordinate
|
||||
double constrainedScale = newScale;
|
||||
ScreenCoordinate constrainedPoint = point;
|
||||
constrain(constrainedScale, constrainedPoint.x, constrainedPoint.y);
|
||||
|
||||
|
||||
scale = constrainedScale;
|
||||
x = constrainedPoint.x;
|
||||
y = constrainedPoint.y;
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
|
||||
mat4 coordinatePointMatrix(double z) const;
|
||||
mat4 getPixelMatrix() const;
|
||||
|
||||
|
||||
/** Recenter the map so that the given coordinate is located at the given
|
||||
point on screen. */
|
||||
void moveLatLng(const LatLng&, const ScreenCoordinate&);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
DebugBucket::DebugBucket(const OverscaledTileID& id,
|
||||
const bool renderable_,
|
||||
@@ -51,3 +51,5 @@ void DebugBucket::drawPoints(PlainShader& shader, gl::ObjectStore& store) {
|
||||
MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, (GLsizei)(fontBuffer.index())));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <mbgl/renderer/frame_history.hpp>
|
||||
#include <mbgl/math/minmax.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
FrameHistory::FrameHistory() {
|
||||
changeOpacities.fill(0);
|
||||
@@ -110,3 +110,5 @@ void FrameHistory::bind(gl::ObjectStore& store) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/gl/debugging.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
|
||||
void Painter::drawClippingMasks(const std::map<UnwrappedTileID, ClipID>& stencils) {
|
||||
@@ -38,3 +38,5 @@ void Painter::drawClippingMasks(const std::map<UnwrappedTileID, ClipID>& stencil
|
||||
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <mbgl/gl/gl_helper.hpp>
|
||||
#include <mbgl/util/color.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void Painter::renderTileDebug(const RenderTile& tile) {
|
||||
MBGL_DEBUG_GROUP(std::string { "debug " } + util::toString(tile.id));
|
||||
@@ -118,3 +118,5 @@ void Painter::renderClipMasks() {
|
||||
MBGL_CHECK_ERROR(glDrawPixels(fbSize[0], fbSize[1], GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
|
||||
#endif // GL_ES_VERSION_2_0
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -98,7 +98,7 @@ void Painter::renderLine(LineBucket& bucket,
|
||||
} else if (!properties.linePattern.value.from.empty()) {
|
||||
optional<SpriteAtlasPosition> imagePosA = spriteAtlas->getPosition(properties.linePattern.value.from, true);
|
||||
optional<SpriteAtlasPosition> imagePosB = spriteAtlas->getPosition(properties.linePattern.value.to, true);
|
||||
|
||||
|
||||
if (!imagePosA || !imagePosB)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <mbgl/renderer/render_tile.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -370,7 +370,7 @@ void SymbolBucket::addFeature(const GeometryCollection &lines,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SymbolBucket::anchorIsTooClose(const std::u32string &text, const float repeatDistance, Anchor &anchor) {
|
||||
if (compareText.find(text) == compareText.end()) {
|
||||
compareText.emplace(text, Anchors());
|
||||
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
const size_t index);
|
||||
bool anchorIsTooClose(const std::u32string &text, const float repeatDistance, Anchor &anchor);
|
||||
std::map<std::u32string, std::vector<Anchor>> compareText;
|
||||
|
||||
|
||||
void addToDebugBuffers(CollisionTile &collisionTile);
|
||||
|
||||
void swapRenderData() override;
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <mbgl/shader/circle.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::circle;
|
||||
namespace mbgl {
|
||||
|
||||
CircleShader::CircleShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store) {
|
||||
: Shader(shaders::circle::name, shaders::circle::vertex, shaders::circle::fragment, store) {
|
||||
}
|
||||
|
||||
void CircleShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 4, offset));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
#include <mbgl/shader/collisionbox.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::collisionbox;
|
||||
namespace mbgl {
|
||||
|
||||
CollisionBoxShader::CollisionBoxShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store)
|
||||
, a_extrude(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_extrude")))
|
||||
, a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
: Shader(shaders::collisionbox::name,
|
||||
shaders::collisionbox::vertex,
|
||||
shaders::collisionbox::fragment,
|
||||
store),
|
||||
a_extrude(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_extrude"))),
|
||||
a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
}
|
||||
|
||||
void CollisionBoxShader::bind(GLbyte *offset) {
|
||||
@@ -25,3 +27,5 @@ void CollisionBoxShader::bind(GLbyte *offset) {
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 2, GL_UNSIGNED_BYTE, false, stride, offset + 8));
|
||||
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
#include <mbgl/shader/icon.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::icon;
|
||||
namespace mbgl {
|
||||
|
||||
IconShader::IconShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store)
|
||||
, a_offset(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")))
|
||||
, a_data1(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")))
|
||||
, a_data2(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2"))) {
|
||||
: Shader(shaders::icon::name, shaders::icon::vertex, shaders::icon::fragment, store),
|
||||
a_offset(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset"))),
|
||||
a_data1(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1"))),
|
||||
a_data2(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2"))) {
|
||||
}
|
||||
|
||||
void IconShader::bind(GLbyte* offset) {
|
||||
@@ -28,3 +27,5 @@ void IconShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
#include <mbgl/shader/line.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::line;
|
||||
namespace mbgl {
|
||||
|
||||
LineShader::LineShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store)
|
||||
, a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
: Shader(shaders::line::name, shaders::line::vertex, shaders::line::fragment, store),
|
||||
a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
}
|
||||
|
||||
void LineShader::bind(GLbyte* offset) {
|
||||
@@ -18,3 +17,5 @@ void LineShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
#include <mbgl/shader/linepattern.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::linepattern;
|
||||
namespace mbgl {
|
||||
|
||||
LinepatternShader::LinepatternShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store)
|
||||
, a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
: Shader(shaders::linepattern::name,
|
||||
shaders::linepattern::vertex,
|
||||
shaders::linepattern::fragment,
|
||||
store),
|
||||
a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
}
|
||||
|
||||
void LinepatternShader::bind(GLbyte* offset) {
|
||||
@@ -18,3 +20,5 @@ void LinepatternShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
#include <mbgl/shader/linesdfpattern.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::linesdfpattern;
|
||||
namespace mbgl {
|
||||
|
||||
LineSDFShader::LineSDFShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store)
|
||||
, a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
: Shader(shaders::linesdfpattern::name,
|
||||
shaders::linesdfpattern::vertex,
|
||||
shaders::linesdfpattern::fragment,
|
||||
store),
|
||||
a_data(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data"))) {
|
||||
}
|
||||
|
||||
void LineSDFShader::bind(GLbyte* offset) {
|
||||
@@ -18,3 +20,5 @@ void LineSDFShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <mbgl/shader/outline.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::outline;
|
||||
namespace mbgl {
|
||||
|
||||
OutlineShader::OutlineShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store) {
|
||||
: Shader(shaders::outline::name, shaders::outline::vertex, shaders::outline::fragment, store) {
|
||||
}
|
||||
|
||||
void OutlineShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,18 @@
|
||||
#include <mbgl/shader/outlinepattern.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::outlinepattern;
|
||||
namespace mbgl {
|
||||
|
||||
OutlinePatternShader::OutlinePatternShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store) {
|
||||
: Shader(shaders::outlinepattern::name,
|
||||
shaders::outlinepattern::vertex,
|
||||
shaders::outlinepattern::fragment,
|
||||
store) {
|
||||
}
|
||||
|
||||
void OutlinePatternShader::bind(GLbyte *offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <mbgl/shader/pattern.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::pattern;
|
||||
namespace mbgl {
|
||||
|
||||
PatternShader::PatternShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store) {
|
||||
: Shader(shaders::pattern::name, shaders::pattern::vertex, shaders::pattern::fragment, store) {
|
||||
}
|
||||
|
||||
void PatternShader::bind(GLbyte *offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <mbgl/shader/fill.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::fill;
|
||||
namespace mbgl {
|
||||
|
||||
PlainShader::PlainShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store) {
|
||||
: Shader(shaders::fill::name, shaders::fill::vertex, shaders::fill::fragment, store) {
|
||||
}
|
||||
|
||||
void PlainShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <mbgl/shader/raster.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::raster;
|
||||
namespace mbgl {
|
||||
|
||||
RasterShader::RasterShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store) {
|
||||
: Shader(shaders::raster::name, shaders::raster::vertex, shaders::raster::fragment, store) {
|
||||
}
|
||||
|
||||
void RasterShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
#include <mbgl/shader/sdf.fragment.hpp>
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace shaders::sdf;
|
||||
namespace mbgl {
|
||||
|
||||
SDFShader::SDFShader(gl::ObjectStore& store)
|
||||
: Shader(::name, ::vertex, ::fragment, store)
|
||||
, a_offset(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset")))
|
||||
, a_data1(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1")))
|
||||
, a_data2(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2"))) {
|
||||
: Shader(shaders::sdf::name, shaders::sdf::vertex, shaders::sdf::fragment, store),
|
||||
a_offset(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_offset"))),
|
||||
a_data1(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data1"))),
|
||||
a_data2(MBGL_CHECK_ERROR(glGetAttribLocation(getID(), "a_data2"))) {
|
||||
}
|
||||
|
||||
void SDFGlyphShader::bind(GLbyte* offset) {
|
||||
@@ -44,3 +43,5 @@ void SDFIconShader::bind(GLbyte* offset) {
|
||||
MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data2));
|
||||
MBGL_CHECK_ERROR(glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, stride, offset + 12));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
SpriteAtlas::SpriteAtlas(dimension width_, dimension height_, float pixelRatio_, SpriteStore& store_)
|
||||
: width(width_),
|
||||
@@ -253,3 +253,5 @@ SpriteAtlas::Holder::Holder(std::shared_ptr<const SpriteImage> spriteImage_, Rec
|
||||
|
||||
SpriteAtlas::Holder::Holder(Holder&& h) : spriteImage(std::move(h.spriteImage)), pos(h.pos) {
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -80,25 +80,25 @@ Anchors getAnchors(const GeometryCoordinates &line, float spacing,
|
||||
const float angleWindowSize = (textLeft - textRight) != 0.0f ?
|
||||
3.0f / 5.0f * glyphSize * boxScale :
|
||||
0;
|
||||
|
||||
|
||||
const float labelLength = fmax(textRight - textLeft, iconRight - iconLeft);
|
||||
|
||||
|
||||
// Is the line continued from outside the tile boundary?
|
||||
const bool continuedLine = (line[0].x == 0 || line[0].x == util::EXTENT || line[0].y == 0 || line[0].y == util::EXTENT);
|
||||
|
||||
|
||||
// Is the label long, relative to the spacing?
|
||||
// If so, adjust the spacing so there is always a minimum space of `spacing / 4` between label edges.
|
||||
if (spacing - labelLength * boxScale < spacing / 4) {
|
||||
spacing = labelLength * boxScale + spacing / 4;
|
||||
}
|
||||
|
||||
|
||||
// Offset the first anchor by:
|
||||
// Either half the label length plus a fixed extra offset if the line is not continued
|
||||
// Or half the spacing if the line is continued.
|
||||
|
||||
// For non-continued lines, add a bit of fixed extra offset to avoid collisions at T intersections.
|
||||
const float fixedExtraOffset = glyphSize * 2;
|
||||
|
||||
|
||||
const float offset = !continuedLine ?
|
||||
std::fmod((labelLength / 2 + fixedExtraOffset) * boxScale * overscaling, spacing) :
|
||||
std::fmod(spacing / 2 * overscaling, spacing);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <mbgl/util/worker.hpp>
|
||||
#include <mbgl/util/work_request.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
RasterTile::RasterTile(const OverscaledTileID& id_,
|
||||
const style::UpdateParameters& parameters,
|
||||
@@ -67,3 +67,5 @@ void RasterTile::setNecessity(Necessity necessity) {
|
||||
void RasterTile::cancel() {
|
||||
workRequest.reset();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using namespace mbgl::style;
|
||||
using namespace style;
|
||||
|
||||
TileWorker::TileWorker(OverscaledTileID id_,
|
||||
SpriteStore& spriteStore_,
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void matrix::identity(mat2& out) {
|
||||
out[0] = 1.0f;
|
||||
@@ -50,3 +50,5 @@ void matrix::scale(mat2& out, const mat2& a, double v0, double v1) {
|
||||
out[2] = a2 * v1;
|
||||
out[3] = a3 * v1;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
void matrix::identity(mat3& out) {
|
||||
out[0] = 1.0f;
|
||||
@@ -93,3 +93,5 @@ void matrix::scale(mat3& out, const mat3& a, double x, double y) {
|
||||
out[7] = a[7];
|
||||
out[8] = a[8];
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
using namespace mbgl;
|
||||
namespace mbgl {
|
||||
|
||||
bool Raster::isLoaded() const {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
@@ -59,3 +59,5 @@ void Raster::upload(gl::ObjectStore& store) {
|
||||
img.data.reset();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
#include <iostream>
|
||||
#include <atomic>
|
||||
|
||||
using namespace mbgl::util;
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
stopwatch::stopwatch(Event event_)
|
||||
: event(event_), start(Clock::now()) {}
|
||||
@@ -33,4 +34,8 @@ stopwatch::~stopwatch() {
|
||||
report(name);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,4 +11,4 @@ const char *string = MBGL_VERSION_STRING;
|
||||
const unsigned int number = MBGL_VERSION;
|
||||
|
||||
} // namespace version
|
||||
} // namespace mbgl
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user