8 Path::Path(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();
57 m_bounds = SolveBounds(objects).Convert<PReal>();
58 #ifdef TRANSFORM_BEZIERS_TO_PATH
59 for (unsigned i = m_start; i <= m_end; ++i)
61 //Debug("Transform %s -> %s", objects.bounds[i].Str().c_str(), bounds.Str().c_str());
62 objects.bounds[i] = TransformRectCoordinates(m_bounds.Convert<Real>(), objects.bounds[i]);
63 //Debug("-> %s", objects.bounds[i].Str().c_str());
69 bool Path::PointInside(const Objects & objects, const Vec2 & pt, bool debug) const
73 for (unsigned i = m_start; i <= m_end; ++i)
75 Bezier bez(objects.beziers[objects.data_indices[i]].ToAbsolute(objects.bounds[i]));
76 vector<Vec2> xi(bez.SolveX(pt.x));
77 vector<Vec2> yi(bez.SolveY(pt.y));
78 x_ints.insert(x_ints.end(), xi.begin(), xi.end());
79 y_ints.insert(y_ints.end(), yi.begin(), yi.end());
81 //Debug("Solved for intersections");
84 for (unsigned i = 0; i < x_ints.size(); ++i)
87 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));
88 if (x_ints[i].y >= pt.y)
94 smaller = x_ints.size() - bigger;
97 Debug("%u horizontal, %u bigger, %u smaller", x_ints.size(), bigger, smaller);
99 if (smaller % 2 == 0 || bigger % 2 == 0)
105 for (unsigned i = 0; i < y_ints.size(); ++i)
108 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));
109 if (y_ints[i].x >= pt.x)
115 smaller = y_ints.size() - bigger;
118 Debug("%u vertical, %u bigger, %u smaller", y_ints.size(), bigger, smaller);
120 if (smaller % 2 == 0 || bigger % 2 == 0)
127 vector<Vec2> & Path::FillPoints(const Objects & objects, const View & view)
129 //if (m_fill_points.size() != 0)
130 return m_fill_points;
133 for (unsigned i = m_start; i <= m_end; ++i)
135 const Rect & objb = objects.bounds[i];
139 pt = Vec2(objb.x, objb.y+objb.h/Real(2));
140 if (PointInside(objects, pt))
141 m_fill_points.push_back(pt);
143 pt = Vec2(objb.x+objb.w, objb.y+objb.h/Real(2));
144 if (PointInside(objects, pt))
145 m_fill_points.push_back(pt);
147 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h);
148 if (PointInside(objects, pt))
149 m_fill_points.push_back(pt);
151 pt = Vec2(objb.x+objb.w/Real(2), objb.y);
152 if (PointInside(objects, pt))
153 m_fill_points.push_back(pt);
156 pt = Vec2(objb.x, objb.y);
157 if (PointInside(objects, pt))
158 m_fill_points.push_back(pt);
160 pt = Vec2(objb.x+objb.w, objb.y);
161 if (PointInside(objects, pt))
162 m_fill_points.push_back(pt);
164 pt = Vec2(objb.x, objb.y+objb.h);
165 if (PointInside(objects, pt))
166 m_fill_points.push_back(pt);
168 pt = Vec2(objb.x+objb.w, objb.y);
169 if (PointInside(objects, pt))
170 m_fill_points.push_back(pt);
173 pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h/Real(2));
174 if (PointInside(objects, pt))
175 m_fill_points.push_back(pt);
181 Vec2 pt = (m_top + m_bottom)/2;
182 if (PointInside(objects, pt))
183 m_fill_points.push_back(pt);
184 pt = (m_left + m_right)/2;
185 if (PointInside(objects, pt))
186 m_fill_points.push_back(pt);
187 pt = (m_left + m_right + m_top + m_bottom)/4;
188 if (PointInside(objects, pt))
189 m_fill_points.push_back(pt);
191 return m_fill_points;
194 Rect Path::SolveBounds(const Objects & objects)
196 return Rect(m_left.x, m_top.y, m_right.x-m_left.x, m_bottom.y-m_top.y);
199 Rect & Path::GetBounds(Objects & objects)
201 objects.bounds[m_index] = m_bounds.Convert<Real>();
202 return objects.bounds[m_index];