Removing unused pad parts working

This commit is contained in:
tamasmeszaros 2019-06-18 11:24:50 +02:00
parent 778b2cf293
commit d7684188f9
2 changed files with 60 additions and 3 deletions

View file

@ -5,6 +5,9 @@
#include <mutex> // for std::lock_guard
#include <functional> // for std::function
#include <utility> // for std::forward
#include <vector>
#include <algorithm>
#include <cmath>
namespace Slic3r {
@ -182,6 +185,57 @@ public:
inline bool empty() const { return size() == 0; }
};
template<class T>
struct remove_cvref
{
using type =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
};
template<class T>
using remove_cvref_t = typename remove_cvref<T>::type;
template<template<class> class C, class T>
class Container: public C<remove_cvref_t<T>> {
public:
explicit Container(size_t count, T&& initval):
C<remove_cvref_t<T>>(count, initval) {}
};
template<class T> using DefaultContainer = std::vector<T>;
/// Exactly like Matlab https://www.mathworks.com/help/matlab/ref/linspace.html
template<class T, class I, template<class> class C = DefaultContainer>
inline C<remove_cvref_t<T>> linspace(const T &start, const T &stop, const I &n)
{
Container<C, T> vals(n, T());
T stride = (stop - start) / n;
size_t i = 0;
std::generate(vals.begin(), vals.end(), [&i, start, stride] {
return start + i++ * stride;
});
return vals;
}
/// A set of equidistant values starting from 'start' (inclusive), ending
/// in the closest multiple of 'stride' less than or equal to 'end' and
/// leaving 'stride' space between each value.
/// Very similar to Matlab [start:stride:end] notation.
template<class T, template<class> class C = DefaultContainer>
inline C<remove_cvref_t<T>> grid(const T &start, const T &stop, const T &stride)
{
Container<C, T> vals(size_t(std::ceil((stop - start) / stride)), T());
int i = 0;
std::generate(vals.begin(), vals.end(), [&i, start, stride] {
return start + i++ * stride;
});
return vals;
}
}
#endif // MTUTILS_HPP