1
1
use crate :: style:: { HSLColor , RGBAColor , RGBColor } ;
2
2
3
- use num_traits:: { Float , FromPrimitive , ToPrimitive } ;
4
-
5
3
/// Converts scalar values to colors.
6
4
pub trait ColorMap < ColorType : crate :: prelude:: Color , FloatType = f32 >
7
5
where
8
- FloatType : Float ,
6
+ FloatType : num_traits :: Float ,
9
7
{
10
8
/// Takes a scalar value 0.0 <= h <= 1.0 and returns the corresponding color.
11
9
/// Typically color-scales are named according to which color-type they return.
@@ -81,8 +79,8 @@ macro_rules! calculate_new_color_value(
81
79
} ;
82
80
) ;
83
81
84
- fn calculate_relative_difference_index_lower_upper <
85
- FloatType : Float + FromPrimitive + ToPrimitive ,
82
+ pub fn calculate_relative_difference_index_lower_upper <
83
+ FloatType : num_traits :: Float + num_traits :: FromPrimitive + num_traits :: ToPrimitive ,
86
84
> (
87
85
h : FloatType ,
88
86
min : FloatType ,
@@ -106,7 +104,7 @@ fn calculate_relative_difference_index_lower_upper<
106
104
macro_rules! implement_color_scale_for_derived_color_map{
107
105
( $( $color_type: ident) ,+) => {
108
106
$(
109
- impl <FloatType : Float + FromPrimitive + ToPrimitive > ColorMap <$color_type, FloatType > for DerivedColorMap <$color_type> {
107
+ impl <FloatType : num_traits :: Float + num_traits :: FromPrimitive + num_traits :: ToPrimitive > ColorMap <$color_type, FloatType > for DerivedColorMap <$color_type> {
110
108
fn get_color_normalized( & self , h: FloatType , min: FloatType , max: FloatType ) -> $color_type {
111
109
let (
112
110
relative_difference,
@@ -148,9 +146,12 @@ macro_rules! define_colors_from_list_of_values_or_directly{
148
146
} ;
149
147
}
150
148
149
+ #[ macro_export]
150
+ #[ doc( hidden) ]
151
+ /// Implements the [ColorMap] trait on a given color scale.
151
152
macro_rules! implement_linear_interpolation_color_map {
152
153
( $color_scale_name: ident, $color_type: ident) => {
153
- impl <FloatType : std:: fmt:: Debug + Float + FromPrimitive + ToPrimitive >
154
+ impl <FloatType : std:: fmt:: Debug + num_traits :: Float + num_traits :: FromPrimitive + num_traits :: ToPrimitive >
154
155
ColorMap <$color_type, FloatType > for $color_scale_name
155
156
{
156
157
fn get_color_normalized(
@@ -184,7 +185,7 @@ macro_rules! implement_linear_interpolation_color_map {
184
185
#[ doc = "Get color value from `" ]
185
186
#[ doc = stringify!( $color_scale_name) ]
186
187
#[ doc = "` by supplying a parameter 0.0 <= h <= 1.0" ]
187
- pub fn get_color<FloatType : std:: fmt:: Debug + Float + FromPrimitive + ToPrimitive >(
188
+ pub fn get_color<FloatType : std:: fmt:: Debug + num_traits :: Float + num_traits :: FromPrimitive + num_traits :: ToPrimitive >(
188
189
h: FloatType ,
189
190
) -> $color_type {
190
191
let color_scale = $color_scale_name { } ;
@@ -195,7 +196,7 @@ macro_rules! implement_linear_interpolation_color_map {
195
196
#[ doc = stringify!( $color_scale_name) ]
196
197
#[ doc = "` by supplying lower and upper bounds min, max and a parameter h where min <= h <= max" ]
197
198
pub fn get_color_normalized<
198
- FloatType : std:: fmt:: Debug + Float + FromPrimitive + ToPrimitive ,
199
+ FloatType : std:: fmt:: Debug + num_traits :: Float + num_traits :: FromPrimitive + num_traits :: ToPrimitive ,
199
200
>(
200
201
h: FloatType ,
201
202
min: FloatType ,
0 commit comments