@@ -124,10 +124,15 @@ macro_rules! gen_key_points_comp {
124
124
// By default, we make the granularity as the 1/10 of the scale.
125
125
let mut value_granularity = scale / 10.0 ;
126
126
fn rem_euclid( a: f64 , b: f64 ) -> f64 {
127
- if b > 0.0 {
127
+ let ret = if b > 0.0 {
128
128
a - ( a / b) . floor( ) * b
129
129
} else {
130
130
a - ( a / b) . ceil( ) * b
131
+ } ;
132
+ if ( ret - b) . abs( ) < std:: f64 :: EPSILON {
133
+ 0.0
134
+ } else {
135
+ ret
131
136
}
132
137
}
133
138
@@ -174,7 +179,7 @@ macro_rules! gen_key_points_comp {
174
179
let left_base = ( left / value_granularity) . floor( ) * value_granularity;
175
180
let mut left_relative = left - left_base;
176
181
let right = range. 1 - rem_euclid( range. 1 , scale) ;
177
- while left_relative <= right - left_base {
182
+ while ( right - left_relative - left_base) >= -std :: f64 :: EPSILON {
178
183
let new_left_relative = ( left_relative / value_granularity) . round( ) * value_granularity;
179
184
if new_left_relative < 0.0 {
180
185
left_relative += value_granularity;
@@ -423,5 +428,8 @@ mod test {
423
428
let coord: RangedCoordf64 = ( 1.0 ..125.0 ) . into ( ) ;
424
429
let points = coord. key_points ( 12 ) ;
425
430
assert_eq ! ( points. len( ) , 12 ) ;
431
+ let coord: RangedCoordf64 = ( 0.9995 ..1.0005 ) . into ( ) ;
432
+ let points = coord. key_points ( 11 ) ;
433
+ assert_eq ! ( points. len( ) , 11 ) ;
426
434
}
427
435
}
0 commit comments