From 657442947b8af3676cc2d9f23e5b1cc221908ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=BDdila?= Date: Mon, 23 Mar 2020 23:07:49 +0100 Subject: [PATCH] add support for spacing-offset --- include/mapnik/markers_placements/basic.hpp | 1 + include/mapnik/markers_placements/line.hpp | 5 ++++- include/mapnik/symbolizer_default_values.hpp | 7 +++++++ include/mapnik/symbolizer_keys.hpp | 1 + src/load_map.cpp | 1 + src/renderer_common/render_markers_symbolizer.cpp | 1 + src/symbolizer_keys.cpp | 1 + test/unit/symbolizer/marker_placement_vertex_last.cpp | 8 ++++---- test/unit/symbolizer/markers_point_placement.cpp | 10 +++++----- 9 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/mapnik/markers_placements/basic.hpp b/include/mapnik/markers_placements/basic.hpp index 84520d12d..3bc8c27ba 100644 --- a/include/mapnik/markers_placements/basic.hpp +++ b/include/mapnik/markers_placements/basic.hpp @@ -42,6 +42,7 @@ struct markers_placement_params box2d size; agg::trans_affine tr; double spacing; + double spacing_offset; double max_error; bool allow_overlap; bool avoid_edges; diff --git a/include/mapnik/markers_placements/line.hpp b/include/mapnik/markers_placements/line.hpp index facfcbe7a..d7f3dd39d 100644 --- a/include/mapnik/markers_placements/line.hpp +++ b/include/mapnik/markers_placements/line.hpp @@ -43,10 +43,12 @@ public: : point_placement(locator, detector, params), first_point_(true), spacing_(0.0), + spacing_offset_(NAN), marker_width_((params.size * params.tr).width()), path_(locator) { spacing_ = params.spacing < 1 ? 100 : params.spacing; + spacing_offset_ = params.spacing_offset; } void rewind() @@ -77,7 +79,7 @@ public: return false; } first_point_ = false; - move = spacing_ / 2.0; + move = std::isnan(spacing_offset_) ? spacing_ / 2.0 : spacing_offset_; } while (path_.forward(move)) @@ -113,6 +115,7 @@ public: private: bool first_point_; double spacing_; + double spacing_offset_; double marker_width_; vertex_cache path_; }; diff --git a/include/mapnik/symbolizer_default_values.hpp b/include/mapnik/symbolizer_default_values.hpp index 4e7c7c06a..14918c34d 100644 --- a/include/mapnik/symbolizer_default_values.hpp +++ b/include/mapnik/symbolizer_default_values.hpp @@ -185,6 +185,13 @@ struct symbolizer_default static value_double value() { return 100.0; } }; +// spacing-offset +template <> +struct symbolizer_default +{ + static value_double value() { return NAN; } +}; + // max-error template <> struct symbolizer_default diff --git a/include/mapnik/symbolizer_keys.hpp b/include/mapnik/symbolizer_keys.hpp index 42200d6e5..9ab7a6965 100644 --- a/include/mapnik/symbolizer_keys.hpp +++ b/include/mapnik/symbolizer_keys.hpp @@ -52,6 +52,7 @@ enum class keys : std::uint8_t line_rasterizer, image_transform, spacing, + spacing_offset, max_error, allow_overlap, ignore_placement, diff --git a/src/load_map.cpp b/src/load_map.cpp index 919971d45..531be1533 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -1124,6 +1124,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& node) set_symbolizer_property(sym, keys::opacity, node); set_symbolizer_property(sym, keys::fill_opacity, node); set_symbolizer_property(sym, keys::spacing, node); + set_symbolizer_property(sym, keys::spacing_offset, node); set_symbolizer_property(sym, keys::max_error, node); set_symbolizer_property(sym, keys::offset, node); set_symbolizer_property(sym, keys::width, node); diff --git a/src/renderer_common/render_markers_symbolizer.cpp b/src/renderer_common/render_markers_symbolizer.cpp index 15d9c7c8d..7cecaa9a3 100644 --- a/src/renderer_common/render_markers_symbolizer.cpp +++ b/src/renderer_common/render_markers_symbolizer.cpp @@ -225,6 +225,7 @@ markers_dispatch_params::markers_dispatch_params(box2d const& size, size, tr, get(sym, feature, vars), + get(sym, feature, vars), get(sym, feature, vars), get(sym, feature, vars), get(sym, feature, vars), diff --git a/src/symbolizer_keys.cpp b/src/symbolizer_keys.cpp index 9772e5098..853d77e7c 100644 --- a/src/symbolizer_keys.cpp +++ b/src/symbolizer_keys.cpp @@ -80,6 +80,7 @@ static const property_meta_type key_meta[const_max_key] = property_types::target_double }, property_meta_type{ "transform", nullptr, property_types::target_transform }, property_meta_type{ "spacing", nullptr, property_types::target_double }, + property_meta_type{ "spacing-offset", nullptr, property_types::target_double }, property_meta_type{ "max-error", nullptr, property_types::target_double }, property_meta_type{ "allow-overlap", nullptr, property_types::target_bool }, property_meta_type{ "ignore-placement", nullptr, property_types::target_bool }, diff --git a/test/unit/symbolizer/marker_placement_vertex_last.cpp b/test/unit/symbolizer/marker_placement_vertex_last.cpp index d7b19f25a..4abfe2f1e 100644 --- a/test/unit/symbolizer/marker_placement_vertex_last.cpp +++ b/test/unit/symbolizer/marker_placement_vertex_last.cpp @@ -23,7 +23,7 @@ SECTION("empty geometry") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -45,7 +45,7 @@ SECTION("point") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -75,7 +75,7 @@ SECTION("line string") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -109,7 +109,7 @@ SECTION("polygon") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); diff --git a/test/unit/symbolizer/markers_point_placement.cpp b/test/unit/symbolizer/markers_point_placement.cpp index d4f7a029d..818424864 100644 --- a/test/unit/symbolizer/markers_point_placement.cpp +++ b/test/unit/symbolizer/markers_point_placement.cpp @@ -23,7 +23,7 @@ SECTION("empty geometry") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -45,7 +45,7 @@ SECTION("point") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -75,7 +75,7 @@ SECTION("line string") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -105,7 +105,7 @@ SECTION("line string zero length") { mapnik::markers_placement_params params { mapnik::box2d(0, 0, 10, 10), agg::trans_affine(), - 0, 0, false, false, DIRECTION_AUTO, 1.0 }; + 0, NAN, 0, false, false, DIRECTION_AUTO, 1.0 }; placement_type placement(va, detector, params); @@ -119,4 +119,4 @@ SECTION("line string zero length") { CHECK( !placement.get_point(x, y, angle, true) ); } -} \ No newline at end of file +}