1 #ifndef VTESTBED_GEOMETRY_CURVE_SEGMENTS_HH 2 #define VTESTBED_GEOMETRY_CURVE_SEGMENTS_HH 6 #include <vtestbed/geometry/math.hh> 7 #include <vtestbed/geometry/types.hh> 13 template <
class T,
int N>
18 using reference = value_type&;
19 using const_reference =
const value_type&;
20 using pointer = value_type*;
21 using const_pointer =
const value_type*;
23 using size_type = size_t;
35 this->chord_length(points);
40 const auto nvalues = values.size();
44 auto& result = this->_segments;
46 result.reserve(nvalues-1);
48 auto p0 = values.front();
49 for (
size_t i=1; i<nvalues; ++i) {
50 const auto& p1 = values[i];
51 auto s = distance(p0,p1);
52 result.emplace_back(s);
61 uniform(size_type npoints) {
65 auto& result = this->_segments;
67 result.reserve(npoints-1);
68 T delta = T{1}/(npoints-1);
69 for (
size_t i=1; i<npoints; ++i) {
70 result.emplace_back(delta);
77 projection(
const vertex_array& values,
int dim, T z_min, T z_max, T eps=T{}) {
81 const auto nvalues = values.size();
82 if (nvalues == 0) {
return; }
83 auto& result = this->_segments;
85 result.reserve(nvalues-1);
87 auto p0 = values.front();
88 for (
size_t i=1; i<nvalues; ++i) {
89 const auto& p1 = values[i];
90 const auto z0 = max(z_min, min(z_max, p0(dim)));
91 const auto z1 = max(z_min, min(z_max, p1(dim)));
93 if (s < eps) { s = distance(p0,p1); }
94 result.emplace_back(s);
103 projection(
const vertex_array& values,
int dim, T eps=T{}) {
115 auto& length = this->_length;
116 for (
auto& s : this->_segments) {
119 this->_min /= length;
120 this->_max /= length;
125 locate(T& t, size_type& i)
const {
126 T new_t = _min + (_max - _min)*t;
127 const auto& segments = this->_segments;
128 const auto nsegments = segments.size();
130 for (; i < nsegments; ++i) {
131 const auto& s = segments[i];
135 t = (new_t - old_sum) / s;
142 locate(size_type i)
const {
143 i = std::min(i, this->_segments.size());
145 for (size_type j=0; j<i; ++j) { sum += this->_segments[j]; }
150 range(T min, T max) {
157 return this->_length;
162 return this->_segments.size();
166 operator[](size_type i) {
167 return this->_segments[i];
170 inline const_reference
171 operator[](size_type i)
const {
172 return this->_segments[i];
177 return this->_segments.data();
182 return this->_segments.data();
187 return this->begin() + this->size();
192 return this->begin() + this->size();
203 #endif // vim:filetype=cpp