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);
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();
57 bool Path::PointInside(const Objects & objects, const Vec2 & pt, bool debug) const
61 for (unsigned i = m_start; i <= m_end; ++i)
63 Bezier bez(objects.beziers[objects.data_indices[i]].ToAbsolute(objects.bounds[i]));
64 vector<Vec2> xi(bez.SolveX(pt.x));
65 vector<Vec2> yi(bez.SolveY(pt.y));
66 x_ints.insert(x_ints.end(), xi.begin(), xi.end());
67 y_ints.insert(y_ints.end(), yi.begin(), yi.end());
69 //Debug("Solved for intersections");
72 for (unsigned i = 0; i < x_ints.size(); ++i)
75 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));
76 if (x_ints[i].y >= pt.y)
82 smaller = x_ints.size() - bigger;
85 Debug("%u horizontal, %u bigger, %u smaller", x_ints.size(), bigger, smaller);
87 if (smaller % 2 == 0 || bigger % 2 == 0)
93 for (unsigned i = 0; i < y_ints.size(); ++i)
96 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));
97 if (y_ints[i].x >= pt.x)
103 smaller = y_ints.size() - bigger;
106 Debug("%u vertical, %u bigger, %u smaller", y_ints.size(), bigger, smaller);
108 if (smaller % 2 == 0 || bigger % 2 == 0)
115 vector<Vec2> & Path::FillPoints(const Objects & objects, const View & view)
117 if (m_fill_points.size() != 0)
118 return m_fill_points;
121 for (unsigned i = m_start; i <= m_end; ++i)
123 const Rect & objb = objects.bounds[i];
127 pt = Vec2(objb.x, objb.y+objb.h/Real(2));
128 if (PointInside(objects, pt))
129 m_fill_points.push_back(pt);
131 pt = Vec2(objb.x+objb.w, objb.y+objb.h/Real(2));
132 if (PointInside(objects, pt))
133 m_fill_points.push_back(pt);
135 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h);
136 if (PointInside(objects, pt))
137 m_fill_points.push_back(pt);
139 pt = Vec2(objb.x+objb.w/Real(2), objb.y);
140 if (PointInside(objects, pt))
141 m_fill_points.push_back(pt);
144 pt = Vec2(objb.x, objb.y);
145 if (PointInside(objects, pt))
146 m_fill_points.push_back(pt);
148 pt = Vec2(objb.x+objb.w, objb.y);
149 if (PointInside(objects, pt))
150 m_fill_points.push_back(pt);
152 pt = Vec2(objb.x, objb.y+objb.h);
153 if (PointInside(objects, pt))
154 m_fill_points.push_back(pt);
156 pt = Vec2(objb.x+objb.w, objb.y);
157 if (PointInside(objects, pt))
158 m_fill_points.push_back(pt);
161 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h/Real(2));
162 if (PointInside(objects, pt))
163 m_fill_points.push_back(pt);
169 Vec2 pt = (m_top + m_bottom)/2;
170 if (PointInside(objects, pt))
171 m_fill_points.push_back(pt);
172 pt = (m_left + m_right)/2;
173 if (PointInside(objects, pt))
174 m_fill_points.push_back(pt);
175 pt = (m_left + m_right + m_top + m_bottom)/4;
176 if (PointInside(objects, pt))
177 m_fill_points.push_back(pt);
179 return m_fill_points;
182 Rect Path::SolveBounds(const Objects & objects) const
184 return Rect(m_left.x, m_top.y, m_right.x-m_left.x, m_bottom.y-m_top.y);