Improve padding calculation

This commit is contained in:
Raul Marin 2018-05-25 17:12:05 +02:00
parent a396282189
commit 8e11ef3fd7
7 changed files with 32 additions and 50 deletions

View file

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

View file

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

View file

@ -140,23 +140,12 @@ 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_);
if (clip)
{
double padding = static_cast<double>(common_.query_extent_.width() / common_.width_);
double half_stroke = 0.5 * width;
if (half_stroke > 1)
{
padding *= half_stroke;
}
if (std::fabs(offset) > 0)
{
padding *= std::fabs(offset) * 1.2;
}
double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
double pixels = std::ceil(std::max(width / 2.0 + std::fabs(offset),
(std::fabs(offset) * offset_converter_default_threshold)));
double padding = pad_per_pixel * pixels * common_.scale_factor_;
padding *= common_.scale_factor_;
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)

View file

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

View file

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