summaryrefslogtreecommitdiffstats
path: root/src/2geom/recursive-bezier-intersection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2geom/recursive-bezier-intersection.cpp')
-rw-r--r--src/2geom/recursive-bezier-intersection.cpp52
1 files changed, 24 insertions, 28 deletions
diff --git a/src/2geom/recursive-bezier-intersection.cpp b/src/2geom/recursive-bezier-intersection.cpp
index 7db0438a7..548065196 100644
--- a/src/2geom/recursive-bezier-intersection.cpp
+++ b/src/2geom/recursive-bezier-intersection.cpp
@@ -13,6 +13,8 @@
unsigned intersect_steps = 0;
using std::vector;
+using std::swap;
+
namespace Geom {
class OldBezier {
@@ -31,7 +33,7 @@ public:
minax = p[0][X]; // These are the most likely to be extremal
maxax = p.back()[X];
if( minax > maxax )
- std::swap(minax, maxax);
+ swap(minax, maxax);
for(unsigned i = 1; i < p.size()-1; i++) {
if( p[i][X] < minax )
minax = p[i][X];
@@ -42,7 +44,7 @@ public:
minay = p[0][Y]; // These are the most likely to be extremal
maxay = p.back()[Y];
if( minay > maxay )
- std::swap(minay, maxay);
+ swap(minay, maxay);
for(unsigned i = 1; i < p.size()-1; i++) {
if( p[i][Y] < minay )
minay = p[i][Y];
@@ -71,9 +73,6 @@ find_intersections_bezier_recursive( std::vector<std::pair<double, double> > &xs
}
-/* The value of 1.0 / (1L<<14) is enough for most applications */
-const double INV_EPS = (1L<<14);
-
/*
* split the curve at the midpoint, returning an array with the two parts
* Temporary storage is minimized by using part of the storage for the result
@@ -81,14 +80,13 @@ const double INV_EPS = (1L<<14);
*/
void OldBezier::split(double t, OldBezier &left, OldBezier &right) const {
const unsigned sz = p.size();
-
- Geom::Point **Vtemp = new Geom::Point* [sz];
-
- for (unsigned int i = 0; i < sz; ++i)
- Vtemp[i] = new Geom::Point[sz];
+ //Geom::Point Vtemp[sz][sz];
+ std::vector< std::vector< Geom::Point > > Vtemp;
+ for (size_t i = 0; i < sz; ++i )
+ Vtemp[i].reserve(sz);
/* Copy control points */
- std::copy(p.begin(), p.end(), Vtemp[0]);
+ std::copy(p.begin(), p.end(), Vtemp[0].begin());
/* Triangle computation */
for (unsigned i = 1; i < sz; i++) {
@@ -103,11 +101,6 @@ void OldBezier::split(double t, OldBezier &left, OldBezier &right) const {
left.p[j] = Vtemp[j][0];
for (unsigned j = 0; j < sz; j++)
right.p[j] = Vtemp[sz-1-j][j];
-
- for (unsigned int i = 0; i < sz; ++i)
- delete[] Vtemp[i];
-
- delete[] Vtemp;
}
#if 0
@@ -134,17 +127,15 @@ Point OldBezier::operator()(double t) const {
#endif
// suggested by Sederberg.
-Point OldBezier::operator()(double t) const {
- int n = p.size()-1;
- double u, bc, tn, tmp;
- int i;
+Point OldBezier::operator()(double const t) const {
+ size_t const n = p.size()-1;
Point r;
for(int dim = 0; dim < 2; dim++) {
- u = 1.0 - t;
- bc = 1;
- tn = 1;
- tmp = p[0][dim]*u;
- for(i=1; i<n; i++){
+ double const u = 1.0 - t;
+ double bc = 1;
+ double tn = 1;
+ double tmp = p[0][dim]*u;
+ for(size_t i=1; i<n; i++){
tn = tn*t;
bc = bc*(n-i+1)/i;
tmp = (tmp + tn*bc*p[i][dim])*u;
@@ -183,8 +174,8 @@ bool intersect_BB( OldBezier a, OldBezier b ) {
b.bounds(minbx, maxbx, minby, maxby);
// Test bounding box of b against bounding box of a
// Not >= : need boundary case
- return not( ( minax > maxbx ) || ( minay > maxby )
- || ( minbx > maxax ) || ( minby > maxay ) );
+ return !( ( minax > maxbx ) || ( minay > maxby )
+ || ( minbx > maxax ) || ( minby > maxay ) );
}
/*
@@ -326,9 +317,14 @@ double Lmax(Point p) {
return std::max(fabs(p[X]), fabs(p[Y]));
}
+
unsigned wangs_theorem(OldBezier /*a*/) {
return 6; // seems a good approximation!
- /*double la1 = Lmax( ( a.p[2] - a.p[1] ) - (a.p[1] - a.p[0]) );
+
+ /*
+ const double INV_EPS = (1L<<14); // The value of 1.0 / (1L<<14) is enough for most applications
+
+ double la1 = Lmax( ( a.p[2] - a.p[1] ) - (a.p[1] - a.p[0]) );
double la2 = Lmax( ( a.p[3] - a.p[2] ) - (a.p[2] - a.p[1]) );
double l0 = std::max(la1, la2);
unsigned ra;