Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
Normalize.hpp
Go to the documentation of this file.
1#pragma once
2#include <cmath>
4#include <type_traits>
5#include <stdexcept>
6
7namespace fishnet::math{
8
18template<Number ValueType, Number BoundType>
19static auto normalize(const ValueType value, BoundType upperBound){
20 [[unlikely]] if (upperBound <= 0){
21 throw std::invalid_argument("Cannot normalize value into range [0,0), upperBound is zero or less");
22 }
23 if constexpr(std::integral<ValueType> && std::integral<BoundType>){
24 auto norm = value % upperBound;
25 if (norm < 0){
26 return norm + upperBound;
27 }
28 return norm;
29 }else {
30 auto norm = std::fmod(value,upperBound);
31 if (norm < 0 ){
32 return norm + upperBound;
33 }
34 return norm;
35 }
36};
37
46static auto normalize(Number auto value, Number auto lowerBound, Number auto upperBound){
47 [[unlikely]] if (lowerBound >= upperBound){
48 throw new std::invalid_argument("upperBound has to be greater than lowerBound");
49 }
50 auto range = upperBound - lowerBound;
51 auto norm_to_range = normalize(value+lowerBound,range);
52 return norm_to_range + lowerBound;
53}
54}
Definition NumericConcepts.hpp:7
Definition NumericConcepts.hpp:4
static auto normalize(const ValueType value, BoundType upperBound)
Normalizes any value into the range: [0,upperBound)
Definition Normalize.hpp:19