namespace IPDF
{
-Path::Path(const Objects & objects, unsigned start, unsigned end, const Colour & fill, const Colour & stroke)
+Path::Path(Objects & objects, unsigned start, unsigned end, const Colour & fill, const Colour & stroke)
: m_start(start), m_end(end), m_fill(fill), m_stroke(stroke)
{
Real xmin = 0; Real ymin = 0;
// Find the bounds coordinates
// and identify the top left and bottom right objects
- unsigned left;
- unsigned right;
- unsigned top;
- unsigned bottom;
+ unsigned left = m_start;
+ unsigned right = m_start;
+ unsigned top = m_start;
+ unsigned bottom = m_start;
for (unsigned i = m_start; i <= m_end; ++i)
{
+ if (i >= objects.bounds.size())
+ break;
const Rect & objb = objects.bounds[i];
if (i == m_start || objb.x < xmin)
{
ymax = (objb.y+objb.h);
bottom = i;
- }
-
- // find fill points
- Vec2 pt;
- // left
- pt = Vec2(objb.x, objb.y+objb.h/Real(2));
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- // right
- pt = Vec2(objb.x+objb.w, objb.y+objb.h/Real(2));
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- // bottom
- pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h);
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- // top
- pt = Vec2(objb.x+objb.w/Real(2), objb.y);
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
-
- // topleft
- pt = Vec2(objb.x, objb.y);
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- // topright
- pt = Vec2(objb.x+objb.w, objb.y);
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- // bottom left
- pt = Vec2(objb.x, objb.y+objb.h);
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- // bottom right
- pt = Vec2(objb.x+objb.w, objb.y);
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
-
- // mid
- pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h/Real(2));
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
-
-
+ }
}
// Get actual turning point coords of the 4 edge case beziers
m_top = objects.beziers[objects.data_indices[top]].ToAbsolute(objects.bounds[top]).GetTop();
m_bottom = objects.beziers[objects.data_indices[bottom]].ToAbsolute(objects.bounds[bottom]).GetBottom();
m_left = objects.beziers[objects.data_indices[left]].ToAbsolute(objects.bounds[left]).GetLeft();
- m_right = objects.beziers[objects.data_indices[right]].ToAbsolute(objects.bounds[right]).GetRight();
+ m_right = objects.beziers[objects.data_indices[right]].ToAbsolute(objects.bounds[right]).GetRight();
- Vec2 pt = (m_top + m_bottom)/2;
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- pt = (m_left + m_right)/2;
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
- pt = (m_left + m_right + m_top + m_bottom)/4;
- if (PointInside(objects, pt))
- m_fill_points.push_back(pt);
-
+ m_bounds = SolveBounds(objects).Convert<PReal>();
+ #ifdef TRANSFORM_BEZIERS_TO_PATH
+ for (unsigned i = m_start; i <= m_end; ++i)
+ {
+ //Debug("Transform %s -> %s", objects.bounds[i].Str().c_str(), bounds.Str().c_str());
+ objects.bounds[i] = TransformRectCoordinates(m_bounds.Convert<Real>(), objects.bounds[i]);
+ //Debug("-> %s", objects.bounds[i].Str().c_str());
+ }
+ #endif
}
for (unsigned i = 0; i < x_ints.size(); ++i)
{
if (debug)
- Debug("X Intersection %u at %f,%f vs %f,%f", i,x_ints[i].x, x_ints[i].y, pt.x, pt.y);
+ 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));
if (x_ints[i].y >= pt.y)
{
for (unsigned i = 0; i < y_ints.size(); ++i)
{
if (debug)
- Debug("Y Intersection %u at %f,%f vs %f,%f", i,x_ints[i].x, x_ints[i].y, pt.x, pt.y);
+ 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));
if (y_ints[i].x >= pt.x)
{
return true;
}
-Rect Path::SolveBounds(const Objects & objects) const
+vector<Vec2> & Path::FillPoints(const Objects & objects, const View & view)
+{
+ //if (m_fill_points.size() != 0)
+ return m_fill_points;
+
+
+ for (unsigned i = m_start; i <= m_end; ++i)
+ {
+ const Rect & objb = objects.bounds[i];
+ // find fill points
+ Vec2 pt;
+ // left
+ pt = Vec2(objb.x, objb.y+objb.h/Real(2));
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ // right
+ pt = Vec2(objb.x+objb.w, objb.y+objb.h/Real(2));
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ // bottom
+ pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h);
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ // top
+ pt = Vec2(objb.x+objb.w/Real(2), objb.y);
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+
+ // topleft
+ pt = Vec2(objb.x, objb.y);
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ // topright
+ pt = Vec2(objb.x+objb.w, objb.y);
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ // bottom left
+ pt = Vec2(objb.x, objb.y+objb.h);
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ // bottom right
+ pt = Vec2(objb.x+objb.w, objb.y);
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+
+ // mid
+ pt = Vec2(objb.x+objb.w/Real(2), objb.y+objb.h/Real(2));
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+
+
+ }
+
+ // 4 extrema
+ Vec2 pt = (m_top + m_bottom)/2;
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ pt = (m_left + m_right)/2;
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+ pt = (m_left + m_right + m_top + m_bottom)/4;
+ if (PointInside(objects, pt))
+ m_fill_points.push_back(pt);
+
+ return m_fill_points;
+}
+
+Rect Path::SolveBounds(const Objects & objects)
+{
+ return Rect(m_left.x, m_top.y, m_right.x-m_left.x, m_bottom.y-m_top.y);
+}
+
+Rect & Path::GetBounds(Objects & objects)
{
- return Rect(m_left.x, m_top.y, m_right.x-m_left.x, m_bottom.y-m_top.y);
+ objects.bounds[m_index] = m_bounds.Convert<Real>();
+ return objects.bounds[m_index];
}
}