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

Commit

Permalink
Reconcile changes from rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Mar 27, 2017
1 parent 2ed99ef commit 3661090
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
18 changes: 12 additions & 6 deletions include/mbgl/style/conversion/constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ struct Converter<Color> {
template <>
struct Converter<Position> {
template <class V>
Result<Position> operator()(const V& value) const {
Result<std::array<float, 3>> spherical = convert<std::array<float, 3>>(value);
optional<Position> operator()(const V& value, Error& error) const {
optional<std::array<float, 3>> spherical = convert<std::array<float, 3>>(value, error);

if (!spherical) {
return spherical.error();
return {};
}

optional<Position> converted = Position(*spherical);
if (!converted) {
error = { "value must be a valid position" };
return {};
}

return *converted;
}
Expand Down Expand Up @@ -131,16 +135,18 @@ struct Converter<std::array<float, 2>> {
template <>
struct Converter<std::array<float, 3>> {
template <class V>
Result<std::array<float, 3>> operator()(const V& value) const {
optional<std::array<float, 3>> operator()(const V& value, Error& error) const {
if (!isArray(value) || arrayLength(value) != 3) {
return Error { "value must be an array of three numbers" };
error = { "value must be an array of three numbers" };
return {};
}

optional<float> first = toNumber(arrayMember(value, 0));
optional<float> second = toNumber(arrayMember(value, 1));
optional<float> third = toNumber(arrayMember(value, 2));
if (!first || !second || !third) {
return Error { "value must be an array of three numbers" };
error = { "value must be an array of three numbers" };
return {};
}

return std::array<float, 3> {{ *first, *second, *third }};
Expand Down
25 changes: 13 additions & 12 deletions include/mbgl/style/conversion/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,54 @@ template <>
struct Converter<Light> {
public:
template <class V>
Result<Light> operator()(const V& value) const {
optional<Light> operator()(const V& value, Error& error) const {
if (!isObject(value)) {
return Error{ "light must be an object" };
error = { "light must be an object" };
return {};
}

Light light;

const auto anchor = objectMember(value, "anchor");
if (anchor) {
Result<PropertyValue<LightAnchorType>> convertedAnchor =
convert<PropertyValue<LightAnchorType>>(*anchor);
optional<PropertyValue<LightAnchorType>> convertedAnchor =
convert<PropertyValue<LightAnchorType>>(*anchor, error);
if (convertedAnchor) {
light.set<LightAnchor>(*convertedAnchor);
} else {
return convertedAnchor.error();
return {};
}
}

const auto color = objectMember(value, "color");
if (color) {
Result<PropertyValue<Color>> convertedColor = convert<PropertyValue<Color>>(*color);
optional<PropertyValue<Color>> convertedColor = convert<PropertyValue<Color>>(*color, error);
if (convertedColor) {
light.set<LightColor>(*convertedColor);
} else {
return convertedColor.error();
return {};
}
}

const auto position = objectMember(value, "position");
if (position) {
auto convertedPosition = convert<PropertyValue<Position>>(*position);
optional<PropertyValue<Position>> convertedPosition = convert<PropertyValue<Position>>(*position, error);

if (convertedPosition) {
light.set<LightPosition>(*convertedPosition);
} else {
return convertedPosition.error();
return {};
}
}

const auto intensity = objectMember(value, "intensity");
if (intensity) {
Result<PropertyValue<float>> convertedIntensity =
convert<PropertyValue<float>>(*intensity);
optional<PropertyValue<float>> convertedIntensity =
convert<PropertyValue<float>>(*intensity, error);
if (convertedIntensity) {
light.set<LightIntensity>(*convertedIntensity);
} else {
return convertedIntensity.error();
return {};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void Painter::renderPass(PaintParameters& parameters,
auto renderTiles = [this, &item, &layer, &parameters, &style]() {
for (auto& tileRef : item.tiles) {
auto& tile = tileRef.get();
MBGL_DEBUG_GROUP(layer.baseImpl->id + " - " + util::toString(tile.id));
MBGL_DEBUG_GROUP(context, layer.baseImpl->id + " - " + util::toString(tile.id));
auto bucket = tile.tile.getBucket(layer);
if (bucket) {
bucket->render(*this, parameters, layer, tile, style);
Expand Down
8 changes: 7 additions & 1 deletion src/mbgl/style/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ void Parser::parseLight(const JSValue& value) {
return;
}

conversion::Result<Light> converted = conversion::convert<Light>(value);
conversion::Error error;
optional<Light> converted = conversion::convert<Light>(value, error);
if (!converted) {
Log::Warning(Event::ParseStyle, error.message);
return;
}

light = *converted;
}

Expand Down

0 comments on commit 3661090

Please sign in to comment.