[librsvg: 1/3] Use float_cmp for floating number comparisons




commit 4acf5f14534a906929d073574c81a95f08c00dce
Author: Sven Neumann <sven svenfoo org>
Date:   Mon Aug 24 11:19:30 2020 +0200

    Use float_cmp for floating number comparisons
    
    Follow-up change to one of the recent changes inspired by clippy.

 rsvg_internals/src/drawing_ctx.rs      | 3 ++-
 rsvg_internals/src/filters/lighting.rs | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 25f22e4e..db08b7ad 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -1,5 +1,6 @@
 //! The main context structure which drives the drawing process.
 
+use float_cmp::approx_eq;
 use once_cell::sync::Lazy;
 use regex::{Captures, Regex};
 use std::borrow::Cow;
@@ -510,7 +511,7 @@ 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 is_opaque = (opacity - 1.0).abs() < f64::EPSILON;
+                let is_opaque = approx_eq!(f64, opacity, 1.0);
                 let needs_temporary_surface = !(is_opaque
                     && filter.is_none()
                     && mask.is_none()
diff --git a/rsvg_internals/src/filters/lighting.rs b/rsvg_internals/src/filters/lighting.rs
index 80a7f2a8..2c45e9bc 100644
--- a/rsvg_internals/src/filters/lighting.rs
+++ b/rsvg_internals/src/filters/lighting.rs
@@ -1,5 +1,6 @@
 //! Lighting filters and light nodes.
 
+use float_cmp::approx_eq;
 use markup5ever::{expanded_name, local_name, namespace_url, ns};
 use matches::matches;
 use nalgebra::{Vector2, Vector3};
@@ -422,7 +423,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).abs() < f64::EPSILON {
+            if approx_eq!(f64, self.specular_exponent, 1.0) {
                 n_dot_h
             } else {
                 n_dot_h.powf(self.specular_exponent)
@@ -435,7 +436,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).abs() < f64::EPSILON {
+            if approx_eq!(f64, self.specular_exponent, 1.0) {
                 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]