Merge branch 'master' into cairocanvas
[ardour.git] / libs / canvas / test / polygon.cc
1 #include "canvas/group.h"
2 #include "canvas/types.h"
3 #include "canvas/polygon.h"
4 #include "canvas/canvas.h"
5 #include "polygon.h"
6
7 using namespace std;
8 using namespace ArdourCanvas;
9
10 CPPUNIT_TEST_SUITE_REGISTRATION (PolygonTest);
11
12 void
13 PolygonTest::bounding_box ()
14 {
15         ImageCanvas canvas;
16         Group group (canvas.root ());
17         Polygon polygon (&group);
18
19         /* should have no initial bounding box */
20         CPPUNIT_ASSERT (!polygon.bounding_box().is_initialized());
21
22         Points points;
23         points.push_back (Duple (-6, -6));
24         points.push_back (Duple ( 6, -6));
25         points.push_back (Duple ( 6,  6));
26         points.push_back (Duple (-6,  6));
27         polygon.set (points);
28
29         /* should now have a bounding box around those points,
30            taking into account default line width
31         */
32         boost::optional<Rect> bbox = polygon.bounding_box ();
33         CPPUNIT_ASSERT (bbox.is_initialized ());
34         CPPUNIT_ASSERT (bbox.get().x0 == -6.25);
35         CPPUNIT_ASSERT (bbox.get().x1 ==  6.25);
36         CPPUNIT_ASSERT (bbox.get().y0 == -6.25);
37         CPPUNIT_ASSERT (bbox.get().y1 ==  6.25);
38
39         /* and its parent group should have noticed and adjusted
40            its bounding box
41         */
42
43         bbox = group.bounding_box ();
44         CPPUNIT_ASSERT (bbox.is_initialized ());
45         CPPUNIT_ASSERT (bbox.get().x0 == -6.25);
46         CPPUNIT_ASSERT (bbox.get().x1 ==  6.25);
47         CPPUNIT_ASSERT (bbox.get().y0 == -6.25);
48         CPPUNIT_ASSERT (bbox.get().y1 ==  6.25);
49 }