Add bounding box calculation.
This commit is contained in:
parent
2e22d740cf
commit
ffc3a5d52a
3 changed files with 46 additions and 1 deletions
|
@ -77,7 +77,7 @@ private:
|
|||
static double normalize_angle(double angle);
|
||||
double get_spacing(double path_length, double layout_width) const;
|
||||
bool collision(box2d<double> const& box) const;
|
||||
box2d<double> get_bbox(glyph_info const& glyph, pixel_position const& pos, rotation rot);
|
||||
box2d<double> get_bbox(glyph_info const& glyph, pixel_position const& pos, rotation const& rot);
|
||||
Feature const& feature_;
|
||||
DetectorType &detector_;
|
||||
box2d<double> const& extent_;
|
||||
|
|
|
@ -396,6 +396,15 @@ bool box2d<T>::valid() const
|
|||
return (minx_ <= maxx_ && miny_ <= maxy_) ;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void box2d<T>::move(T x, T y)
|
||||
{
|
||||
minx_ += x;
|
||||
maxx_ += x;
|
||||
miny_ += y;
|
||||
maxy_ += y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
||||
{
|
||||
|
|
|
@ -338,6 +338,8 @@ bool placement_finder_ng::single_line_placement(vertex_cache &pp, text_upright_e
|
|||
cluster_offset.x += rot.cos * glyph_itr->width;
|
||||
cluster_offset.y -= rot.sin * glyph_itr->width;
|
||||
|
||||
// detector_.insert(get_bbox(glyph, pos, rot), layout_.get_text());
|
||||
|
||||
glyphs->push_back(glyph, pos, rot);
|
||||
}
|
||||
}
|
||||
|
@ -403,6 +405,40 @@ bool placement_finder_ng::collision(const box2d<double> &box) const
|
|||
return false;
|
||||
}
|
||||
|
||||
box2d<double> placement_finder_ng::get_bbox(glyph_info const& glyph, pixel_position const& pos, rotation const& rot)
|
||||
{
|
||||
/*
|
||||
|
||||
(0/ymax) (width/ymax)
|
||||
***************
|
||||
* *
|
||||
(0/0)* *
|
||||
* *
|
||||
***************
|
||||
(0/ymin) (width/ymin)
|
||||
Add glyph offset in y direction, but not in x direction (as we use the full cluster width anyways)!
|
||||
*/
|
||||
std::cout << glyph.offset << glyph.width << "," << glyph.ymin << glyph.ymax << "\n";
|
||||
double width = layout_.cluster_width(glyph.char_index);
|
||||
if (glyph.width <= 0) width = -width;
|
||||
pixel_position tmp, tmp2;
|
||||
tmp.set(0, glyph.ymax);
|
||||
tmp = tmp.rotate(rot);
|
||||
tmp2.set(width, glyph.ymax);
|
||||
tmp2 = tmp2.rotate(rot);
|
||||
box2d<double> bbox(tmp.x, -tmp.y,
|
||||
tmp2.x, -tmp2.y);
|
||||
tmp.set(width, glyph.ymin);
|
||||
tmp = tmp.rotate(rot);
|
||||
bbox.expand_to_include(tmp.x, -tmp.y);
|
||||
tmp.set(0, glyph.ymin);
|
||||
tmp = tmp.rotate(rot);
|
||||
bbox.expand_to_include(tmp.x, -tmp.y);
|
||||
pixel_position pos2 = pos + pixel_position(0, glyph.offset.y).rotate(rot);
|
||||
bbox.move(pos2.x , -pos2.y);
|
||||
return bbox;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue