un-template markers_basic_placement
- move Locator/Detector-dependent stuff back to markers_point_placement - slightly reduces library size, by about 20% of what #3338 added
This commit is contained in:
parent
b02a8c3caf
commit
d9339e4bfc
3 changed files with 52 additions and 50 deletions
|
@ -37,8 +37,6 @@ template <typename Locator, typename Detector>
|
||||||
class markers_placement_finder : util::noncopyable
|
class markers_placement_finder : util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using basic_placement = markers_basic_placement<Locator, Detector>;
|
|
||||||
|
|
||||||
markers_placement_finder(marker_placement_e placement_type,
|
markers_placement_finder(marker_placement_e placement_type,
|
||||||
Locator &locator,
|
Locator &locator,
|
||||||
Detector &detector,
|
Detector &detector,
|
||||||
|
@ -75,7 +73,7 @@ public:
|
||||||
|
|
||||||
~markers_placement_finder()
|
~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.
|
// 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:
|
private:
|
||||||
basic_placement* active_placement_;
|
markers_basic_placement* active_placement_;
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,43 +46,27 @@ struct markers_placement_params
|
||||||
direction_enum direction;
|
direction_enum direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Locator, typename Detector>
|
|
||||||
class markers_basic_placement : util::noncopyable
|
class markers_basic_placement : util::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
markers_basic_placement(Locator & locator, Detector & detector,
|
markers_basic_placement(markers_placement_params const& params)
|
||||||
markers_placement_params const& params)
|
: params_(params)
|
||||||
: locator_(locator),
|
|
||||||
detector_(detector),
|
|
||||||
params_(params),
|
|
||||||
done_(false)
|
|
||||||
{
|
{
|
||||||
// no need to rewind locator here, markers_placement_finder
|
|
||||||
// does that after construction
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markers_basic_placement(markers_basic_placement && ) = default;
|
|
||||||
|
|
||||||
virtual ~markers_basic_placement()
|
virtual ~markers_basic_placement()
|
||||||
{
|
{
|
||||||
// empty but necessary
|
// empty but necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start again at first marker. Returns the same list of markers only works when they were NOT added to the detector.
|
// Start again at first marker. Returns the same list of markers only works when they were NOT added to the detector.
|
||||||
virtual void rewind()
|
virtual void rewind() = 0;
|
||||||
{
|
|
||||||
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.
|
// 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;
|
virtual bool get_point(double &x, double &y, double &angle, bool ignore_placement) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Locator & locator_;
|
|
||||||
Detector & detector_;
|
|
||||||
markers_placement_params const& params_;
|
markers_placement_params const& params_;
|
||||||
bool done_;
|
|
||||||
|
|
||||||
// Rotates the size_ box and translates the position.
|
// Rotates the size_ box and translates the position.
|
||||||
box2d<double> perform_transform(double angle, double dx, double dy) const
|
box2d<double> perform_transform(double angle, double dx, double dy) const
|
||||||
|
@ -91,30 +75,6 @@ protected:
|
||||||
return box2d<double>(params_.size, tr);
|
return box2d<double>(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
|
bool set_direction(double & angle) const
|
||||||
{
|
{
|
||||||
switch (params_.direction)
|
switch (params_.direction)
|
||||||
|
|
|
@ -30,11 +30,26 @@
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
template <typename Locator, typename Detector>
|
template <typename Locator, typename Detector>
|
||||||
class markers_point_placement : public markers_basic_placement<Locator, Detector>
|
class markers_point_placement : public markers_basic_placement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using basic_placement = markers_basic_placement<Locator, Detector>;
|
markers_point_placement(Locator & locator, Detector & detector,
|
||||||
using basic_placement::basic_placement;
|
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.
|
// 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)
|
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
|
||||||
|
@ -71,6 +86,35 @@ public:
|
||||||
this->done_ = true;
|
this->done_ = true;
|
||||||
return 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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue