[librsvg: 8/19] Avoid strict comparison of floating point values




commit 71c959b4a03d7218054bf0c920c558c4e947f62d
Author: Sven Neumann <sven svenfoo org>
Date:   Thu Aug 20 23:18:24 2020 +0200

    Avoid strict comparison of floating point values
    
    See https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp

 rsvg_internals/src/drawing_ctx.rs      | 3 ++-
 rsvg_internals/src/filters/lighting.rs | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 4e61f11ce..fa8201c9b 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -510,7 +510,8 @@ impl DrawingCtx {
                 // Here we are clipping in user space, so the bbox doesn't matter
                 dc.clip_to_node(&clip_in_user_space, acquired_nodes, &dc.empty_bbox())?;
 
-                let needs_temporary_surface = !(opacity == 1.0
+                let is_opaque = (opacity - 1.0).abs() < f64::EPSILON;
+                let needs_temporary_surface = !(is_opaque
                     && filter.is_none()
                     && mask.is_none()
                     && clip_in_object_space.is_none());
diff --git a/rsvg_internals/src/filters/lighting.rs b/rsvg_internals/src/filters/lighting.rs
index 256ef928b..848246548 100644
--- a/rsvg_internals/src/filters/lighting.rs
+++ b/rsvg_internals/src/filters/lighting.rs
@@ -421,7 +421,7 @@ impl Lighting for FeSpecularLighting {
         let k = if normal.normal.is_zero() {
             // Common case of (0, 0, 1) normal.
             let n_dot_h = h.z / h_norm;
-            if self.specular_exponent == 1.0 {
+            if (self.specular_exponent - 1.0).abs() < f64::EPSILON {
                 n_dot_h
             } else {
                 n_dot_h.powf(self.specular_exponent)
@@ -434,7 +434,7 @@ impl Lighting for FeSpecularLighting {
             let normal = Vector3::new(n.x, n.y, 1.0);
 
             let n_dot_h = normal.dot(&h) / normal.norm() / h_norm;
-            if self.specular_exponent == 1.0 {
+            if (self.specular_exponent - 1.0).abs() < f64::EPSILON {
                 n_dot_h
             } else {
                 n_dot_h.powf(self.specular_exponent)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]