Skip to content

Commit

Permalink
Refactor Scale::compute_scaling_from for more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
sebjameswml committed Oct 7, 2024
1 parent bb901d9 commit d9461c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/ref/coremaths/scale.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ s.output_range.max = 5;
s.compute_scaling (-10, 10);
```

You can also trigger the computation of the scaling function if you have a container of data by using `compute_scaling_from`, which is the function that is automatically called by `transform` when `do_autoscale` is `true`.
You can also trigger the computation of the scaling function if you have a container of data by using `compute_scaling_from_data`, which is the function that is automatically called by `transform` when `do_autoscale` is `true`.

```c++
morph::Scale<int, float> s;
std::vector<int> input_data = { 1, 2, 3, 6, 100 };
s.compute_scaling_from (input_data);
s.compute_scaling_from_data (input_data);
```
### Logarithmic scaling
Expand Down
2 changes: 1 addition & 1 deletion examples/scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main()
}

// If you need to reset the scaling in s (our Scale object), then you can do this:
s.compute_scaling_from (vf2); // will immediately compute the scaling function from the container of values vf2.
s.compute_scaling_from_data (vf2); // will immediately compute the scaling function from the container of values vf2.

// OR you can do this, which forces automatic scaling when s.transform() is next
// called (as long as s.do_autoscale is true).
Expand Down
4 changes: 2 additions & 2 deletions morph/Scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace morph {
throw std::runtime_error ("ScaleImplBase::transform(): Ensure data.size()==output.size()");
}
if (this->do_autoscale == true && !this->ready()) {
this->compute_scaling_from<Container> (data); // not const
this->compute_scaling_from_data<Container> (data); // not const
} else if (this->do_autoscale == false && !this->ready()) {
throw std::runtime_error ("ScaleImplBase::transform(): Params are not set and do_autoscale is set false. Can't transform.");
}
Expand Down Expand Up @@ -221,7 +221,7 @@ namespace morph {
*/
template <typename Container>
std::enable_if_t<morph::is_copyable_container<Container>::value, void>
compute_scaling_from (const Container& data)
compute_scaling_from_data (const Container& data)
{
morph::range<typename Container::value_type> mm = MathAlgo::maxmin (data);
this->compute_scaling (mm.min, mm.max);
Expand Down

0 comments on commit d9461c1

Please sign in to comment.