Skip to content

Commit

Permalink
Info about the changes in morph::range and morph::Scale plus an extra…
Browse files Browse the repository at this point in the history
… Scale test
  • Loading branch information
sebjameswml committed Oct 17, 2024
1 parent c0ad64a commit 658e28a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/ref/coremaths/range.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ morph::range<float> r(0.0f, 10.0f); // Construct with a defined range
**Update** the range to include a value
```c++
morph::range<int> r; // range initially 0 to 0
r.update (100); // range now 0 to 100
r.update (-100); // range now -100 to 100
bool changed1 = r.update (100); // range now 0 to 100
bool changed2 = r.update (-100); // range now -100 to 100
bool changed3 = r.update (50); // range unchanged; still -100 to 100
```

`update` returns a `bool` which will be true if the range was changed and false if the range is not changed. In the example above, `changed1` and changed2` will both be `true`, but `changed3` will contain `false`.

**Set** the range manually in a single function call
```c++
morph::range<int> r; // range initially 0 to 0
Expand Down
10 changes: 9 additions & 1 deletion docs/ref/coremaths/scale.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,15 @@ 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_data`, which is the function that is automatically called by `transform` when `do_autoscale` is `true`.
You can also pass the input range to `Scale<>::compute_scaling` and set the `output_range` using `morph::range<>` objects:

```c++
morph::Scale<int, float> s;
s.output_range = morph::range<float>{0, 5};
s.compute_scaling (morph::range<int>{-10, 10});
```
You can 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;
Expand Down
7 changes: 7 additions & 0 deletions tests/testScale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,12 @@ int main () {
// Fifth element should be NaN still:
if (!std::isnan(resultnan[5])) { --rtn; }

morph::Scale<int, float> sif;
sif.output_range = morph::range<float>{0, 5};
sif.compute_scaling (morph::range<int>{-10, 10});
std::cout << "input 8(int) transforms to float: " << sif.transform_one (8) << std::endl;
if (sif.transform_one (8) != 4.5f) { --rtn; }

std::cout << "testScale " << (rtn == 0 ? "Passed" : "Failed") << std::endl;
return rtn;
}

0 comments on commit 658e28a

Please sign in to comment.