Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: solvespace/solvespace
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 76b3efbd08cb
Choose a base ref
...
head repository: solvespace/solvespace
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7366a6c53deb
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on May 2, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7366a6c View commit details
Showing with 21 additions and 78 deletions.
  1. +21 −74 src/srf/ratpoly.cpp
  2. +0 −4 src/srf/surface.h
95 changes: 21 additions & 74 deletions src/srf/ratpoly.cpp
Original file line number Diff line number Diff line change
@@ -13,84 +13,31 @@
// and convergence should be fast by now.
#define RATPOLY_EPS (LENGTH_EPS/(1e2))

double SolveSpace::Bernstein(int k, int deg, double t)
static double Bernstein(int k, int deg, double t)
{
if(k > deg || k < 0) return 0;

switch(deg) {
case 0:
return 1;

case 1:
if(k == 0) {
return (1 - t);
} else if(k == 1) {
return t;
}
break;

case 2:
if(k == 0) {
return (1 - t)*(1 - t);
} else if(k == 1) {
return 2*(1 - t)*t;
} else if(k == 2) {
return t*t;
}
break;

case 3:
if(k == 0) {
return (1 - t)*(1 - t)*(1 - t);
} else if(k == 1) {
return 3*(1 - t)*(1 - t)*t;
} else if(k == 2) {
return 3*(1 - t)*t*t;
} else if(k == 3) {
return t*t*t;
}
break;
}
ssassert(false, "Unexpected degree of spline");
// indexed by [degree][k][exponent]
static const double bernstein_coeff[4][4][4] = {
{ { 1.0,0.0,0.0,0.0 }, { 1.0,0.0,0.0,0.0 }, { 1.0,0.0,0.0,0.0 }, { 1.0,0.0,0.0,0.0 } },
{ { 1.0,-1.0,0.0,0.0 }, { 0.0,1.0,0.0,0.0 }, { 0.0,0.0,0.0,0.0 }, { 0.0,0.0,0.0,0.0 } },
{ { 1.0,-2.0,1.0,0.0 }, { 0.0,2.0,-2.0,0.0 },{ 0.0,0.0,1.0,0.0 }, { 0.0,0.0,0.0,0.0 } },
{ { 1.0,-3.0,3.0,-1.0 },{ 0.0,3.0,-6.0,3.0 },{ 0.0,0.0,3.0,-3.0}, { 0.0,0.0,0.0,1.0 } } };

const double *c;
c = bernstein_coeff[deg][k];
return (((c[3]*t+c[2])*t)+c[1])*t+c[0];
}

double SolveSpace::BernsteinDerivative(int k, int deg, double t)
static double BernsteinDerivative(int k, int deg, double t)
{
switch(deg) {
case 0:
return 0;

case 1:
if(k == 0) {
return -1;
} else if(k == 1) {
return 1;
}
break;

case 2:
if(k == 0) {
return -2 + 2*t;
} else if(k == 1) {
return 2 - 4*t;
} else if(k == 2) {
return 2*t;
}
break;

case 3:
if(k == 0) {
return -3 + 6*t - 3*t*t;
} else if(k == 1) {
return 3 - 12*t + 9*t*t;
} else if(k == 2) {
return 6*t - 9*t*t;
} else if(k == 3) {
return 3*t*t;
}
break;
}
ssassert(false, "Unexpected degree of spline");
static const double bernstein_derivative_coeff[4][4][3] = {
{ { 0.0,0.0,0.0 }, { 0.0,0.0,0.0 }, { 0.0,0.0,0.0 }, { 0.0,0.0,0.0 } },
{ { -1.0,0.0,0.0 }, { 1.0,0.0,0.0 }, { 0.0,0.0,0.0 }, { 0.0,0.0,0.0 } },
{ { -2.0,2.0,0.0 }, { 2.0,-4.0,0.0 },{ 0.0,2.0,0.0 }, { 0.0,0.0,0.0 } },
{ { -3.0,6.0,-3.0 },{ 3.0,-12.0,9.0 },{ 0.0,6.0,-9.0}, { 0.0,0.0,3.0 } } };

const double *c;
c = bernstein_derivative_coeff[deg][k];
return ((c[2]*t)+c[1])*t+c[0];
}

Vector SBezier::PointAt(double t) const {
4 changes: 0 additions & 4 deletions src/srf/surface.h
Original file line number Diff line number Diff line change
@@ -10,10 +10,6 @@
#ifndef SOLVESPACE_SURFACE_H
#define SOLVESPACE_SURFACE_H

// Utility functions, Bernstein polynomials of order 1-3 and their derivatives.
double Bernstein(int k, int deg, double t);
double BernsteinDerivative(int k, int deg, double t);

class SBezierList;
class SSurface;
class SCurvePt;