A Song of Floodfills and Segfaults
[ipdf/code.git] / src / path.cpp
1 #include "ipdf.h"
2 #include "path.h"
3 using namespace std;
4
5 namespace IPDF
6 {
7
8 Path::Path(const Objects & objects, unsigned start, unsigned end, const Colour & fill)
9         : m_start(start), m_end(end), m_fill(fill)
10 {
11         Real xmin = 0; Real ymin = 0; 
12         Real xmax = 0; Real ymax = 0;
13         
14         // Find the bounds coordinates
15         //  and identify the top left and bottom right objects
16         
17         unsigned left;
18         unsigned right;
19         unsigned top;
20         unsigned bottom;
21         
22         for (unsigned i = m_start; i <= m_end; ++i)
23         {
24                 const Rect & objb = objects.bounds[i];
25                 
26                 if (i == m_start || objb.x < xmin)
27                 {
28                         xmin = objb.x;
29                         left = i;
30                 }
31                 if (i == m_start || (objb.x+objb.w) > xmax)
32                 {
33                         xmax = (objb.x+objb.w);
34                         right = i;
35                 }
36                         
37                 if (i == m_start || objb.y < ymin)
38                 {
39                         ymin = objb.y;
40                         top = i;
41                 }
42                 if (i == m_start || (objb.y+objb.h) > ymax)
43                 {
44                         ymax = (objb.y+objb.h);
45                         bottom = i;
46                 }
47         }
48         
49         // Get actual turning point coords of the 4 edge case beziers
50         m_top = objects.beziers[objects.data_indices[top]].ToAbsolute(objects.bounds[top]).GetTop();
51         m_bottom = objects.beziers[objects.data_indices[bottom]].ToAbsolute(objects.bounds[bottom]).GetBottom();
52         m_left = objects.beziers[objects.data_indices[left]].ToAbsolute(objects.bounds[left]).GetLeft();
53         m_right = objects.beziers[objects.data_indices[right]].ToAbsolute(objects.bounds[right]).GetRight();
54         /*Debug("Top: %f, %f", m_top.first, m_top.second);
55         Debug("Bottom: %f, %f", m_bottom.first, m_bottom.second);
56         Debug("Left: %f, %f", m_left.first, m_left.second);
57         Debug("Right: %f, %f", m_right.first, m_right.second);
58         Debug("Left - Right: %f, %f", m_right.first - m_left.first, m_right.second - m_left.second);
59         Debug("Top - Bottom: %f, %f", m_top.first - m_bottom.first, m_top.second - m_bottom.second);
60         */
61 }
62
63 Rect Path::SolveBounds(const Objects & objects) const
64 {
65                 return Rect(m_left.first, m_top.second, m_right.first-m_left.first, m_bottom.second-m_top.second);
66 }
67
68 }

UCC git Repository :: git.ucc.asn.au