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
17 unsigned left = m_start;
18 unsigned right = m_start;
19 unsigned top = m_start;
20 unsigned bottom = m_start;
22 for (unsigned i = m_start; i <= m_end; ++i)
24 if (i >= objects.bounds.size())
26 const Rect & objb = objects.bounds[i];
28 if (i == m_start || objb.x < xmin)
33 if (i == m_start || (objb.x+objb.w) > xmax)
35 xmax = (objb.x+objb.w);
39 if (i == m_start || objb.y < ymin)
44 if (i == m_start || (objb.y+objb.h) > ymax)
46 ymax = (objb.y+objb.h);
51 // Get actual turning point coords of the 4 edge case beziers
52 m_top = objects.beziers[objects.data_indices[top]].ToAbsolute(objects.bounds[top]).GetTop();
53 m_bottom = objects.beziers[objects.data_indices[bottom]].ToAbsolute(objects.bounds[bottom]).GetBottom();
54 m_left = objects.beziers[objects.data_indices[left]].ToAbsolute(objects.bounds[left]).GetLeft();
55 m_right = objects.beziers[objects.data_indices[right]].ToAbsolute(objects.bounds[right]).GetRight();
59 bool Path::PointInside(const Objects & objects, const Vec2 & pt, bool debug) const
63 for (unsigned i = m_start; i <= m_end; ++i)
65 Bezier bez(objects.beziers[objects.data_indices[i]].ToAbsolute(objects.bounds[i]));
66 vector<Vec2> xi(bez.SolveX(pt.x));
67 vector<Vec2> yi(bez.SolveY(pt.y));
68 x_ints.insert(x_ints.end(), xi.begin(), xi.end());
69 y_ints.insert(y_ints.end(), yi.begin(), yi.end());
71 //Debug("Solved for intersections");
74 for (unsigned i = 0; i < x_ints.size(); ++i)
77 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));
78 if (x_ints[i].y >= pt.y)
84 smaller = x_ints.size() - bigger;
87 Debug("%u horizontal, %u bigger, %u smaller", x_ints.size(), bigger, smaller);
89 if (smaller % 2 == 0 || bigger % 2 == 0)
95 for (unsigned i = 0; i < y_ints.size(); ++i)
98 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));
99 if (y_ints[i].x >= pt.x)
105 smaller = y_ints.size() - bigger;
108 Debug("%u vertical, %u bigger, %u smaller", y_ints.size(), bigger, smaller);
110 if (smaller % 2 == 0 || bigger % 2 == 0)
117 vector<Vec2> & Path::FillPoints(const Objects & objects, const View & view)
119 if (m_fill_points.size() != 0)
120 return m_fill_points;
123 for (unsigned i = m_start; i <= m_end; ++i)
125 const Rect & objb = objects.bounds[i];
129 pt = Vec2(objb.x, objb.y+objb.h/Real(2));
130 if (PointInside(objects, pt))
131 m_fill_points.push_back(pt);
133 pt = Vec2(objb.x+objb.w, objb.y+objb.h/Real(2));
134 if (PointInside(objects, pt))
135 m_fill_points.push_back(pt);
137 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h);
138 if (PointInside(objects, pt))
139 m_fill_points.push_back(pt);
141 pt = Vec2(objb.x+objb.w/Real(2), objb.y);
142 if (PointInside(objects, pt))
143 m_fill_points.push_back(pt);
146 pt = Vec2(objb.x, objb.y);
147 if (PointInside(objects, pt))
148 m_fill_points.push_back(pt);
150 pt = Vec2(objb.x+objb.w, objb.y);
151 if (PointInside(objects, pt))
152 m_fill_points.push_back(pt);
154 pt = Vec2(objb.x, objb.y+objb.h);
155 if (PointInside(objects, pt))
156 m_fill_points.push_back(pt);
158 pt = Vec2(objb.x+objb.w, objb.y);
159 if (PointInside(objects, pt))
160 m_fill_points.push_back(pt);
163 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h/Real(2));
164 if (PointInside(objects, pt))
165 m_fill_points.push_back(pt);
171 Vec2 pt = (m_top + m_bottom)/2;
172 if (PointInside(objects, pt))
173 m_fill_points.push_back(pt);
174 pt = (m_left + m_right)/2;
175 if (PointInside(objects, pt))
176 m_fill_points.push_back(pt);
177 pt = (m_left + m_right + m_top + m_bottom)/4;
178 if (PointInside(objects, pt))
179 m_fill_points.push_back(pt);
181 return m_fill_points;
184 Rect Path::SolveBounds(const Objects & objects) const
186 return Rect(m_left.x, m_top.y, m_right.x-m_left.x, m_bottom.y-m_top.y);