[librsvg: 3/5] lighting: move utility function




commit 94494296c8e179e0a45bee29d9e1e63a2c62c7bc
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Dec 30 21:17:11 2020 +0100

    lighting: move utility function
    
    It is only called in lighting, no need to be a Context method.

 src/filters/context.rs  |  7 -------
 src/filters/lighting.rs | 12 +++++++++---
 2 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/filters/context.rs b/src/filters/context.rs
index 5c7fd269..417b58a5 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -1,6 +1,5 @@
 use once_cell::sync::OnceCell;
 use std::collections::HashMap;
-use std::f64;
 
 use crate::bbox::BoundingBox;
 use crate::coord_units::CoordUnits;
@@ -366,12 +365,6 @@ impl FilterContext {
         self.processing_linear_rgb = false;
         rv
     }
-
-    /// Applies the `primitiveUnits` coordinate transformation to a non-x or y distance.
-    #[inline]
-    pub fn transform_dist(&self, d: f64) -> f64 {
-        d * (self.paffine.xx.powi(2) + self.paffine.yy.powi(2)).sqrt() / f64::consts::SQRT_2
-    }
 }
 
 impl FilterInput {
diff --git a/src/filters/lighting.rs b/src/filters/lighting.rs
index b6a1cfec..c02f6e94 100644
--- a/src/filters/lighting.rs
+++ b/src/filters/lighting.rs
@@ -182,7 +182,7 @@ pub struct FePointLight {
 impl FePointLight {
     pub fn transform(&self, ctx: &FilterContext) -> LightSource {
         let (x, y) = ctx.paffine().transform_point(self.x, self.y);
-        let z = ctx.transform_dist(self.z);
+        let z = transform_dist(ctx, self.z);
 
         LightSource::Point {
             origin: Vector3::new(x, y, z),
@@ -222,11 +222,11 @@ pub struct FeSpotLight {
 impl FeSpotLight {
     pub fn transform(&self, ctx: &FilterContext) -> LightSource {
         let (x, y) = ctx.paffine().transform_point(self.x, self.y);
-        let z = ctx.transform_dist(self.z);
+        let z = transform_dist(ctx, self.z);
         let (points_at_x, points_at_y) = ctx
             .paffine()
             .transform_point(self.points_at_x, self.points_at_y);
-        let points_at_z = ctx.transform_dist(self.points_at_z);
+        let points_at_z = transform_dist(ctx, self.points_at_z);
 
         let origin = Vector3::new(x, y, z);
         let mut direction = Vector3::new(points_at_x, points_at_y, points_at_z) - origin;
@@ -270,6 +270,12 @@ impl SetAttributes for FeSpotLight {
 
 impl Draw for FeSpotLight {}
 
+/// Applies the `primitiveUnits` coordinate transformation to a non-x or y distance.
+#[inline]
+fn transform_dist(ctx: &FilterContext, d: f64) -> f64 {
+    d * (ctx.paffine().xx.powi(2) + ctx.paffine().yy.powi(2)).sqrt() / std::f64::consts::SQRT_2
+}
+
 /// The `feDiffuseLighting` filter primitives.
 pub struct FeDiffuseLighting {
     base: PrimitiveWithInput,


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