Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement size recalculations for rectangles

  • Loading branch information...
commit 7de9da839d3bf187f02dd142f2da21ad7ff9fddb 1 parent 4f4261a
@hyperair authored
View
50 src/imgpack/algorithm/rectangles.cc
@@ -74,11 +74,13 @@ namespace {
void CompositeRectangle::child1 (Rectangle::Ptr child)
{
set_child (_children.first, child, *this);
+ recalculate_size ();
}
void CompositeRectangle::child2 (Rectangle::Ptr child)
{
set_child (_children.second, child, *this);
+ recalculate_size ();
}
void CompositeRectangle::orphan_child (Rectangle &child)
@@ -90,19 +92,23 @@ void CompositeRectangle::orphan_child (Rectangle &child)
child2 (Rectangle::Ptr ());
}
+void CompositeRectangle::recalculate_size ()
+{
+ if (parent ())
+ parent ()->recalculate_size ();
+
+ else
+ recalculate_size_impl ();
+}
+
+
// HCompositeRectangle definitions
HCompositeRectangle::HCompositeRectangle (ipa::Rectangle::Ptr rect1,
ipa::Rectangle::Ptr rect2) :
CompositeRectangle (rect1, rect2)
{
- double common_height = std::min (rect1->max_height (),
- rect2->max_height ());
-
- LOG(info) << "Equalizing height to " << common_height;
-
- rect1->height (common_height);
- rect2->height (common_height);
+ recalculate_size ();
}
double HCompositeRectangle::width ()
@@ -135,19 +141,24 @@ double HCompositeRectangle::max_width ()
return aspect_ratio () * max_height ();
}
+void HCompositeRectangle::recalculate_size_impl ()
+{
+ double common_height = std::min (child1 ()->max_height (),
+ child2 ()->max_height ());
+
+ LOG(info) << "Equalizing height to " << common_height;
+
+ child1 ()->height (common_height);
+ child2 ()->height (common_height);
+}
+
// VCompositeRectangle definitions
VCompositeRectangle::VCompositeRectangle (ipa::Rectangle::Ptr rect1,
ipa::Rectangle::Ptr rect2) :
CompositeRectangle (rect1, rect2)
{
- double common_width = std::min (rect1->max_width (),
- rect2->max_width ());
-
- LOG(info) << "Equalizing width to " << common_width;
-
- rect1->width (common_width);
- rect2->width (common_width);
+ recalculate_size ();
}
double VCompositeRectangle::height ()
@@ -178,3 +189,14 @@ double VCompositeRectangle::max_width ()
{
return std::min (child1 ()->max_width (), child2 ()->max_width ());
}
+
+void VCompositeRectangle::recalculate_size_impl ()
+{
+ double common_width = std::min (child1 ()->max_width (),
+ child2 ()->max_width ());
+
+ LOG(info) << "Equalizing width to " << common_width;
+
+ child1 ()->width (common_width);
+ child2 ()->width (common_width);
+}
View
11 src/imgpack/algorithm/rectangles.hh
@@ -49,6 +49,7 @@ namespace ImgPack
CompositeRectangle *_parent;
};
+
class CompositeRectangle :
public Rectangle,
public std::enable_shared_from_this<CompositeRectangle>
@@ -67,10 +68,13 @@ namespace ImgPack
void orphan_child (Rectangle &child);
+ void recalculate_size ();
protected:
+ virtual void recalculate_size_impl () = 0;
std::pair<Rectangle::Ptr, Rectangle::Ptr> _children;
};
+
class HCompositeRectangle :
public CompositeRectangle,
public nihpp::SharedPtrCreator<HCompositeRectangle>
@@ -88,8 +92,12 @@ namespace ImgPack
virtual double max_width ();
virtual Orientation orientation () {return HORIZONTAL;}
+
+ private:
+ virtual void recalculate_size_impl ();
};
+
class VCompositeRectangle :
public CompositeRectangle,
public nihpp::SharedPtrCreator<VCompositeRectangle>
@@ -107,6 +115,9 @@ namespace ImgPack
virtual double max_width ();
virtual Orientation orientation () {return VERTICAL;}
+
+ private:
+ virtual void recalculate_size_impl ();
};
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.