7#include "penwidthutil_p.h"
9#include "style/mapcssdeclaration_p.h"
18}
static constexpr const unit_conversion_table[] = {
23double PenWidthUtil::penWidth(
OSM::Element e,
const MapCSSDeclaration *decl,
Unit &unit)
26 if (decl->keyValue().isEmpty()) {
27 if (decl->unit() != MapCSSDeclaration::NoUnit) {
28 unit = decl->unit() == MapCSSDeclaration::Meters ? Unit::Meter : Unit::Pixel;
30 return decl->doubleValue();
35 double unitConversionFactor = 1.0;
38 const auto value = e.tagValue(decl->keyValue().constData()).
constData();
39 const auto valueLen = std::strlen(value);
40 const auto valueEnd = value + valueLen;
41 const char* it = value;
43 while (it < valueEnd) {
45 num = std::isnan(num) ? std::strtod(it, &numEnd) : std::max(num, std::strtod(it, &numEnd));
51 while (it != valueEnd && std::isspace(
static_cast<unsigned char>(*it))) {
56 for (
const auto &unit : unit_conversion_table) {
57 const auto unitLen = std::strlen(unit.unit);
58 if (std::strncmp(it, unit.unit, unitLen) == 0) {
59 unitConversionFactor = unit.factor;
65 if (it != valueEnd && (*it) ==
';') {
72 if (std::isnan(num)) {
73 qCDebug(
Log) <<
"Failed to parse width from tag value:" << value << decl->keyValue() << e.url();
78 if (it == value + valueLen) {
79 if (std::strcmp(decl->keyValue().constData(),
"gauge") == 0) {
80 unitConversionFactor = 0.001;
85 return num * unitConversionFactor;
A reference to any of OSM::Node/OSM::Way/OSM::Relation.
OSM-based multi-floor indoor maps for buildings.
Unit
Unit for geometry sizes.
const char * constData() const const