Skip to content

Commit 9daef14

Browse files
committed
feat(Component): add active component status
1 parent 83450c9 commit 9daef14

8 files changed

Lines changed: 230 additions & 22 deletions

File tree

include/geode/geosciences/explicit/mixin/core/fault_blocks.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace geode
5858

5959
void operator++();
6060

61+
void set_active_only();
62+
6163
protected:
6264
FaultBlockRangeBase( const FaultBlocks& fault_blocks );
6365
FaultBlockRangeBase( FaultBlockRangeBase&& other ) noexcept;
@@ -91,13 +93,17 @@ namespace geode
9193

9294
[[nodiscard]] index_t nb_fault_blocks() const;
9395

96+
[[nodiscard]] index_t nb_active_fault_blocks() const;
97+
9498
[[nodiscard]] bool has_fault_block( const uuid& id ) const;
9599

96100
[[nodiscard]] const FaultBlock< dimension >& fault_block(
97101
const uuid& id ) const;
98102

99103
[[nodiscard]] FaultBlockRange fault_blocks() const;
100104

105+
[[nodiscard]] FaultBlockRange active_fault_blocks() const;
106+
101107
[[nodiscard]] FaultBlockRange components() const
102108
{
103109
return fault_blocks();

include/geode/geosciences/explicit/mixin/core/faults.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace geode
5858

5959
void operator++();
6060

61+
void set_active_only();
62+
6163
protected:
6264
FaultRangeBase( const Faults& faults );
6365
FaultRangeBase( FaultRangeBase&& other ) noexcept;
@@ -91,12 +93,16 @@ namespace geode
9193

9294
[[nodiscard]] index_t nb_faults() const;
9395

96+
[[nodiscard]] index_t nb_active_faults() const;
97+
9498
[[nodiscard]] bool has_fault( const uuid& id ) const;
9599

96100
[[nodiscard]] const Fault< dimension >& fault( const uuid& id ) const;
97101

98102
[[nodiscard]] FaultRange faults() const;
99103

104+
[[nodiscard]] FaultRange active_faults() const;
105+
100106
[[nodiscard]] FaultRange components() const
101107
{
102108
return faults();

include/geode/geosciences/explicit/mixin/core/horizons.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace geode
5858

5959
void operator++();
6060

61+
void set_active_only();
62+
6163
protected:
6264
HorizonRangeBase( const Horizons& horizons );
6365
HorizonRangeBase( HorizonRangeBase&& other ) noexcept;
@@ -91,13 +93,17 @@ namespace geode
9193

9294
[[nodiscard]] index_t nb_horizons() const;
9395

96+
[[nodiscard]] index_t nb_active_horizons() const;
97+
9498
[[nodiscard]] bool has_horizon( const uuid& id ) const;
9599

96100
[[nodiscard]] const Horizon< dimension >& horizon(
97101
const uuid& id ) const;
98102

99103
[[nodiscard]] HorizonRange horizons() const;
100104

105+
[[nodiscard]] HorizonRange active_horizons() const;
106+
101107
[[nodiscard]] HorizonRange components() const
102108
{
103109
return horizons();

include/geode/geosciences/explicit/mixin/core/stratigraphic_units.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ namespace geode
5959

6060
void operator++();
6161

62+
void set_active_only();
63+
6264
protected:
6365
StratigraphicUnitRangeBase(
6466
const StratigraphicUnits& stratigraphic_units );
@@ -97,13 +99,17 @@ namespace geode
9799

98100
[[nodiscard]] index_t nb_stratigraphic_units() const;
99101

102+
[[nodiscard]] index_t nb_active_stratigraphic_units() const;
103+
100104
[[nodiscard]] bool has_stratigraphic_unit( const uuid& id ) const;
101105

102106
[[nodiscard]] const StratigraphicUnit< dimension >& stratigraphic_unit(
103107
const uuid& id ) const;
104108

105109
[[nodiscard]] StratigraphicUnitRange stratigraphic_units() const;
106110

111+
[[nodiscard]] StratigraphicUnitRange active_stratigraphic_units() const;
112+
107113
[[nodiscard]] StratigraphicUnitRange components() const
108114
{
109115
return stratigraphic_units();

src/geode/geosciences/explicit/mixin/core/fault_blocks.cpp

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <geode/geosciences/explicit/mixin/core/fault_blocks.hpp>
2525

26+
#include <geode/basic/detail/count_range_elements.hpp>
2627
#include <geode/basic/identifier_builder.hpp>
2728
#include <geode/basic/pimpl_impl.hpp>
2829
#include <geode/basic/range.hpp>
@@ -58,6 +59,12 @@ namespace geode
5859
return impl_->nb_components();
5960
}
6061

62+
template < index_t dimension >
63+
index_t FaultBlocks< dimension >::nb_active_fault_blocks() const
64+
{
65+
return detail::count_range_elements( active_fault_blocks() );
66+
}
67+
6168
template < index_t dimension >
6269
bool FaultBlocks< dimension >::has_fault_block( const uuid& id ) const
6370
{
@@ -93,16 +100,23 @@ namespace geode
93100
}
94101

95102
template < index_t dimension >
96-
typename FaultBlocks< dimension >::FaultBlockRange
97-
FaultBlocks< dimension >::fault_blocks() const
103+
auto FaultBlocks< dimension >::fault_blocks() const -> FaultBlockRange
98104
{
99105
return { *this };
100106
}
101107

102108
template < index_t dimension >
103-
typename FaultBlocks< dimension >::ModifiableFaultBlockRange
104-
FaultBlocks< dimension >::modifiable_fault_blocks(
105-
FaultBlocksBuilderKey /*unused*/ )
109+
auto FaultBlocks< dimension >::active_fault_blocks() const
110+
-> FaultBlockRange
111+
{
112+
FaultBlockRange range{ *this };
113+
range.set_active_only();
114+
return range;
115+
}
116+
117+
template < index_t dimension >
118+
auto FaultBlocks< dimension >::modifiable_fault_blocks(
119+
FaultBlocksBuilderKey /*unused*/ ) -> ModifiableFaultBlockRange
106120
{
107121
return { *this };
108122
}
@@ -156,6 +170,31 @@ namespace geode
156170
{
157171
return *this->current()->second;
158172
}
173+
174+
void set_active_only()
175+
{
176+
active_only_ = true;
177+
next_fault_block();
178+
}
179+
180+
void next()
181+
{
182+
this->operator++();
183+
next_fault_block();
184+
}
185+
186+
private:
187+
void next_fault_block()
188+
{
189+
while( this->operator!=( *this )
190+
&& ( active_only_ && !fault_block().is_active() ) )
191+
{
192+
this->operator++();
193+
}
194+
}
195+
196+
private:
197+
bool active_only_{ false };
159198
};
160199

161200
template < index_t dimension >
@@ -187,10 +226,16 @@ namespace geode
187226
return impl_->operator!=( *impl_ );
188227
}
189228

229+
template < index_t dimension >
230+
void FaultBlocks< dimension >::FaultBlockRangeBase::set_active_only()
231+
{
232+
impl_->set_active_only();
233+
}
234+
190235
template < index_t dimension >
191236
void FaultBlocks< dimension >::FaultBlockRangeBase::operator++()
192237
{
193-
return impl_->operator++();
238+
return impl_->next();
194239
}
195240

196241
template < index_t dimension >

src/geode/geosciences/explicit/mixin/core/faults.cpp

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <geode/geosciences/explicit/mixin/core/faults.hpp>
2525

26+
#include <geode/basic/detail/count_range_elements.hpp>
2627
#include <geode/basic/identifier_builder.hpp>
2728
#include <geode/basic/pimpl_impl.hpp>
2829
#include <geode/basic/range.hpp>
@@ -58,6 +59,12 @@ namespace geode
5859
return impl_->nb_components();
5960
}
6061

62+
template < index_t dimension >
63+
index_t Faults< dimension >::nb_active_faults() const
64+
{
65+
return detail::count_range_elements( active_faults() );
66+
}
67+
6168
template < index_t dimension >
6269
bool Faults< dimension >::has_fault( const uuid& id ) const
6370
{
@@ -91,14 +98,22 @@ namespace geode
9198
}
9299

93100
template < index_t dimension >
94-
typename Faults< dimension >::FaultRange Faults< dimension >::faults() const
101+
auto Faults< dimension >::faults() const -> FaultRange
95102
{
96103
return { *this };
97104
}
98105

99106
template < index_t dimension >
100-
typename Faults< dimension >::ModifiableFaultRange
101-
Faults< dimension >::modifiable_faults( FaultsBuilderKey /*unused*/ )
107+
auto Faults< dimension >::active_faults() const -> FaultRange
108+
{
109+
FaultRange range{ *this };
110+
range.set_active_only();
111+
return range;
112+
}
113+
114+
template < index_t dimension >
115+
auto Faults< dimension >::modifiable_faults( FaultsBuilderKey /*unused*/ )
116+
-> ModifiableFaultRange
102117
{
103118
return { *this };
104119
}
@@ -175,6 +190,31 @@ namespace geode
175190
{
176191
return *this->current()->second;
177192
}
193+
194+
void set_active_only()
195+
{
196+
active_only_ = true;
197+
next_fault();
198+
}
199+
200+
void next()
201+
{
202+
this->operator++();
203+
next_fault();
204+
}
205+
206+
private:
207+
void next_fault()
208+
{
209+
while( this->operator!=( *this )
210+
&& ( active_only_ && !fault().is_active() ) )
211+
{
212+
this->operator++();
213+
}
214+
}
215+
216+
private:
217+
bool active_only_{ false };
178218
};
179219

180220
template < index_t dimension >
@@ -204,10 +244,16 @@ namespace geode
204244
return impl_->operator!=( *impl_ );
205245
}
206246

247+
template < index_t dimension >
248+
void Faults< dimension >::FaultRangeBase::set_active_only()
249+
{
250+
impl_->set_active_only();
251+
}
252+
207253
template < index_t dimension >
208254
void Faults< dimension >::FaultRangeBase::operator++()
209255
{
210-
return impl_->operator++();
256+
return impl_->next();
211257
}
212258

213259
template < index_t dimension >

0 commit comments

Comments
 (0)