FastLED 3.9.15
Loading...
Searching...
No Matches

◆ simplifyInternal()

template<typename NumberT = float>
void fl::LineSimplifier< NumberT >::simplifyInternal ( const fl::Slice< const Point > & polyLine)
inlineprivate

Definition at line 129 of file line_simplification.h.

129 {
130 mSimplified.clear();
131 int n = polyLine.size();
132 if (n < 2) {
133 if (n) {
134 mSimplified.assign(polyLine.data(), polyLine.data() + n);
135 }
136 return;
137 }
139
140 // mark all points as “kept” initially
141 keep.assign(n, 1);
142
143 // explicit stack of (start,end) index pairs
144 indexStack.clear();
145 // indexStack.reserve(64);
146 indexStack.push_back({0, n - 1});
147
148 // process segments
149 while (!indexStack.empty()) {
150 // auto [i0, i1] = indexStack.back();
151 auto pair = indexStack.back();
152 int i0 = pair.first;
153 int i1 = pair.second;
154 indexStack.pop_back();
155 const bool has_interior = (i1 - i0) > 1;
156 if (!has_interior) {
157 // no interior points, just keep the endpoints
158 // keep[i0] = 1;
159 // keep[i1] = 1;
160 continue;
161 }
162
163 // find farthest point in [i0+1 .. i1-1]
164 NumberT maxDist2 = 0;
165 int split = i0;
166 for (int i = i0 + 1; i < i1; ++i) {
167 if (!keep[i])
168 continue;
170 polyLine[i1]);
171
172 // FASTLED_WARN("Perpendicular distance2 between "
173 // << polyLine[i] << " and " << polyLine[i0]
174 // << " and " << polyLine[i1] << " is " << d2);
175
176 if (d2 > maxDist2) {
177 maxDist2 = d2;
178 split = i;
179 }
180 }
181
182 if (maxDist2 > minDist2) {
183 // need to keep that split point and recurse on both halves
184 indexStack.push_back({i0, split});
185 indexStack.push_back({split, i1});
186 } else {
187 // drop all interior points in this segment
188 for (int i = i0 + 1; i < i1; ++i) {
189 keep[i] = 0;
190 }
191 }
192 }
193
194 // collect survivors
195 mSimplified.clear();
196 mSimplified.reserve(n);
197 for (int i = 0; i < n; ++i) {
198 if (keep[i])
199 mSimplified.push_back(polyLine[i]);
200 }
201 }
static NumberT PerpendicularDistance2(const Point &pt, const Point &a, const Point &b)
fl::bitset< 256 > keep
fl::vector_inlined< fl::pair< int, int >, 64 > indexStack

References fl::Slice< T >::data(), indexStack, keep, mMinDistance, mSimplified, PerpendicularDistance2(), and fl::Slice< T >::size().

Referenced by simplifyT().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: