8 Path::Path(const Objects & objects, unsigned start, unsigned end, const Colour & fill, const Colour & stroke)
9 : m_start(start), m_end(end), m_fill(fill), m_stroke(stroke)
11 Real xmin = 0; Real ymin = 0;
12 Real xmax = 0; Real ymax = 0;
14 // Find the bounds coordinates
15 // and identify the top left and bottom right objects
22 for (unsigned i = m_start; i <= m_end; ++i)
24 const Rect & objb = objects.bounds[i];
26 if (i == m_start || objb.x < xmin)
31 if (i == m_start || (objb.x+objb.w) > xmax)
33 xmax = (objb.x+objb.w);
37 if (i == m_start || objb.y < ymin)
42 if (i == m_start || (objb.y+objb.h) > ymax)
44 ymax = (objb.y+objb.h);
51 pt = Vec2(objb.x, objb.y+objb.h/Real(2));
52 if (PointInside(objects, pt))
53 m_fill_points.push_back(pt);
55 pt = Vec2(objb.x+objb.w, objb.y+objb.h/Real(2));
56 if (PointInside(objects, pt))
57 m_fill_points.push_back(pt);
59 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h);
60 if (PointInside(objects, pt))
61 m_fill_points.push_back(pt);
63 pt = Vec2(objb.x+objb.w/Real(2), objb.y);
64 if (PointInside(objects, pt))
65 m_fill_points.push_back(pt);
68 pt = Vec2(objb.x, objb.y);
69 if (PointInside(objects, pt))
70 m_fill_points.push_back(pt);
72 pt = Vec2(objb.x+objb.w, objb.y);
73 if (PointInside(objects, pt))
74 m_fill_points.push_back(pt);
76 pt = Vec2(objb.x, objb.y+objb.h);
77 if (PointInside(objects, pt))
78 m_fill_points.push_back(pt);
80 pt = Vec2(objb.x+objb.w, objb.y);
81 if (PointInside(objects, pt))
82 m_fill_points.push_back(pt);
85 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h/Real(2));
86 if (PointInside(objects, pt))
87 m_fill_points.push_back(pt);
92 // Get actual turning point coords of the 4 edge case beziers
93 m_top = objects.beziers[objects.data_indices[top]].ToAbsolute(objects.bounds[top]).GetTop();
94 m_bottom = objects.beziers[objects.data_indices[bottom]].ToAbsolute(objects.bounds[bottom]).GetBottom();
95 m_left = objects.beziers[objects.data_indices[left]].ToAbsolute(objects.bounds[left]).GetLeft();
96 m_right = objects.beziers[objects.data_indices[right]].ToAbsolute(objects.bounds[right]).GetRight();
98 Vec2 pt = (m_top + m_bottom)/2;
99 if (PointInside(objects, pt))
100 m_fill_points.push_back(pt);
101 pt = (m_left + m_right)/2;
102 if (PointInside(objects, pt))
103 m_fill_points.push_back(pt);
104 pt = (m_left + m_right + m_top + m_bottom)/4;
105 if (PointInside(objects, pt))
106 m_fill_points.push_back(pt);
111 bool Path::PointInside(const Objects & objects, const Vec2 & pt, bool debug) const
115 for (unsigned i = m_start; i <= m_end; ++i)
117 Bezier bez(objects.beziers[objects.data_indices[i]].ToAbsolute(objects.bounds[i]));
118 vector<Vec2> xi(bez.SolveX(pt.x));
119 vector<Vec2> yi(bez.SolveY(pt.y));
120 x_ints.insert(x_ints.end(), xi.begin(), xi.end());
121 y_ints.insert(y_ints.end(), yi.begin(), yi.end());
123 //Debug("Solved for intersections");
125 unsigned smaller = 0;
126 for (unsigned i = 0; i < x_ints.size(); ++i)
129 Debug("X Intersection %u at %f,%f vs %f,%f", i,Double(x_ints[i].x), Double(x_ints[i].y), Double(pt.x), Double(pt.y));
130 if (x_ints[i].y >= pt.y)
136 smaller = x_ints.size() - bigger;
139 Debug("%u horizontal, %u bigger, %u smaller", x_ints.size(), bigger, smaller);
141 if (smaller % 2 == 0 || bigger % 2 == 0)
147 for (unsigned i = 0; i < y_ints.size(); ++i)
150 Debug("Y Intersection %u at %f,%f vs %f,%f", i,Double(y_ints[i].x), Double(y_ints[i].y), Double(pt.x), Double(pt.y));
151 if (y_ints[i].x >= pt.x)
157 smaller = y_ints.size() - bigger;
160 Debug("%u vertical, %u bigger, %u smaller", y_ints.size(), bigger, smaller);
162 if (smaller % 2 == 0 || bigger % 2 == 0)
169 Rect Path::SolveBounds(const Objects & objects) const
171 return Rect(m_left.x, m_top.y, m_right.x-m_left.x, m_bottom.y-m_top.y);