diff --git a/include/mapnik/markers_placement.hpp b/include/mapnik/markers_placement.hpp index 02149d767..dad500f60 100644 --- a/include/mapnik/markers_placement.hpp +++ b/include/mapnik/markers_placement.hpp @@ -37,8 +37,6 @@ template class markers_placement_finder : util::noncopyable { public: - using basic_placement = markers_basic_placement; - markers_placement_finder(marker_placement_e placement_type, Locator &locator, Detector &detector, @@ -75,7 +73,7 @@ public: ~markers_placement_finder() { - active_placement_->~basic_placement(); + active_placement_->~markers_basic_placement(); } // Get next point where the marker should be placed. Returns true if a place is found, false if none is found. @@ -85,7 +83,7 @@ public: } private: - basic_placement* active_placement_; + markers_basic_placement* active_placement_; union { diff --git a/include/mapnik/markers_placements/basic.hpp b/include/mapnik/markers_placements/basic.hpp index ede68bb6b..15c3be81c 100644 --- a/include/mapnik/markers_placements/basic.hpp +++ b/include/mapnik/markers_placements/basic.hpp @@ -46,43 +46,27 @@ struct markers_placement_params direction_enum direction; }; -template class markers_basic_placement : util::noncopyable { public: - markers_basic_placement(Locator & locator, Detector & detector, - markers_placement_params const& params) - : locator_(locator), - detector_(detector), - params_(params), - done_(false) + markers_basic_placement(markers_placement_params const& params) + : params_(params) { - // no need to rewind locator here, markers_placement_finder - // does that after construction } - markers_basic_placement(markers_basic_placement && ) = default; - virtual ~markers_basic_placement() { // empty but necessary } // Start again at first marker. Returns the same list of markers only works when they were NOT added to the detector. - virtual void rewind() - { - locator_.rewind(0); - done_ = false; - } + virtual void rewind() = 0; // Get next point where the marker should be placed. Returns true if a place is found, false if none is found. virtual bool get_point(double &x, double &y, double &angle, bool ignore_placement) = 0; protected: - Locator & locator_; - Detector & detector_; markers_placement_params const& params_; - bool done_; // Rotates the size_ box and translates the position. box2d perform_transform(double angle, double dx, double dy) const @@ -91,30 +75,6 @@ protected: return box2d(params_.size, tr); } - // Checks transformed box placement with collision detector. - // returns false if the box: - // - a) isn't wholly inside extent and avoid_edges == true - // - b) collides with something and allow_overlap == false - // otherwise returns true, and if ignore_placement == true, - // also adds the box to collision detector - bool push_to_detector(double x, double y, double angle, bool ignore_placement) - { - auto box = perform_transform(angle, x, y); - if (params_.avoid_edges && !detector_.extent().contains(box)) - { - return false; - } - if (!params_.allow_overlap && !detector_.has_placement(box)) - { - return false; - } - if (!ignore_placement) - { - detector_.insert(box); - } - return true; - } - bool set_direction(double & angle) const { switch (params_.direction) diff --git a/include/mapnik/markers_placements/point.hpp b/include/mapnik/markers_placements/point.hpp index dbbf92c1b..14bf5b2ea 100644 --- a/include/mapnik/markers_placements/point.hpp +++ b/include/mapnik/markers_placements/point.hpp @@ -30,11 +30,26 @@ namespace mapnik { template -class markers_point_placement : public markers_basic_placement +class markers_point_placement : public markers_basic_placement { public: - using basic_placement = markers_basic_placement; - using basic_placement::basic_placement; + markers_point_placement(Locator & locator, Detector & detector, + markers_placement_params const& params) + : markers_basic_placement(params), + locator_(locator), + detector_(detector), + done_(false) + { + // no need to rewind locator here, markers_placement_finder + // does that after construction + } + + // Start again at first marker. Returns the same list of markers only works when they were NOT added to the detector. + void rewind() + { + locator_.rewind(0); + done_ = false; + } // Get next point where the marker should be placed. Returns true if a place is found, false if none is found. bool get_point(double &x, double &y, double &angle, bool ignore_placement) @@ -71,6 +86,35 @@ public: this->done_ = true; return true; } + +protected: + Locator & locator_; + Detector & detector_; + bool done_; + + // Checks transformed box placement with collision detector. + // returns false if the box: + // - a) isn't wholly inside extent and avoid_edges == true + // - b) collides with something and allow_overlap == false + // otherwise returns true, and if ignore_placement == false, + // also adds the box to collision detector + bool push_to_detector(double x, double y, double angle, bool ignore_placement) + { + auto box = perform_transform(angle, x, y); + if (params_.avoid_edges && !detector_.extent().contains(box)) + { + return false; + } + if (!params_.allow_overlap && !detector_.has_placement(box)) + { + return false; + } + if (!ignore_placement) + { + detector_.insert(box); + } + return true; + } }; }