summaryrefslogtreecommitdiff
path: root/include/llmr
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-01-28 17:17:00 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-01-28 17:17:00 +0100
commit918a68f5dd8ca768cc2dbd6c0ccf031f9f3bbf75 (patch)
tree2e61a0505e606809a4ebf2c805ce93f34f6efa38 /include/llmr
parentf19d5c95dbc2784c53e47e869bef3bbde15c4c71 (diff)
downloadqtlocation-mapboxgl-918a68f5dd8ca768cc2dbd6c0ccf031f9f3bbf75.tar.gz
create line geometry
Diffstat (limited to 'include/llmr')
-rw-r--r--include/llmr/map/vector_tile.hpp22
-rw-r--r--include/llmr/renderer/fill_bucket.hpp5
-rw-r--r--include/llmr/renderer/line_bucket.hpp8
-rw-r--r--include/llmr/style/bucket_description.hpp7
-rw-r--r--include/llmr/style/properties.hpp3
-rw-r--r--include/llmr/util/math.hpp18
-rw-r--r--include/llmr/util/vec.hpp11
7 files changed, 69 insertions, 5 deletions
diff --git a/include/llmr/map/vector_tile.hpp b/include/llmr/map/vector_tile.hpp
index c0cfc9bfbc..14b497709f 100644
--- a/include/llmr/map/vector_tile.hpp
+++ b/include/llmr/map/vector_tile.hpp
@@ -14,6 +14,28 @@ class VectorTileLayer;
struct pbf;
+struct Coordinate {
+ Coordinate() : x(0), y(0) {}
+ Coordinate(int16_t x, int16_t y) : x(x), y(y) {}
+ int16_t x;
+ int16_t y;
+
+ inline bool operator==(const Coordinate& other) const {
+ return x == other.x && y == other.y;
+ }
+
+ inline operator bool() const {
+ return *this == null;
+ }
+
+ static const Coordinate null;
+};
+
+/*
+ * Allows iterating over the features of a VectorTileLayer using a
+ * BucketDescription as filter. Only features matching the descriptions will
+ * be returned (as pbf).
+ */
class FilteredVectorTileLayer {
public:
class iterator {
diff --git a/include/llmr/renderer/fill_bucket.hpp b/include/llmr/renderer/fill_bucket.hpp
index a64350a7ee..e4d813a95e 100644
--- a/include/llmr/renderer/fill_bucket.hpp
+++ b/include/llmr/renderer/fill_bucket.hpp
@@ -9,6 +9,8 @@ namespace llmr {
class Style;
class FillBuffer;
+class BucketDescription;
+struct Coordinate;
struct pbf;
class FillBucket : public Bucket {
@@ -17,7 +19,8 @@ public:
virtual void render(Painter& painter, const std::string& layer_name);
- void addGeometry(pbf& data);
+ void addGeometry(pbf& data, const BucketDescription& bucket_desc);
+ void addGeometry(const std::vector<Coordinate>& line, const BucketDescription& bucket_desc);
void drawElements(int32_t attrib);
void drawVertices(int32_t attrib);
diff --git a/include/llmr/renderer/line_bucket.hpp b/include/llmr/renderer/line_bucket.hpp
index 8feff69b3c..852f265e0d 100644
--- a/include/llmr/renderer/line_bucket.hpp
+++ b/include/llmr/renderer/line_bucket.hpp
@@ -9,6 +9,8 @@ namespace llmr {
class Style;
class LineBuffer;
+class BucketDescription;
+struct Coordinate;
struct pbf;
class LineBucket : public Bucket {
@@ -17,11 +19,13 @@ public:
virtual void render(Painter& painter, const std::string& layer_name);
- void addGeometry(pbf& data);
+ void addGeometry(pbf& data, const BucketDescription& bucket_desc);
+ void addGeometry(const std::vector<Coordinate>& line, const BucketDescription& bucket_desc);
private:
std::shared_ptr<LineBuffer> buffer;
-
+ uint32_t start;
+ uint32_t length;
};
}
diff --git a/include/llmr/style/bucket_description.hpp b/include/llmr/style/bucket_description.hpp
index c8933d4190..fb72b7bb5a 100644
--- a/include/llmr/style/bucket_description.hpp
+++ b/include/llmr/style/bucket_description.hpp
@@ -18,12 +18,15 @@ enum class BucketType {
enum class CapType {
None = 0,
Round = 1,
+ Butt = 2,
+ Square = 3
};
enum class JoinType {
None = 0,
Butt = 1,
- Bevel = 2
+ Bevel = 2,
+ Round = 3
};
@@ -42,6 +45,8 @@ public:
JoinType join = JoinType::None;
std::string font;
float font_size = 0.0f;
+ float miter_limit = 2.0f;
+ float round_limit = 1.0f;
};
std::ostream& operator<<(std::ostream&, const BucketDescription& bucket);
diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp
index 5b4f7d6275..66a1cebf4e 100644
--- a/include/llmr/style/properties.hpp
+++ b/include/llmr/style/properties.hpp
@@ -22,7 +22,6 @@ enum class Winding {
// Bevel = 2
// };
-
enum class Property {
Null = 1,
Constant = 2,
@@ -59,6 +58,7 @@ struct LineClass {
FunctionProperty<float> width;
FunctionProperty<float> offset;
Color color = {{ 0, 0, 0, 1 }};
+ FunctionProperty<float> opacity = 1;
};
// LineProperties is the one we resolve this to.
@@ -67,6 +67,7 @@ struct LineProperties {
float width = 0;
float offset = 0;
Color color = {{ 0, 0, 0, 1 }};
+ float opacity = 1.0;
};
diff --git a/include/llmr/util/math.hpp b/include/llmr/util/math.hpp
index 744a9d9473..8ea4a6b792 100644
--- a/include/llmr/util/math.hpp
+++ b/include/llmr/util/math.hpp
@@ -3,6 +3,8 @@
#include <cmath>
+#include "vec.hpp"
+
namespace llmr {
namespace util {
@@ -10,6 +12,22 @@ inline double angle_between(double ax, double ay, double bx, double by) {
return atan2((ax * by - ay * bx), ax * bx + ay * by);
}
+template <typename T, typename S1, typename S2>
+inline vec2<T> normal(const S1& a, const S2& b) {
+ T dx = b.x - a.x;
+ T dy = b.y - a.y;
+ T c = sqrt(dx * dx + dy * dy);
+ return { dx / c, dy / c };
+}
+
+template <typename T, typename S1, typename S2>
+inline T dist(const S1& a, const S2& b) {
+ T dx = b.x - a.x;
+ T dy = b.y - a.y;
+ T c = sqrt(dx * dx + dy * dy);
+ return c;
+};
+
}
}
diff --git a/include/llmr/util/vec.hpp b/include/llmr/util/vec.hpp
index 782573d7fd..8ef938faab 100644
--- a/include/llmr/util/vec.hpp
+++ b/include/llmr/util/vec.hpp
@@ -1,18 +1,29 @@
#ifndef llmr_util_vec2_
#define llmr_util_vec2_
+#include <limits>
+
namespace llmr {
template <typename T = double>
struct vec2 {
+ struct null {};
+
T x, y;
inline vec2() {}
+ inline vec2(null) : x(std::numeric_limits<T>::quiet_NaN()), y(std::numeric_limits<T>::quiet_NaN()) {}
+
inline vec2(const vec2& o) : x(o.x), y(o.y) {}
inline vec2(T x, T y) : x(x), y(y) {}
inline bool operator==(const vec2& rhs) const {
return x == rhs.x && y == rhs.y;
}
+
+ template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline operator bool() const {
+ return isnan(x) || isnan(y);
+ }
};
template <typename T = double>