Use double instead of int and avoid rounding when possible.
Closes #1078.
This commit is contained in:
parent
73339b3936
commit
46f80cc6aa
14 changed files with 52 additions and 44 deletions
|
@ -69,7 +69,7 @@ public:
|
|||
void end_map_processing(Map const& map);
|
||||
void start_layer_processing(layer const& lay);
|
||||
void end_layer_processing(layer const& lay);
|
||||
void render_marker(double x, double y, marker & marker, agg::trans_affine const& tr, double opacity);
|
||||
void render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr, double opacity);
|
||||
|
||||
void process(point_symbolizer const& sym,
|
||||
mapnik::feature_ptr const& feature,
|
||||
|
|
|
@ -123,7 +123,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
void render_marker(const int x, const int y, marker &marker, const agg::trans_affine & mtx, double opacity=1.0);
|
||||
void render_marker(pixel_position const& pos, marker const& marker, const agg::trans_affine & mtx, double opacity=1.0);
|
||||
|
||||
Map const& m_;
|
||||
Cairo::RefPtr<Cairo::Context> context_;
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
void end_map_processing(Map const& map);
|
||||
void start_layer_processing(layer const& lay);
|
||||
void end_layer_processing(layer const& lay);
|
||||
void render_marker(mapnik::feature_ptr const& feature, unsigned int step, const int x, const int y, marker &marker, const agg::trans_affine & tr, double opacity);
|
||||
void render_marker(mapnik::feature_ptr const& feature, unsigned int step, pixel_position const& pos, marker const& marker, const agg::trans_affine & tr, double opacity);
|
||||
|
||||
void process(point_symbolizer const& sym,
|
||||
mapnik::feature_ptr const& feature,
|
||||
|
|
|
@ -79,20 +79,20 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
inline unsigned width() const
|
||||
inline double width() const
|
||||
{
|
||||
if (is_bitmap())
|
||||
return (*bitmap_data_)->width();
|
||||
else if (is_vector())
|
||||
return static_cast<unsigned>((*vector_data_)->bounding_box().width());
|
||||
return (*vector_data_)->bounding_box().width();
|
||||
return 0;
|
||||
}
|
||||
inline unsigned height() const
|
||||
inline double height() const
|
||||
{
|
||||
if (is_bitmap())
|
||||
return (*bitmap_data_)->height();
|
||||
else if (is_vector())
|
||||
return static_cast<unsigned>((*vector_data_)->bounding_box().height());
|
||||
return (*vector_data_)->bounding_box().height();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -106,12 +106,12 @@ public:
|
|||
return vector_data_;
|
||||
}
|
||||
|
||||
boost::optional<mapnik::image_ptr> get_bitmap_data()
|
||||
boost::optional<mapnik::image_ptr> get_bitmap_data() const
|
||||
{
|
||||
return bitmap_data_;
|
||||
}
|
||||
|
||||
boost::optional<mapnik::path_ptr> get_vector_data()
|
||||
boost::optional<mapnik::path_ptr> get_vector_data() const
|
||||
{
|
||||
return vector_data_;
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ public:
|
|||
}
|
||||
|
||||
text_placement_info_ptr get_placement();
|
||||
std::pair<int, int> get_marker_position(text_path &p);
|
||||
pixel_position get_marker_position(text_path const& p);
|
||||
marker &get_marker() const;
|
||||
agg::trans_affine const& get_transform() const;
|
||||
protected:
|
||||
|
|
|
@ -223,7 +223,7 @@ void agg_renderer<T>::end_layer_processing(layer const&)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void agg_renderer<T>::render_marker(double x, double y, marker & marker, agg::trans_affine const& tr, double opacity)
|
||||
void agg_renderer<T>::render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr, double opacity)
|
||||
{
|
||||
if (marker.is_vector())
|
||||
{
|
||||
|
@ -246,7 +246,7 @@ void agg_renderer<T>::render_marker(double x, double y, marker & marker, agg::tr
|
|||
mtx *= tr;
|
||||
mtx *= agg::trans_affine_scaling(scale_factor_);
|
||||
// render the marker at the center of the marker box
|
||||
mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height());
|
||||
mtx.translate(pos.x+0.5 * marker.width(), pos.y+0.5 * marker.height());
|
||||
|
||||
vertex_stl_adapter<svg_path_storage> stl_storage((*marker.get_vector_data())->source());
|
||||
svg_path_adapter svg_path(stl_storage);
|
||||
|
@ -264,8 +264,8 @@ void agg_renderer<T>::render_marker(double x, double y, marker & marker, agg::tr
|
|||
{
|
||||
//TODO: Add subpixel support
|
||||
pixmap_.set_rectangle_alpha2(**marker.get_bitmap_data(),
|
||||
boost::math::iround(x),
|
||||
boost::math::iround(y),
|
||||
boost::math::iround(pos.x),
|
||||
boost::math::iround(pos.y),
|
||||
opacity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,8 +87,8 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
|
|||
double y1 = bbox.miny();
|
||||
double x2 = bbox.maxx();
|
||||
double y2 = bbox.maxy();
|
||||
int w = (*mark)->width();
|
||||
int h = (*mark)->height();
|
||||
double w = (*mark)->width();
|
||||
double h = (*mark)->height();
|
||||
|
||||
agg::trans_affine recenter = agg::trans_affine_translation(-0.5*(x1+x2),-0.5*(y1+y2));
|
||||
tr.transform(&x1,&y1);
|
||||
|
@ -120,7 +120,7 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
|
|||
detector_->has_placement(extent))
|
||||
{
|
||||
|
||||
render_marker(floor(x - 0.5 * w),floor(y - 0.5 * h) ,**mark,tr, sym.get_opacity());
|
||||
render_marker(pixel_position(x - 0.5 * w, y - 0.5 * h) ,**mark, tr, sym.get_opacity());
|
||||
|
||||
// TODO - impl this for markers?
|
||||
//if (!sym.get_ignore_placement())
|
||||
|
|
|
@ -62,8 +62,8 @@ void agg_renderer<T>::process(point_symbolizer const& sym,
|
|||
|
||||
if (marker)
|
||||
{
|
||||
int w = (*marker)->width();
|
||||
int h = (*marker)->height();
|
||||
double w = (*marker)->width();
|
||||
double h = (*marker)->height();
|
||||
agg::trans_affine tr;
|
||||
boost::array<double,6> const& m = sym.get_transform();
|
||||
tr.load_from(&m[0]);
|
||||
|
@ -102,7 +102,7 @@ void agg_renderer<T>::process(point_symbolizer const& sym,
|
|||
detector_->has_placement(label_ext))
|
||||
{
|
||||
|
||||
render_marker(floor(x - 0.5 * w),floor(y - 0.5 * h) ,**marker,tr, sym.get_opacity());
|
||||
render_marker(pixel_position(x - 0.5 * w, y - 0.5 * h) ,**marker,tr, sym.get_opacity());
|
||||
|
||||
if (!sym.get_ignore_placement())
|
||||
detector_->insert(label_ext);
|
||||
|
|
|
@ -54,8 +54,8 @@ void agg_renderer<T>::process(shield_symbolizer const& sym,
|
|||
while ((placement = helper.get_placement())) {
|
||||
for (unsigned int ii = 0; ii < placement->placements.size(); ++ii)
|
||||
{
|
||||
std::pair<int, int> marker_pos = helper.get_marker_position(placement->placements[ii]);
|
||||
render_marker(marker_pos.first, marker_pos.second, helper.get_marker(), helper.get_transform(), sym.get_opacity());
|
||||
pixel_position marker_pos = helper.get_marker_position(placement->placements[ii]);
|
||||
render_marker(marker_pos, helper.get_marker(), helper.get_transform(), sym.get_opacity());
|
||||
|
||||
ren.prepare_glyphs(&(placement->placements[ii]));
|
||||
ren.render(placement->placements[ii].center);
|
||||
|
|
|
@ -884,7 +884,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
|
|||
}
|
||||
}
|
||||
|
||||
void cairo_renderer_base::render_marker(const int x, const int y, marker &marker, const agg::trans_affine & tr, double opacity)
|
||||
void cairo_renderer_base::render_marker(pixel_position const& pos, marker const& marker, const agg::trans_affine & tr, double opacity)
|
||||
|
||||
{
|
||||
cairo_context context(context_);
|
||||
|
@ -899,7 +899,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
|
|||
// apply symbol transformation to get to map space
|
||||
mtx *= tr;
|
||||
// render the marker at the center of the marker box
|
||||
mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height());
|
||||
mtx.translate(pos.x+0.5 * marker.width(), pos.y+0.5 * marker.height());
|
||||
|
||||
typedef coord_transform2<CoordTransform,geometry_type> path_type;
|
||||
mapnik::path_ptr vmarker = *marker.get_vector_data();
|
||||
|
@ -981,7 +981,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
|
|||
}
|
||||
else if (marker.is_bitmap())
|
||||
{
|
||||
context.add_image(x, y, **marker.get_bitmap_data(), opacity);
|
||||
context.add_image(pos.x, pos.y, **marker.get_bitmap_data(), opacity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1031,7 +1031,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
|
|||
boost::array<double,6> const& m = sym.get_transform();
|
||||
mtx.load_from(&m[0]);
|
||||
|
||||
render_marker(px,py,**marker, mtx, sym.get_opacity());
|
||||
render_marker(pixel_position(px,py),**marker, mtx, sym.get_opacity());
|
||||
|
||||
if (!sym.get_ignore_placement())
|
||||
detector_.insert(label_ext);
|
||||
|
@ -1062,8 +1062,8 @@ void cairo_renderer_base::start_map_processing(Map const& map)
|
|||
while ((placement = helper.get_placement())) {
|
||||
for (unsigned int ii = 0; ii < placement->placements.size(); ++ii)
|
||||
{
|
||||
std::pair<int, int> marker_pos = helper.get_marker_position(placement->placements[ii]);
|
||||
render_marker(marker_pos.first, marker_pos.second,
|
||||
pixel_position marker_pos = helper.get_marker_position(placement->placements[ii]);
|
||||
render_marker(marker_pos,
|
||||
helper.get_marker(), helper.get_transform(),
|
||||
sym.get_opacity());
|
||||
context.add_text(placement->placements[ii], face_manager_, font_manager_);
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
// boost
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
|
||||
// agg
|
||||
#include "agg_trans_affine.h"
|
||||
|
@ -118,7 +119,7 @@ void grid_renderer<T>::end_layer_processing(layer const&)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void grid_renderer<T>::render_marker(mapnik::feature_ptr const& feature, unsigned int step, const int x, const int y, marker &marker, const agg::trans_affine & tr, double opacity)
|
||||
void grid_renderer<T>::render_marker(mapnik::feature_ptr const& feature, unsigned int step, pixel_position const& pos, marker const& marker, agg::trans_affine const& tr, double opacity)
|
||||
{
|
||||
if (marker.is_vector())
|
||||
{
|
||||
|
@ -143,7 +144,7 @@ void grid_renderer<T>::render_marker(mapnik::feature_ptr const& feature, unsigne
|
|||
mtx *= tr;
|
||||
mtx *= agg::trans_affine_scaling(scale_factor_*(1.0/step));
|
||||
// render the marker at the center of the marker box
|
||||
mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height());
|
||||
mtx.translate(pos.x+0.5 * marker.width(), pos.y+0.5 * marker.height());
|
||||
|
||||
vertex_stl_adapter<svg_path_storage> stl_storage((*marker.get_vector_data())->source());
|
||||
svg_path_adapter svg_path(stl_storage);
|
||||
|
@ -161,7 +162,9 @@ void grid_renderer<T>::render_marker(mapnik::feature_ptr const& feature, unsigne
|
|||
image_data_32 const& data = **marker.get_bitmap_data();
|
||||
if (step == 1 && scale_factor_ == 1.0)
|
||||
{
|
||||
pixmap_.set_rectangle(feature->id(), data, x, y);
|
||||
pixmap_.set_rectangle(feature->id(), data,
|
||||
boost::math::iround(pos.x),
|
||||
boost::math::iround(pos.y));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -169,7 +172,9 @@ void grid_renderer<T>::render_marker(mapnik::feature_ptr const& feature, unsigne
|
|||
image_data_32 target(ratio * data.width(), ratio * data.height());
|
||||
mapnik::scale_image_agg<image_data_32>(target,data, SCALING_NEAR,
|
||||
scale_factor_, 0.0, 0.0, 1.0, ratio);
|
||||
pixmap_.set_rectangle(feature->id(), target, x, y);
|
||||
pixmap_.set_rectangle(feature->id(), target,
|
||||
boost::math::iround(pos.x),
|
||||
boost::math::iround(pos.y));
|
||||
}
|
||||
}
|
||||
pixmap_.add_feature(feature);
|
||||
|
|
|
@ -70,11 +70,11 @@ void grid_renderer<T>::process(point_symbolizer const& sym,
|
|||
prj_trans.backward(x,y,z);
|
||||
t_.forward(&x,&y);
|
||||
|
||||
int w = (*marker)->width() * (1.0/pixmap_.get_resolution());
|
||||
int h = (*marker)->height() * (1.0/pixmap_.get_resolution());
|
||||
double w = (*marker)->width() * (1.0/pixmap_.get_resolution());
|
||||
double h = (*marker)->height() * (1.0/pixmap_.get_resolution());
|
||||
|
||||
int px = int(floor(x - 0.5 * w));
|
||||
int py = int(floor(y - 0.5 * h));
|
||||
double px = x - 0.5 * w;
|
||||
double py = y - 0.5 * h;
|
||||
box2d<double> label_ext (px, py, px + w, py + h);
|
||||
if (sym.get_allow_overlap() ||
|
||||
detector_.has_placement(label_ext))
|
||||
|
@ -83,7 +83,10 @@ void grid_renderer<T>::process(point_symbolizer const& sym,
|
|||
boost::array<double,6> const& m = sym.get_transform();
|
||||
tr.load_from(&m[0]);
|
||||
|
||||
render_marker(feature,pixmap_.get_resolution(),px,py,**marker,tr, sym.get_opacity());
|
||||
render_marker(feature, pixmap_.get_resolution(),
|
||||
pixel_position(px, py),
|
||||
**marker, tr,
|
||||
sym.get_opacity());
|
||||
|
||||
if (!sym.get_ignore_placement())
|
||||
detector_.insert(label_ext);
|
||||
|
|
|
@ -60,9 +60,9 @@ void grid_renderer<T>::process(shield_symbolizer const& sym,
|
|||
placement_found = true;
|
||||
for (unsigned int ii = 0; ii < placement->placements.size(); ++ii)
|
||||
{
|
||||
std::pair<int, int> marker_pos = helper.get_marker_position(placement->placements[ii]);
|
||||
pixel_position marker_pos = helper.get_marker_position(placement->placements[ii]);
|
||||
render_marker(feature, pixmap_.get_resolution(),
|
||||
marker_pos.first, marker_pos.second,
|
||||
marker_pos,
|
||||
helper.get_marker(), helper.get_transform(),
|
||||
sym.get_opacity());
|
||||
|
||||
|
|
|
@ -358,21 +358,21 @@ void shield_symbolizer_helper<FaceManagerT, DetectorT>::init_marker()
|
|||
}
|
||||
|
||||
template <typename FaceManagerT, typename DetectorT>
|
||||
std::pair<int, int> shield_symbolizer_helper<FaceManagerT, DetectorT>::get_marker_position(text_path &p)
|
||||
pixel_position shield_symbolizer_helper<FaceManagerT, DetectorT>::get_marker_position(text_path const& p)
|
||||
{
|
||||
position const& pos = placement_->properties.displacement;
|
||||
if (placement_->properties.label_placement == LINE_PLACEMENT) {
|
||||
double lx = p.center.x - pos.first;
|
||||
double ly = p.center.y - pos.second;
|
||||
int px = lx - 0.5*marker_w_;
|
||||
int py = ly - 0.5*marker_h_;
|
||||
double px = lx - 0.5*marker_w_;
|
||||
double py = ly - 0.5*marker_h_;
|
||||
marker_ext_.re_center(lx, ly);
|
||||
// detector_->insert(label_ext); //TODO: Is this done by placement_finder?
|
||||
|
||||
if (writer_.first) writer_.first->add_box(marker_ext_, feature_, t_, writer_.second);
|
||||
return std::make_pair(px, py);
|
||||
return pixel_position(px, py);
|
||||
} else {
|
||||
return std::make_pair(marker_x_, marker_y_);
|
||||
return pixel_position(marker_x_, marker_y_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue