Merge pull request #4001 from mapycz/v3.0.x-offset_clip

v3.0.x: Improve padding calculation
This commit is contained in:
talaj 2018-10-23 21:47:03 +02:00 committed by GitHub
commit 1a043342f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 52 deletions

View file

@ -40,6 +40,8 @@
namespace mapnik namespace mapnik
{ {
static constexpr double offset_converter_default_threshold = 5.0;
template <typename Geometry> template <typename Geometry>
struct offset_converter struct offset_converter
{ {
@ -48,7 +50,7 @@ struct offset_converter
offset_converter(Geometry & geom) offset_converter(Geometry & geom)
: geom_(geom) : geom_(geom)
, offset_(0.0) , offset_(0.0)
, threshold_(5.0) , threshold_(offset_converter_default_threshold)
, half_turn_segments_(16) , half_turn_segments_(16)
, status_(initial) , status_(initial)
, pre_first_(vertex2d::no_init) , pre_first_(vertex2d::no_init)

View file

@ -134,12 +134,11 @@ private:
box2d<double> clip_box = clipping_extent(common_); box2d<double> clip_box = clipping_extent(common_);
if (clip) if (clip)
{ {
double padding = (double)(common_.query_extent_.width()/pixmap_.width()); double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
if (half_stroke > 1) double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
padding *= half_stroke; (std::fabs(offset) * offset_converter_default_threshold)));
if (std::fabs(offset) > 0) double padding = pad_per_pixel * pixels * common_.scale_factor_;
padding *= std::fabs(offset) * 1.2;
padding *= common_.scale_factor_;
clip_box.pad(padding); clip_box.pad(padding);
} }
using vertex_converter_type = vertex_converter<clip_line_tag, transform_tag, using vertex_converter_type = vertex_converter<clip_line_tag, transform_tag,

View file

@ -139,23 +139,11 @@ void agg_renderer<T0,T1>::process(line_symbolizer const& sym,
line_rasterizer_enum rasterizer_e = get<line_rasterizer_enum, keys::line_rasterizer>(sym, feature, common_.vars_); line_rasterizer_enum rasterizer_e = get<line_rasterizer_enum, keys::line_rasterizer>(sym, feature, common_.vars_);
if (clip) if (clip)
{ {
double padding = static_cast<double>(common_.query_extent_.width()/pixmap_.width()); double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
double half_stroke = 0.5 * width; double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
if (half_stroke > 1) (std::fabs(offset) * offset_converter_default_threshold)));
{ double padding = pad_per_pixel * pixels * common_.scale_factor_;
padding *= half_stroke;
}
if (std::fabs(offset) > 0)
{
padding *= std::fabs(offset) * 1.2;
}
padding *= common_.scale_factor_;
clip_box.pad(padding); clip_box.pad(padding);
// debugging
//box2d<double> inverse = query_extent_;
//inverse.pad(-padding);
//draw_geo_extent(inverse,mapnik::color("red"));
} }
if (rasterizer_e == RASTERIZER_FAST) if (rasterizer_e == RASTERIZER_FAST)

View file

@ -131,13 +131,11 @@ void cairo_renderer<T>::process(line_pattern_symbolizer const& sym,
box2d<double> clipping_extent = common_.query_extent_; box2d<double> clipping_extent = common_.query_extent_;
if (clip) if (clip)
{ {
double padding = (double)(common_.query_extent_.width()/common_.width_); double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
double half_stroke = width/2.0; double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
if (half_stroke > 1) (std::fabs(offset) * offset_converter_default_threshold)));
padding *= half_stroke; double padding = pad_per_pixel * pixels * common_.scale_factor_;
if (std::fabs(offset) > 0)
padding *= std::fabs(offset) * 1.2;
padding *= common_.scale_factor_;
clipping_extent.pad(padding); clipping_extent.pad(padding);
} }

View file

@ -73,13 +73,11 @@ void cairo_renderer<T>::process(line_symbolizer const& sym,
box2d<double> clipping_extent = common_.query_extent_; box2d<double> clipping_extent = common_.query_extent_;
if (clip) if (clip)
{ {
double padding = (double)(common_.query_extent_.width()/common_.width_); double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
double half_stroke = width/2.0; double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
if (half_stroke > 1) (std::fabs(offset) * offset_converter_default_threshold)));
padding *= half_stroke; double padding = pad_per_pixel * pixels * common_.scale_factor_;
if (std::fabs(offset) > 0)
padding *= std::fabs(offset) * 1.2;
padding *= common_.scale_factor_;
clipping_extent.pad(padding); clipping_extent.pad(padding);
} }
using vertex_converter_type = vertex_converter<clip_line_tag, using vertex_converter_type = vertex_converter<clip_line_tag,

View file

@ -97,13 +97,11 @@ void grid_renderer<T>::process(line_pattern_symbolizer const& sym,
box2d<double> clipping_extent = common_.query_extent_; box2d<double> clipping_extent = common_.query_extent_;
if (clip) if (clip)
{ {
double padding = (double)(common_.query_extent_.width()/pixmap_.width()); double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
double half_stroke = stroke_width/2.0; double pixels = std::ceil(std::max(stroke_width / 2.0 + std::fabs(offset),
if (half_stroke > 1) (std::fabs(offset) * offset_converter_default_threshold)));
padding *= half_stroke; double padding = pad_per_pixel * pixels * common_.scale_factor_;
if (std::fabs(offset) > 0)
padding *= std::fabs(offset) * 1.2;
padding *= common_.scale_factor_;
clipping_extent.pad(padding); clipping_extent.pad(padding);
} }

View file

@ -84,13 +84,11 @@ void grid_renderer<T>::process(line_symbolizer const& sym,
if (clip) if (clip)
{ {
double padding = (double)(common_.query_extent_.width()/pixmap_.width()); double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
double half_stroke = width/2.0; double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
if (half_stroke > 1) (std::fabs(offset) * offset_converter_default_threshold)));
padding *= half_stroke; double padding = pad_per_pixel * pixels * common_.scale_factor_;
if (std::fabs(offset) > 0)
padding *= std::fabs(offset) * 1.2;
padding *= common_.scale_factor_;
clipping_extent.pad(padding); clipping_extent.pad(padding);
} }
using vertex_converter_type = vertex_converter<clip_line_tag, clip_poly_tag, transform_tag, using vertex_converter_type = vertex_converter<clip_line_tag, clip_poly_tag, transform_tag,

@ -1 +1 @@
Subproject commit 13163a419eec939d189a371427022402b98bb08a Subproject commit 0a804e64beee9af6b1388f45d89554fddbba89c5