LibreOffice Module basegfx (master) 1
|
#include <iostream>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <vector>
#include <utility>
#include <math.h>
#include <bezierclip.hxx>
#include <gauss.hxx>
Go to the source code of this file.
Classes | |
struct | ClipBezierFunctor |
struct | BezierTangencyFunctor |
Macros | |
#define | WITH_ASSERTIONS |
#define | WITH_BEZIERCLIP_TEST |
Functions | |
int | fallFac (int n, int k) |
int | fac (int n) |
void | Impl_calcFatLine (FatLine &line, const Bezier &c) |
void | Impl_calcBounds (Point2D &leftTop, Point2D &rightBottom, const Bezier &c1) |
bool | Impl_doBBoxIntersect (const Bezier &c1, const Bezier &c2) |
bool | Impl_calcSafeParams (double &t1, double &t2, const Polygon2D &rPoly, double lowerYBound, double upperYBound) |
bool | Impl_calcSafeParams_clip (double &t1, double &t2, const FatLine &bounds, double c0, double c1, double c2, double c3) |
void | Impl_deCasteljauAt (Bezier &part1, Bezier &part2, const Bezier &input, double t) |
void | printCurvesWithSafeRange (const Bezier &c1, const Bezier &c2, double t1_c1, double t2_c1, const Bezier &c2_part, const FatLine &bounds_c2) |
void | printResultWithFinalCurves (const Bezier &c1, const Bezier &c1_part, const Bezier &c2, const Bezier &c2_part, double t1_c1, double t2_c1) |
bool | Impl_calcClipRange (double &t1, double &t2, const Bezier &c1_orig, const Bezier &c1_part, const Bezier &c2_orig, const Bezier &c2_part) |
determine parameter ranges [0,t1) and (t2,1] on c1, where c1 is guaranteed to lie outside c2. More... | |
void | Impl_calcFocus (Bezier &res, const Bezier &c) |
bool | Impl_calcSafeParams_focus (double &t1, double &t2, const Bezier &curve, const Bezier &focus) |
template<class Functor > | |
void | Impl_applySafeRanges_rec (std::back_insert_iterator< std::vector< std::pair< double, double > > > &result, double delta, const Functor &safeRangeFunctor, int recursionLevel, const Bezier &c1_orig, const Bezier &c1_part, double last_t1_c1, double last_t2_c1, const Bezier &c2_orig, const Bezier &c2_part, double last_t1_c2, double last_t2_c2) |
Calc all values t_i on c1, for which safeRanges functor does not give a safe range on c1 and c2. More... | |
void | clipBezier (std::back_insert_iterator< std::vector< std::pair< double, double > > > &result, double delta, const Bezier &c1, const Bezier &c2) |
Perform a bezier clip (curve against curve) More... | |
int | main (int argc, const char *argv[]) |
#define WITH_ASSERTIONS |
Definition at line 33 of file bezierclip.cxx.
#define WITH_BEZIERCLIP_TEST |
Definition at line 44 of file bezierclip.cxx.
void clipBezier | ( | std::back_insert_iterator< std::vector< std::pair< double, double > > > & | result, |
double | delta, | ||
const Bezier & | c1, | ||
const Bezier & | c2 | ||
) |
Perform a bezier clip (curve against curve)
result | Output iterator where the final t values are added to. This iterator will remain empty, if there are no intersections. |
delta | Maximal allowed distance to true intersection (measured in the original curve's coordinate system) |
Definition at line 1162 of file bezierclip.cxx.
References first, i, Impl_applySafeRanges_rec(), Impl_deCasteljauAt(), and result.
Referenced by main().
Definition at line 71 of file bezierclip.cxx.
Referenced by Impl_calcSafeParams_focus().
Definition at line 56 of file bezierclip.cxx.
References n.
Referenced by fac(), and Impl_calcSafeParams_focus().
void Impl_applySafeRanges_rec | ( | std::back_insert_iterator< std::vector< std::pair< double, double > > > & | result, |
double | delta, | ||
const Functor & | safeRangeFunctor, | ||
int | recursionLevel, | ||
const Bezier & | c1_orig, | ||
const Bezier & | c1_part, | ||
double | last_t1_c1, | ||
double | last_t2_c1, | ||
const Bezier & | c2_orig, | ||
const Bezier & | c2_part, | ||
double | last_t1_c2, | ||
double | last_t2_c2 | ||
) |
Calc all values t_i on c1, for which safeRanges functor does not give a safe range on c1 and c2.
This method is the workhorse of the bezier clipping. Because c1 and c2 must be alternatingly tested against each other (first determine safe parameter interval on c1 with regard to c2, then the other way around), we call this method recursively with c1 and c2 swapped.
result | Output iterator where the final t values are added to. If curves don't intersect, nothing is added. |
delta | Maximal allowed distance to true critical point (measured in the original curve's coordinate system) |
safeRangeFunctor | Functor object, that must provide the following operator(): bool safeRangeFunctor( double& t1, double& t2, const Bezier& c1_orig, const Bezier& c1_part, const Bezier& c2_orig, const Bezier& c2_part ); This functor must calculate the safe ranges [0,t1] and [t2,1] on c1_orig, where c1_orig is 'safe' from c2_part. If the whole c1_orig is safe, false must be returned, true otherwise. |
Definition at line 900 of file bezierclip.cxx.
References i, Impl_applySafeRanges_rec(), Impl_calcFocus(), Impl_deCasteljauAt(), printResultWithFinalCurves(), result, tolGreaterEqual(), and tolLessEqual().
Referenced by clipBezier(), and Impl_applySafeRanges_rec().
Definition at line 121 of file bezierclip.cxx.
References Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, Point2D::x, and Point2D::y.
Referenced by Impl_doBBoxIntersect().
bool Impl_calcClipRange | ( | double & | t1, |
double & | t2, | ||
const Bezier & | c1_orig, | ||
const Bezier & | c1_part, | ||
const Bezier & | c2_orig, | ||
const Bezier & | c2_part | ||
) |
determine parameter ranges [0,t1) and (t2,1] on c1, where c1 is guaranteed to lie outside c2.
Returns false, if the two curves don't even intersect.
t1 | Range [0,t1) on c1 is guaranteed to lie outside c2 |
t2 | Range (t2,1] on c1 is guaranteed to lie outside c2 |
c1_orig | Original curve c1 |
c1_part | Subdivided current part of c1 |
c2_orig | Original curve c2 |
c2_part | Subdivided current part of c2 |
Definition at line 552 of file bezierclip.cxx.
References FatLine::a, FatLine::b, FatLine::c, calcLineDistance(), Impl_calcFatLine(), Impl_calcSafeParams_clip(), Impl_doBBoxIntersect(), Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, Point2D::x, and Point2D::y.
Referenced by main(), and ClipBezierFunctor::operator()().
Definition at line 80 of file bezierclip.cxx.
References calcLineDistance(), line, Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, tolZero(), Point2D::x, and Point2D::y.
Referenced by Impl_calcClipRange(), and main().
Definition at line 613 of file bezierclip.cxx.
References Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, solve(), Point2D::x, and Point2D::y.
Referenced by Impl_applySafeRanges_rec(), main(), and BezierTangencyFunctor::operator()().
bool Impl_calcSafeParams | ( | double & | t1, |
double & | t2, | ||
const Polygon2D & | rPoly, | ||
double | lowerYBound, | ||
double | upperYBound | ||
) |
Definition at line 159 of file bezierclip.cxx.
References convexHull(), i, tolEqual(), tolGreaterEqual(), tolLessEqual(), tolZero(), Point2D::x, and Point2D::y.
Referenced by Impl_calcSafeParams_clip(), Impl_calcSafeParams_focus(), and main().
bool Impl_calcSafeParams_clip | ( | double & | t1, |
double & | t2, | ||
const FatLine & | bounds, | ||
double | c0, | ||
double | c1, | ||
double | c2, | ||
double | c3 | ||
) |
Definition at line 268 of file bezierclip.cxx.
References convexHull(), FatLine::dMax, FatLine::dMin, and Impl_calcSafeParams().
Referenced by Impl_calcClipRange().
bool Impl_calcSafeParams_focus | ( | double & | t1, |
double & | t2, | ||
const Bezier & | curve, | ||
const Bezier & | focus | ||
) |
Definition at line 737 of file bezierclip.cxx.
References convexHull(), count, d, fac(), fallFac(), i, Impl_calcSafeParams(), n, x, and y.
Referenced by main(), and BezierTangencyFunctor::operator()().
Definition at line 329 of file bezierclip.cxx.
References Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, t, tolEqual(), tolZero(), Point2D::x, and Point2D::y.
Referenced by clipBezier(), Impl_applySafeRanges_rec(), main(), and printCurvesWithSafeRange().
Definition at line 131 of file bezierclip.cxx.
References Impl_calcBounds(), lt1, lt2, Point2D::x, and Point2D::y.
Referenced by Impl_calcClipRange().
Definition at line 1234 of file bezierclip.cxx.
References clipBezier(), convexHull(), i, Impl_calcClipRange(), Impl_calcFatLine(), Impl_calcFocus(), Impl_calcSafeParams(), Impl_calcSafeParams_focus(), Impl_deCasteljauAt(), line, Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, result, Point2D::x, and Point2D::y.
void printCurvesWithSafeRange | ( | const Bezier & | c1, |
const Bezier & | c2, | ||
double | t1_c1, | ||
double | t2_c1, | ||
const Bezier & | c2_part, | ||
const FatLine & | bounds_c2 | ||
) |
Definition at line 376 of file bezierclip.cxx.
References FatLine::a, FatLine::b, FatLine::c, FatLine::dMax, FatLine::dMin, Impl_deCasteljauAt(), Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, Point2D::x, and Point2D::y.
void printResultWithFinalCurves | ( | const Bezier & | c1, |
const Bezier & | c1_part, | ||
const Bezier & | c2, | ||
const Bezier & | c2_part, | ||
double | t1_c1, | ||
double | t2_c1 | ||
) |
Definition at line 458 of file bezierclip.cxx.
References Bezier::p0, Bezier::p1, Bezier::p2, Bezier::p3, Point2D::x, and Point2D::y.
Referenced by Impl_applySafeRanges_rec().