#pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace mln { namespace gfx { class PolylineGeneratorDistances { public: PolylineGeneratorDistances(double clipStart_, double clipEnd_, double total_) : clipStart(clipStart_), clipEnd(clipEnd_), total(total_) {} // Scale line distance from tile units to [0, 2^15). double scaleToMaxLineDistance(double tileDistance) const; private: double clipStart; double clipEnd; double total; }; struct PolylineGeneratorOptions { FeatureType type{FeatureType::LineString}; style::LineJoinType joinType{style::LineJoinType::Miter}; float miterLimit{2.f}; style::LineCapType beginCap{style::LineCapType::Butt}; style::LineCapType endCap{style::LineCapType::Butt}; float roundLimit{1.f}; uint32_t overscaling{1}; std::optional clipDistances; }; template class PolylineGenerator { public: using Vertices = gfx::VertexVector; using Segments = std::vector; using LayoutVertexFunc = std::function p, Point e, bool round, bool up, int8_t dir, int32_t linesofar /*= 0*/)>; using CreateSegmentFunc = std::function; using GetSegmentFunc = std::function; using Indexes = gfx::IndexVector; public: PolylineGenerator(Vertices& polylineVertices, LayoutVertexFunc layoutVertexFunc, Segments& polylineSegments, CreateSegmentFunc createSegmentFunc, GetSegmentFunc getSegmentFunc, Indexes& polylineIndexes); ~PolylineGenerator() = default; void generate(const GeometryCoordinates& coordinates, const PolylineGeneratorOptions& options); private: struct TriangleElement; void addCurrentVertex(const GeometryCoordinate& currentCoordinate, double& distance, const Point& normal, double endLeft, double endRight, bool round, std::size_t startVertex, std::vector& triangleStore, std::optional lineDistances); void addPieSliceVertex(const GeometryCoordinate& currentVertex, double distance, const Point& extrude, bool lineTurnsLeft, std::size_t startVertex, std::vector& triangleStore, std::optional lineDistances); private: Vertices& vertices; LayoutVertexFunc layoutVertex; Segments& segments; CreateSegmentFunc createSegment; GetSegmentFunc getSegment; Indexes& indexes; std::ptrdiff_t e1; std::ptrdiff_t e2; std::ptrdiff_t e3; }; } // namespace gfx } // namespace mln