LibreOffice Module basegfx (master) 1
Classes | Macros | Functions
bezierclip.cxx File Reference
#include <iostream>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <vector>
#include <utility>
#include <math.h>
#include <bezierclip.hxx>
#include <gauss.hxx>
Include dependency graph for bezierclip.cxx:

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[])
 

Macro Definition Documentation

◆ WITH_ASSERTIONS

#define WITH_ASSERTIONS

Definition at line 33 of file bezierclip.cxx.

◆ WITH_BEZIERCLIP_TEST

#define WITH_BEZIERCLIP_TEST

Definition at line 44 of file bezierclip.cxx.

Function Documentation

◆ clipBezier()

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)

Parameters
resultOutput iterator where the final t values are added to. This iterator will remain empty, if there are no intersections.
deltaMaximal 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().

◆ fac()

int fac ( int  n)

Definition at line 71 of file bezierclip.cxx.

References fallFac(), and n.

Referenced by Impl_calcSafeParams_focus().

◆ fallFac()

int fallFac ( int  n,
int  k 
)

Definition at line 56 of file bezierclip.cxx.

References n.

Referenced by fac(), and Impl_calcSafeParams_focus().

◆ Impl_applySafeRanges_rec()

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.

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.

Parameters
resultOutput iterator where the final t values are added to. If curves don't intersect, nothing is added.
deltaMaximal allowed distance to true critical point (measured in the original curve's coordinate system)
safeRangeFunctorFunctor 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().

◆ Impl_calcBounds()

void Impl_calcBounds ( Point2D leftTop,
Point2D rightBottom,
const Bezier c1 
)

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().

◆ Impl_calcClipRange()

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.

Parameters
t1Range [0,t1) on c1 is guaranteed to lie outside c2
t2Range (t2,1] on c1 is guaranteed to lie outside c2
c1_origOriginal curve c1
c1_partSubdivided current part of c1
c2_origOriginal curve c2
c2_partSubdivided 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()().

◆ Impl_calcFatLine()

void Impl_calcFatLine ( FatLine line,
const Bezier c 
)

◆ Impl_calcFocus()

void Impl_calcFocus ( Bezier res,
const Bezier c 
)

◆ Impl_calcSafeParams()

bool Impl_calcSafeParams ( double &  t1,
double &  t2,
const Polygon2D rPoly,
double  lowerYBound,
double  upperYBound 
)

◆ Impl_calcSafeParams_clip()

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().

◆ Impl_calcSafeParams_focus()

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()().

◆ Impl_deCasteljauAt()

void Impl_deCasteljauAt ( Bezier part1,
Bezier part2,
const Bezier input,
double  t 
)

◆ Impl_doBBoxIntersect()

bool Impl_doBBoxIntersect ( const Bezier c1,
const Bezier c2 
)

Definition at line 131 of file bezierclip.cxx.

References Impl_calcBounds(), lt1, lt2, Point2D::x, and Point2D::y.

Referenced by Impl_calcClipRange().

◆ main()

int main ( int  argc,
const char *  argv[] 
)

◆ printCurvesWithSafeRange()

void printCurvesWithSafeRange ( const Bezier c1,
const Bezier c2,
double  t1_c1,
double  t2_c1,
const Bezier c2_part,
const FatLine bounds_c2 
)

◆ printResultWithFinalCurves()

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().