@@ -2,7 +2,8 @@ use std::convert::TryFrom;
2
2
use std:: ops:: Range ;
3
3
4
4
use crate :: coord:: ranged1d:: {
5
- AsRangedCoord , DefaultFormatting , DiscreteRanged , KeyPointHint , Ranged , ReversibleRanged ,
5
+ AsRangedCoord , DefaultFormatting , DiscreteRanged , KeyPointHint , NoDefaultFormatting , Ranged ,
6
+ ReversibleRanged , ValueFormatter ,
6
7
} ;
7
8
8
9
macro_rules! impl_discrete_trait {
@@ -58,7 +59,7 @@ macro_rules! impl_reverse_mapping_trait {
58
59
} ;
59
60
}
60
61
macro_rules! make_numeric_coord {
61
- ( $type: ty, $name: ident, $key_points: ident, $doc: expr) => {
62
+ ( $type: ty, $name: ident, $key_points: ident, $doc: expr, $fmt : ident ) => {
62
63
#[ doc = $doc]
63
64
#[ derive( Clone ) ]
64
65
pub struct $name( $type, $type) ;
@@ -68,7 +69,7 @@ macro_rules! make_numeric_coord {
68
69
}
69
70
}
70
71
impl Ranged for $name {
71
- type FormatOption = DefaultFormatting ;
72
+ type FormatOption = $fmt ;
72
73
type ValueType = $type;
73
74
#[ allow( clippy:: float_cmp) ]
74
75
fn map( & self , v: & $type, limit: ( i32 , i32 ) ) -> i32 {
@@ -96,6 +97,9 @@ macro_rules! make_numeric_coord {
96
97
}
97
98
}
98
99
} ;
100
+ ( $type: ty, $name: ident, $key_points: ident, $doc: expr) => {
101
+ make_numeric_coord!( $type, $name, $key_points, $doc, DefaultFormatting ) ;
102
+ }
99
103
}
100
104
101
105
macro_rules! gen_key_points_comp {
@@ -207,16 +211,28 @@ make_numeric_coord!(
207
211
f32 ,
208
212
RangedCoordf32 ,
209
213
compute_f32_key_points,
210
- "The ranged coordinate for type f32"
214
+ "The ranged coordinate for type f32" ,
215
+ NoDefaultFormatting
211
216
) ;
212
217
impl_reverse_mapping_trait ! ( f32 , RangedCoordf32 ) ;
218
+ impl ValueFormatter < f32 > for RangedCoordf32 {
219
+ fn format ( value : & f32 ) -> String {
220
+ crate :: data:: float:: pretty_print_float ( * value as f64 , false )
221
+ }
222
+ }
213
223
make_numeric_coord ! (
214
224
f64 ,
215
225
RangedCoordf64 ,
216
226
compute_f64_key_points,
217
- "The ranged coordinate for type f64"
227
+ "The ranged coordinate for type f64" ,
228
+ NoDefaultFormatting
218
229
) ;
219
230
impl_reverse_mapping_trait ! ( f64 , RangedCoordf64 ) ;
231
+ impl ValueFormatter < f64 > for RangedCoordf64 {
232
+ fn format ( value : & f64 ) -> String {
233
+ crate :: data:: float:: pretty_print_float ( * value, false )
234
+ }
235
+ }
220
236
make_numeric_coord ! (
221
237
u32 ,
222
238
RangedCoordu32 ,
0 commit comments