create line geometry
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user