@@ -118,7 +118,7 @@ namespace geode
118118 " on HorizonsStack will be empty: top and bottom "
119119 " horizons have not been computed, or stack is empty." );
120120 }
121- return { *this };
121+ return { *this , true };
122122 }
123123
124124 template < index_t dimension >
@@ -128,11 +128,39 @@ namespace geode
128128 if ( !impl_->top_horizon () || !impl_->bottom_horizon () )
129129 {
130130 Logger::warn (
131- " [HorizonsStack::bottom_to_top_horizons] Iteration "
131+ " [HorizonsStack::bottom_to_top_units] Iteration "
132+ " on HorizonsStack will be empty: top and bottom "
133+ " horizons have not been computed, or stack is empty" );
134+ }
135+ return { *this , true };
136+ }
137+
138+ template < index_t dimension >
139+ auto HorizonsStack< dimension >::top_to_bottom_horizons() const
140+ -> HorizonOrderedRange
141+ {
142+ if ( !impl_->top_horizon () || !impl_->bottom_horizon () )
143+ {
144+ Logger::warn (
145+ " [HorizonsStack::top_to_bottom_horizons] Iteration "
146+ " on HorizonsStack will be empty: top and bottom "
147+ " horizons have not been computed, or stack is empty." );
148+ }
149+ return { *this , false };
150+ }
151+
152+ template < index_t dimension >
153+ auto HorizonsStack< dimension >::top_to_bottom_units() const
154+ -> StratigraphicUnitOrderedRange
155+ {
156+ if ( !impl_->top_horizon () || !impl_->bottom_horizon () )
157+ {
158+ Logger::warn (
159+ " [HorizonsStack::top_to_bottom_units] Iteration "
132160 " on HorizonsStack will be empty: top and bottom "
133161 " horizons have not been computed, or stack is empty" );
134162 }
135- return { *this };
163+ return { *this , false };
136164 }
137165
138166 template < index_t dimension >
@@ -206,12 +234,15 @@ namespace geode
206234 class HorizonsStack < dimension >::HorizonOrderedRange::Impl
207235 {
208236 public:
209- Impl ( const HorizonsStack< dimension >& stack ) : stack_( stack )
237+ Impl ( const HorizonsStack< dimension >& stack, bool bottom_to_top )
238+ : stack_( stack ), bottom_to_top_( bottom_to_top )
210239 {
211240 auto bot_horizon = stack.bottom_horizon ();
212- if ( bot_horizon && stack.top_horizon () )
241+ auto top_horizon = stack.top_horizon ();
242+ if ( bot_horizon && top_horizon )
213243 {
214- iter_ = bot_horizon.value ();
244+ iter_ =
245+ bottom_to_top_ ? bot_horizon.value () : top_horizon.value ();
215246 }
216247 }
217248
@@ -222,10 +253,23 @@ namespace geode
222253
223254 void operator ++()
224255 {
225- if ( iter_ != stack_.top_horizon ().value () )
256+ if ( bottom_to_top_ )
257+ {
258+ if ( iter_ != stack_.top_horizon ().value () )
259+ {
260+ iter_ =
261+ stack_.above ( stack_.above ( iter_ ).value () ).value ();
262+ return ;
263+ }
264+ }
265+ else
226266 {
227- iter_ = stack_.above ( stack_.above ( iter_ ).value () ).value ();
228- return ;
267+ if ( iter_ != stack_.bottom_horizon ().value () )
268+ {
269+ iter_ =
270+ stack_.under ( stack_.under ( iter_ ).value () ).value ();
271+ return ;
272+ }
229273 }
230274 iter_ = uuid{};
231275 }
@@ -237,13 +281,14 @@ namespace geode
237281
238282 private:
239283 const HorizonsStack< dimension >& stack_;
284+ bool bottom_to_top_;
240285 uuid iter_{};
241286 };
242287
243288 template < index_t dimension >
244289 HorizonsStack< dimension >::HorizonOrderedRange::HorizonOrderedRange(
245- const HorizonsStack& horizons_stack )
246- : impl_( horizons_stack )
290+ const HorizonsStack& horizons_stack, bool bottom_to_top )
291+ : impl_( horizons_stack, bottom_to_top )
247292 {
248293 }
249294
@@ -286,12 +331,16 @@ namespace geode
286331 class HorizonsStack < dimension >::StratigraphicUnitOrderedRange::Impl
287332 {
288333 public:
289- Impl ( const HorizonsStack< dimension >& stack ) : stack_( stack )
334+ Impl ( const HorizonsStack< dimension >& stack, bool bottom_to_top )
335+ : stack_( stack ), bottom_to_top_( bottom_to_top )
290336 {
291337 auto bot_horizon = stack.bottom_horizon ();
292- if ( bot_horizon && stack.top_horizon () )
338+ auto top_horizon = stack.top_horizon ();
339+ if ( bot_horizon && top_horizon )
293340 {
294- iter_ = stack.under ( bot_horizon.value () ).value ();
341+ iter_ = bottom_to_top_
342+ ? stack.under ( bot_horizon.value () ).value ()
343+ : stack.above ( top_horizon.value () ).value ();
295344 }
296345 }
297346
@@ -302,10 +351,25 @@ namespace geode
302351
303352 void operator ++()
304353 {
305- if ( iter_ != stack_. above ( stack_. top_horizon (). value () ). value () )
354+ if ( bottom_to_top_ )
306355 {
307- iter_ = stack_.above ( stack_.above ( iter_ ).value () ).value ();
308- return ;
356+ if ( iter_
357+ != stack_.above ( stack_.top_horizon ().value () ).value () )
358+ {
359+ iter_ =
360+ stack_.above ( stack_.above ( iter_ ).value () ).value ();
361+ return ;
362+ }
363+ }
364+ else
365+ {
366+ if ( iter_
367+ != stack_.under ( stack_.bottom_horizon ().value () ).value () )
368+ {
369+ iter_ =
370+ stack_.under ( stack_.under ( iter_ ).value () ).value ();
371+ return ;
372+ }
309373 }
310374 iter_ = uuid{};
311375 }
@@ -317,13 +381,15 @@ namespace geode
317381
318382 private:
319383 const HorizonsStack< dimension >& stack_;
384+ bool bottom_to_top_;
320385 uuid iter_{};
321386 };
322387
323388 template < index_t dimension >
324389 HorizonsStack< dimension >::StratigraphicUnitOrderedRange::
325- StratigraphicUnitOrderedRange ( const HorizonsStack& horizons_stack )
326- : impl_( horizons_stack )
390+ StratigraphicUnitOrderedRange (
391+ const HorizonsStack& horizons_stack, bool bottom_to_top )
392+ : impl_( horizons_stack, bottom_to_top )
327393 {
328394 }
329395
0 commit comments