From 0eff77c03e8fcf0076260c05123f9dd74d2dae56 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 21 Aug 2012 12:51:39 -0700 Subject: [PATCH] return without rendering if label placement algorithm returns false indicating a degenerate geometry - closes #1423 and refs #1424 --- include/mapnik/grid/grid_marker_helpers.hpp | 20 ++++++++------ include/mapnik/marker_helpers.hpp | 24 ++++++++++------- src/agg/process_point_symbolizer.cpp | 10 +++++-- src/cairo_renderer.cpp | 30 ++++++++++++++------- src/grid/process_point_symbolizer.cpp | 10 +++++-- src/symbolizer_helpers.cpp | 18 ++++++++----- 6 files changed, 75 insertions(+), 37 deletions(-) diff --git a/include/mapnik/grid/grid_marker_helpers.hpp b/include/mapnik/grid/grid_marker_helpers.hpp index 4316f2777..cd8b40ae0 100644 --- a/include/mapnik/grid/grid_marker_helpers.hpp +++ b/include/mapnik/grid/grid_marker_helpers.hpp @@ -78,15 +78,17 @@ struct raster_markers_rasterizer_dispatch_grid box2d bbox_(0,0, src_.width(),src_.height()); if (placement_method != MARKER_LINE_PLACEMENT) { - double x,y; - path.rewind(0); + double x = 0; + double y = 0; if (placement_method == MARKER_INTERIOR_PLACEMENT) { - label::interior_position(path, x, y); + if (!label::interior_position(path, x, y)) + return; } else { - label::centroid(path, x, y); + if (!label::centroid(path, x, y)) + return; } agg::trans_affine matrix = marker_trans_; matrix.translate(x,y); @@ -207,15 +209,17 @@ struct vector_markers_rasterizer_dispatch_grid marker_placement_e placement_method = sym_.get_marker_placement(); if (placement_method != MARKER_LINE_PLACEMENT) { - double x,y; - path.rewind(0); + double x = 0; + double y = 0; if (placement_method == MARKER_INTERIOR_PLACEMENT) { - label::interior_position(path, x, y); + if (!label::interior_position(path, x, y)) + return; } else { - label::centroid(path, x, y); + if (!label::centroid(path, x, y)) + return; } agg::trans_affine matrix = marker_trans_; matrix.translate(x,y); diff --git a/include/mapnik/marker_helpers.hpp b/include/mapnik/marker_helpers.hpp index 2b90d3579..8992112e7 100644 --- a/include/mapnik/marker_helpers.hpp +++ b/include/mapnik/marker_helpers.hpp @@ -87,15 +87,17 @@ struct vector_markers_rasterizer_dispatch if (placement_method != MARKER_LINE_PLACEMENT) { - double x,y; - path.rewind(0); + double x = 0; + double y = 0; if (placement_method == MARKER_INTERIOR_PLACEMENT) { - label::interior_position(path, x, y); + if (!label::interior_position(path, x, y)) + return; } else { - label::centroid(path, x, y); + if (!label::centroid(path, x, y)) + return; } agg::trans_affine matrix = marker_trans_; matrix.translate(x,y); @@ -117,7 +119,9 @@ struct vector_markers_rasterizer_dispatch sym_.get_spacing() * scale_factor_, sym_.get_max_error(), sym_.get_allow_overlap()); - double x, y, angle; + double x = 0; + double y = 0; + double angle = 0; while (placement.get_point(x, y, angle)) { agg::trans_affine matrix = marker_trans_; @@ -179,15 +183,17 @@ struct raster_markers_rasterizer_dispatch if (placement_method != MARKER_LINE_PLACEMENT) { - double x,y; - path.rewind(0); + double x = 0; + double y = 0; if (placement_method == MARKER_INTERIOR_PLACEMENT) { - label::interior_position(path, x, y); + if (!label::interior_position(path, x, y)) + return; } else { - label::centroid(path, x, y); + if (!label::centroid(path, x, y)) + return; } agg::trans_affine matrix = marker_trans_; matrix.translate(x,y); diff --git a/src/agg/process_point_symbolizer.cpp b/src/agg/process_point_symbolizer.cpp index 5917835ec..3fbf21067 100644 --- a/src/agg/process_point_symbolizer.cpp +++ b/src/agg/process_point_symbolizer.cpp @@ -77,9 +77,15 @@ void agg_renderer::process(point_symbolizer const& sym, double y; double z=0; if (sym.get_point_placement() == CENTROID_POINT_PLACEMENT) - label::centroid(geom, x, y); + { + if (!label::centroid(geom, x, y)) + return; + } else - label::interior_position(geom ,x, y); + { + if (!label::interior_position(geom ,x, y)) + return; + } prj_trans.backward(x,y,z); t_.forward(&x,&y); diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index ccd07888c..21bf6d2e8 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -1203,9 +1203,15 @@ void cairo_renderer_base::process(point_symbolizer const& sym, double z = 0; if (sym.get_point_placement() == CENTROID_POINT_PLACEMENT) - label::centroid(geom, x, y); + { + if (!label::centroid(geom, x, y)) + return; + } else - label::interior_position(geom, x, y); + { + if (!label::interior_position(geom ,x, y)) + return; + } prj_trans.backward(x, y, z); t_.forward(&x, &y); @@ -1490,15 +1496,17 @@ struct markers_dispatch if (placement_method != MARKER_LINE_PLACEMENT) { - double x,y; - path.rewind(0); + double x = 0; + double y = 0; if (placement_method == MARKER_INTERIOR_PLACEMENT) { - label::interior_position(path, x, y); + if (!label::interior_position(path, x, y)) + return; } else { - label::centroid(path, x, y); + if (!label::centroid(path, x, y)) + return; } coord2d center = bbox_.center(); agg::trans_affine matrix = agg::trans_affine_translation(-center.x, -center.y); @@ -1571,15 +1579,17 @@ struct markers_dispatch_2 if (placement_method != MARKER_LINE_PLACEMENT) { - double x,y; - path.rewind(0); + double x = 0; + double y = 0; if (placement_method == MARKER_INTERIOR_PLACEMENT) { - label::interior_position(path, x, y); + if (!label::interior_position(path, x, y)) + return; } else { - label::centroid(path, x, y); + if (!label::centroid(path, x, y)) + return; } coord2d center = bbox_.center(); agg::trans_affine matrix = agg::trans_affine_translation(-center.x, -center.y); diff --git a/src/grid/process_point_symbolizer.cpp b/src/grid/process_point_symbolizer.cpp index eec6bf685..843bfd802 100644 --- a/src/grid/process_point_symbolizer.cpp +++ b/src/grid/process_point_symbolizer.cpp @@ -81,9 +81,15 @@ void grid_renderer::process(point_symbolizer const& sym, double y; double z=0; if (sym.get_point_placement() == CENTROID_POINT_PLACEMENT) - label::centroid(geom, x, y); + { + if (!label::centroid(geom, x, y)) + return; + } else - label::interior_position(geom, x, y); + { + if (!label::interior_position(geom ,x, y)) + return; + } prj_trans.backward(x,y,z); t_.forward(&x,&y); diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index 51bfa456f..faadb39c0 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -233,25 +233,31 @@ void text_symbolizer_helper::initialize_points() } else { + // https://github.com/mapnik/mapnik/issues/1423 + bool success = false; + // https://github.com/mapnik/mapnik/issues/1350 if (geom.type() == LineString) { - label::middle_point(geom, label_x,label_y); + success = label::middle_point(geom, label_x,label_y); } else if (how_placed == POINT_PLACEMENT) { - label::centroid(geom, label_x, label_y); + success = label::centroid(geom, label_x, label_y); } else if (how_placed == INTERIOR_PLACEMENT) { - label::interior_position(geom, label_x, label_y); + success = label::interior_position(geom, label_x, label_y); } else { MAPNIK_LOG_ERROR(symbolizer_helpers) << "ERROR: Unknown placement type in initialize_points()"; } - prj_trans_.backward(label_x, label_y, z); - t_.forward(&label_x, &label_y); - points_.push_back(std::make_pair(label_x, label_y)); + if (success) + { + prj_trans_.backward(label_x, label_y, z); + t_.forward(&label_x, &label_y); + points_.push_back(std::make_pair(label_x, label_y)); + } } } point_itr_ = points_.begin();