summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauren Budorick <lauren@mapbox.com>2017-04-08 10:12:49 -0700
committerLauren Budorick <lauren@mapbox.com>2017-04-24 17:09:09 -0700
commit3d78137995dff386f3bc6506dea799945b72befc (patch)
treee12ee366c354bb1cf1ffae9fd924a603221f6bd8
parentbf3088faa17f10b51e69aed5c3ac62bb4508d324 (diff)
downloadqtlocation-mapboxgl-3d78137995dff386f3bc6506dea799945b72befc.tar.gz
Per review:
* Clean up position.hpp
-rw-r--r--include/mbgl/style/light.hpp70
-rw-r--r--include/mbgl/style/position.hpp18
-rw-r--r--include/mbgl/util/interpolate.hpp3
-rw-r--r--src/mbgl/renderer/painter_fill_extrusion.cpp2
4 files changed, 13 insertions, 80 deletions
diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp
index 695a3c7a7b..c9b1cd314d 100644
--- a/include/mbgl/style/light.hpp
+++ b/include/mbgl/style/light.hpp
@@ -50,7 +50,7 @@ public:
template <class TransitioningProperty>
TransitioningProperty cascade(const CascadeParameters& params,
- TransitioningProperty prior) const {
+ TransitioningProperty prior) const {
TransitionOptions transition_;
Value value_;
@@ -63,7 +63,7 @@ public:
}
return TransitioningProperty(std::move(value_), std::move(prior),
- transition_.reverseMerge(params.transition), params.now);
+ transition_.reverseMerge(params.transition), params.now);
}
private:
@@ -162,7 +162,8 @@ struct LightAnchor : LightProperty<LightAnchorType> {
};
struct LightPosition : LightProperty<Position> {
static Position defaultValue() {
- return Position{ { { 1.15, 210, 30 } } };
+ std::array<float, 3> default_ = { { 1.15, 210, 30 } };
+ return Position{ { default_ } };
}
};
struct LightColor : LightProperty<Color> {
@@ -176,68 +177,7 @@ struct LightIntensity : LightProperty<float> {
}
};
-class Light : public LightProperties<LightAnchor, LightPosition, LightColor, LightIntensity> {
-public:
- void setAnchor(PropertyValue<LightAnchorType> value) {
- if (value == this->getAnchor())
- return;
- this->set<LightAnchor>(value);
- // TODO run observer
- }
-
- PropertyValue<LightAnchorType> getAnchor() const {
- return this->get<LightAnchor>();
- }
-
- PropertyValue<LightAnchorType> getDefaultAnchor() const {
- return LightAnchor::defaultValue();
- }
-
- void setPosition(PropertyValue<Position> value) {
- if (value == this->getPosition())
- return;
- this->set<LightPosition>(value);
- // TODO run observer
- }
-
- PropertyValue<Position> getPosition() const {
- return this->get<LightPosition>();
- }
-
- PropertyValue<Position> getDefaultPosition() const {
- return LightPosition::defaultValue();
- }
-
- void setColor(PropertyValue<Color> value) {
- if (value == this->getColor())
- return;
- this->set<LightColor>(value);
- // TODO run observer
- }
-
- PropertyValue<Color> getColor() const {
- return this->get<LightColor>();
- }
-
- PropertyValue<Color> getDefaultColor() const {
- return LightColor::defaultValue();
- }
-
- void setIntensity(PropertyValue<float> value) {
- if (value == this->getIntensity())
- return;
- this->set<LightIntensity>(value);
- // TODO run observer
- }
-
- PropertyValue<float> getIntensity() const {
- return this->get<LightIntensity>();
- }
-
- PropertyValue<float> getDefaultIntensity() const {
- return LightIntensity::defaultValue();
- }
-};
+class Light : public LightProperties<LightAnchor, LightPosition, LightColor, LightIntensity> {};
} // namespace style
} // namespace mbgl
diff --git a/include/mbgl/style/position.hpp b/include/mbgl/style/position.hpp
index 55daf10ade..418f408965 100644
--- a/include/mbgl/style/position.hpp
+++ b/include/mbgl/style/position.hpp
@@ -1,20 +1,15 @@
#pragma once
-#include <mbgl/style/types.hpp>
-#include <mbgl/util/optional.hpp>
#include <mbgl/util/constants.hpp>
#include <array>
-#include <cassert>
-#include <string>
-
namespace mbgl {
namespace style {
class Position {
public:
Position() = default;
- Position(std::array<float, 3> position_)
+ Position(std::array<float, 3>& position_)
: radial(position_[0]), azimuthal(position_[1]), polar(position_[2]) {
calculateCartesian();
};
@@ -28,7 +23,7 @@ public:
return !(lhs == rhs);
}
- const std::array<float, 3> get() const {
+ const std::array<float, 3> getCartesian() const {
return { { x, y, z } };
};
@@ -36,7 +31,7 @@ public:
return { { radial, azimuthal, polar } };
};
- void set(std::array<float, 3> position_) {
+ void set(std::array<float, 3>& position_) {
radial = position_[0];
azimuthal = position_[1];
polar = position_[2];
@@ -52,13 +47,10 @@ private:
float z;
void calculateCartesian() {
- auto _a = azimuthal;
// We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2): we
// correct for that here
- _a += 90;
- _a *= util::DEG2RAD;
- auto _p = polar;
- _p *= util::DEG2RAD;
+ const float _a = (azimuthal + 90) * util::DEG2RAD;
+ const float _p = polar * util::DEG2RAD;
x = radial * std::cos(_a) * std::sin(_p);
y = radial * std::sin(_a) * std::sin(_p);
diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp
index 49d0ed1f14..c75e8efba6 100644
--- a/include/mbgl/util/interpolate.hpp
+++ b/include/mbgl/util/interpolate.hpp
@@ -51,8 +51,9 @@ template <>
struct Interpolator<style::Position> {
public:
style::Position operator()(const style::Position& a, const style::Position& b, const double t) {
+ auto interpolated = interpolate(a.getSpherical(), b.getSpherical(), t);
return {
- style::Position(interpolate(a.getSpherical(), b.getSpherical(), t))
+ style::Position(interpolated)
};
}
};
diff --git a/src/mbgl/renderer/painter_fill_extrusion.cpp b/src/mbgl/renderer/painter_fill_extrusion.cpp
index 5ea2ba6203..3ceda03c6d 100644
--- a/src/mbgl/renderer/painter_fill_extrusion.cpp
+++ b/src/mbgl/renderer/painter_fill_extrusion.cpp
@@ -31,7 +31,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters,
std::array<float, 3> color3f = { { lightColor.r, lightColor.g, lightColor.b } };
const auto lightAnchor = light.get<LightAnchor>();
- auto lightPos = light.get<LightPosition>().get();
+ auto lightPos = light.get<LightPosition>().getCartesian();
mat3 lightmat;
matrix::identity(lightmat);
if (lightAnchor == LightAnchorType::Viewport) {