X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fbezier.h;h=77429cf9033ba06cb199d7ebb0d4fdaef042caa9;hp=3f47555c662d5bd63f5fc13486ccf8fc27c2465c;hb=b716ae547424e4e4bbda86781a151c31e3a64e67;hpb=326f04a375ce3120f7e8957e3d7cd5f296f513e3 diff --git a/src/bezier.h b/src/bezier.h index 3f47555..77429cf 100644 --- a/src/bezier.h +++ b/src/bezier.h @@ -151,7 +151,7 @@ namespace IPDF // (So can't just use the Copy constructor on the inverse of bounds) // BRect inverse = {-bounds.x/bounds.w, -bounds.y/bounds.h, BReal(1)/bounds.w, BReal(1)/bounds.h}; Bezier result; - if (bounds.w == 0) + if (bounds.w == BReal(0)) { result.x0 = 0; result.x1 = 0; @@ -166,7 +166,7 @@ namespace IPDF result.x3 = (x3 - bounds.x)/bounds.w; } - if (bounds.h == 0) + if (bounds.h == BReal(0)) { result.y0 = 0; result.y1 = 0; @@ -258,47 +258,52 @@ namespace IPDF // Find points of intersection with the rectangle. Debug("Clipping Bezier to BRect %s", r.Str().c_str()); + bool isVerticalLine = false;//(x0 == x1 && x1 == x2 && x2 == x3); + bool isHorizontalLine = false;//(y0 == y1 && y1 == y2 && y2 == y3); // Find its roots. - std::vector x_intersection = SolveXParam(r.x); - //Debug("Found %d intersections on left edge", x_intersection.size()); + + std::vector intersection; - // And for the other side. + if (!isVerticalLine) + { + std::vector x_intersection = SolveXParam(r.x); + intersection.insert(intersection.end(), x_intersection.begin(), x_intersection.end()); + Debug("Number of top intersections: %d", x_intersection.size()); - std::vector x_intersection_pt2 = SolveXParam(r.x + r.w); - x_intersection.insert(x_intersection.end(), x_intersection_pt2.begin(), x_intersection_pt2.end()); - //Debug("Found %d intersections on right edge (total x: %d)", x_intersection_pt2.size(), x_intersection.size()); + // And for the other side. + + std::vector x_intersection_pt2 = SolveXParam(r.x + r.w); + intersection.insert(intersection.end(), x_intersection_pt2.begin(), x_intersection_pt2.end()); + Debug("Number of bottom intersections: %d", x_intersection_pt2.size()); + } // Find its roots. - std::vector y_intersection = SolveYParam(r.y); - //Debug("Found %d intersections on top edge", y_intersection.size()); + if (!isHorizontalLine) + { + std::vector y_intersection = SolveYParam(r.y); + intersection.insert(intersection.end(), y_intersection.begin(), y_intersection.end()); + Debug("Number of left intersections: %d", y_intersection.size()); - std::vector y_intersection_pt2 = SolveYParam(r.y+r.h); - y_intersection.insert(y_intersection.end(), y_intersection_pt2.begin(), y_intersection_pt2.end()); - //Debug("Found %d intersections on bottom edge (total y: %d)", y_intersection_pt2.size(), y_intersection.size()); + std::vector y_intersection_pt2 = SolveYParam(r.y+r.h); + intersection.insert(intersection.end(), y_intersection_pt2.begin(), y_intersection_pt2.end()); + Debug("Number of right intersections: %d", y_intersection_pt2.size()); + } // Merge and sort. - x_intersection.insert(x_intersection.end(), y_intersection.begin(), y_intersection.end()); - x_intersection.push_back(BReal(0)); - x_intersection.push_back(BReal(1)); - std::sort(x_intersection.begin(), x_intersection.end()); - - //Debug("Found %d intersections.\n", x_intersection.size()); - /*for(auto t : x_intersection) - { - BReal ptx, pty; - Evaluate(ptx, pty, t); - Debug("Root: t = %f, (%f,%f)", Double(t), Double(ptx), Double(pty)); - }*/ + intersection.push_back(BReal(0)); + intersection.push_back(BReal(1)); + std::sort(intersection.begin(), intersection.end()); + Debug("Number of intersections: %d", intersection.size()); std::vector all_beziers; - if (x_intersection.size() <= 2) + if (intersection.size() <= 2) { all_beziers.push_back(*this); return all_beziers; } - BReal t0 = *(x_intersection.begin()); - for (auto it = x_intersection.begin()+1; it != x_intersection.end(); ++it) + BReal t0 = *(intersection.begin()); + for (auto it = intersection.begin()+1; it != intersection.end(); ++it) { BReal t1 = *it; if (t1 == t0) continue;