fix potential endless loop when evaluating the spline

This commit is contained in:
Florens Wasserfall 2017-04-04 16:25:00 +02:00
parent 8ec0275967
commit f24ca220d5

View File

@ -158,15 +158,18 @@ std::vector<coordf_t> LayerHeightSpline::getInterpolatedLayers() const
coordf_t z = this->_original_layers[0]; coordf_t z = this->_original_layers[0];
coordf_t h; coordf_t h;
coordf_t h_diff = 0; coordf_t h_diff = 0;
coordf_t last_h_diff = 0;
coordf_t eps = 0.0001; coordf_t eps = 0.0001;
while(z <= this->_object_height) { while(z <= this->_object_height) {
h = 0; h = 0;
h_diff = 0;
// find intersection between layer height and spline // find intersection between layer height and spline
do { do {
last_h_diff = h_diff;
h += h_diff/2; h += h_diff/2;
h = this->_layer_height_spline->evaluate(z+h); h = this->_layer_height_spline->evaluate(z+h);
h_diff = this->_layer_height_spline->evaluate(z+h) - h; h_diff = this->_layer_height_spline->evaluate(z+h) - h;
} while(std::abs(h_diff) > eps); } while(std::abs(h_diff) > eps && std::abs(h_diff - last_h_diff) > eps);
z += h; z += h;
layers.push_back(z); layers.push_back(z);
} }