[librsvg] rect: move IRect to rect.rs
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] rect: move IRect to rect.rs
- Date: Fri, 28 Dec 2018 17:35:58 +0000 (UTC)
commit b1cb06d4937bae49a025ae13ce9e22f8df0be2de
Author: Paolo Borelli <pborelli gnome org>
Date: Wed Dec 26 18:37:09 2018 +0100
rect: move IRect to rect.rs
It is used also outside of filters, so let's move it somewhere more
generic.
rsvg_internals/benches/box_blur.rs | 2 +-
rsvg_internals/benches/composite.rs | 3 +-
rsvg_internals/benches/lighting.rs | 26 ++++++------
rsvg_internals/benches/pixel_iterators.rs | 2 +-
rsvg_internals/benches/srgb.rs | 2 +-
rsvg_internals/src/filters/bounds.rs | 3 +-
rsvg_internals/src/filters/composite.rs | 3 +-
rsvg_internals/src/filters/context.rs | 49 +---------------------
rsvg_internals/src/filters/convolve_matrix.rs | 3 +-
rsvg_internals/src/filters/gaussian_blur.rs | 3 +-
rsvg_internals/src/filters/image.rs | 3 +-
rsvg_internals/src/filters/light/mod.rs | 2 +-
rsvg_internals/src/filters/merge.rs | 3 +-
rsvg_internals/src/filters/morphology.rs | 3 +-
rsvg_internals/src/filters/offset.rs | 3 +-
rsvg_internals/src/handle.rs | 2 +-
rsvg_internals/src/mask.rs | 2 +-
rsvg_internals/src/rect.rs | 48 +++++++++++++++++++++
rsvg_internals/src/srgb.rs | 2 +-
rsvg_internals/src/surface_utils/iterators.rs | 2 +-
rsvg_internals/src/surface_utils/shared_surface.rs | 2 +-
21 files changed, 88 insertions(+), 80 deletions(-)
---
diff --git a/rsvg_internals/benches/box_blur.rs b/rsvg_internals/benches/box_blur.rs
index 51aacec6..ac7b017a 100644
--- a/rsvg_internals/benches/box_blur.rs
+++ b/rsvg_internals/benches/box_blur.rs
@@ -6,7 +6,7 @@ extern crate cairo;
extern crate cairo_sys;
extern crate rsvg_internals;
-use rsvg_internals::filters::context::IRect;
+use rsvg_internals::rect::IRect;
use rsvg_internals::surface_utils::shared_surface::{
AlphaOnly,
Horizontal,
diff --git a/rsvg_internals/benches/composite.rs b/rsvg_internals/benches/composite.rs
index fda878d1..94d6010a 100644
--- a/rsvg_internals/benches/composite.rs
+++ b/rsvg_internals/benches/composite.rs
@@ -6,7 +6,8 @@ extern crate cairo;
extern crate cairo_sys;
extern crate rsvg_internals;
-use rsvg_internals::filters::{composite::composite_arithmetic, context::IRect};
+use rsvg_internals::filters::composite::composite_arithmetic;
+use rsvg_internals::rect::IRect;
use rsvg_internals::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
const SURFACE_SIDE: i32 = 512;
diff --git a/rsvg_internals/benches/lighting.rs b/rsvg_internals/benches/lighting.rs
index 49701e65..c66ca4db 100644
--- a/rsvg_internals/benches/lighting.rs
+++ b/rsvg_internals/benches/lighting.rs
@@ -9,21 +9,19 @@ extern crate rsvg_internals;
use nalgebra::{Matrix3, Vector2};
-use rsvg_internals::filters::{
- context::IRect,
- light::{
- bottom_left_normal,
- bottom_right_normal,
- bottom_row_normal,
- interior_normal,
- left_column_normal,
- right_column_normal,
- top_left_normal,
- top_right_normal,
- top_row_normal,
- Normal,
- },
+use rsvg_internals::filters::light::{
+ bottom_left_normal,
+ bottom_right_normal,
+ bottom_row_normal,
+ interior_normal,
+ left_column_normal,
+ right_column_normal,
+ top_left_normal,
+ top_right_normal,
+ top_row_normal,
+ Normal,
};
+use rsvg_internals::rect::IRect;
use rsvg_internals::surface_utils::{
iterators::{PixelRectangle, Pixels},
shared_surface::{SharedImageSurface, SurfaceType},
diff --git a/rsvg_internals/benches/pixel_iterators.rs b/rsvg_internals/benches/pixel_iterators.rs
index b3ed1396..c54725e8 100644
--- a/rsvg_internals/benches/pixel_iterators.rs
+++ b/rsvg_internals/benches/pixel_iterators.rs
@@ -6,7 +6,7 @@ extern crate cairo;
extern crate cairo_sys;
extern crate rsvg_internals;
-use rsvg_internals::filters::context::IRect;
+use rsvg_internals::rect::IRect;
use rsvg_internals::surface_utils::{
iterators::Pixels,
shared_surface::{SharedImageSurface, SurfaceType},
diff --git a/rsvg_internals/benches/srgb.rs b/rsvg_internals/benches/srgb.rs
index 9c3aea7b..89786072 100644
--- a/rsvg_internals/benches/srgb.rs
+++ b/rsvg_internals/benches/srgb.rs
@@ -6,7 +6,7 @@ extern crate cairo;
extern crate cairo_sys;
extern crate rsvg_internals;
-use rsvg_internals::filters::context::IRect;
+use rsvg_internals::rect::IRect;
use rsvg_internals::srgb::{linearize, map_unpremultiplied_components_loop};
use rsvg_internals::surface_utils::{
shared_surface::{SharedImageSurface, SurfaceType},
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index d858cab3..94a3c305 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -4,8 +4,9 @@ use cairo::{self, MatrixTrait};
use bbox::BoundingBox;
use drawing_ctx::DrawingCtx;
use length::Length;
+use rect::IRect;
-use super::context::{FilterContext, FilterInput, FilterOutput, IRect};
+use super::context::{FilterContext, FilterInput, FilterOutput};
/// A helper type for filter primitive subregion computation.
#[derive(Clone, Copy)]
diff --git a/rsvg_internals/src/filters/composite.rs b/rsvg_internals/src/filters/composite.rs
index 509d3eb0..c8869305 100644
--- a/rsvg_internals/src/filters/composite.rs
+++ b/rsvg_internals/src/filters/composite.rs
@@ -10,6 +10,7 @@ use handle::RsvgHandle;
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers::{self, parse, Parse};
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::{
iterators::Pixels,
shared_surface::SharedImageSurface,
@@ -18,7 +19,7 @@ use surface_utils::{
};
use util::clamp;
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::input::Input;
use super::{Filter, FilterError, PrimitiveWithInput};
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index ebda2a3e..6941f85b 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -10,6 +10,7 @@ use drawing_ctx::DrawingCtx;
use length::Length;
use node::RsvgNode;
use paint_server::{self, PaintServer};
+use rect::IRect;
use state::ComputedValues;
use surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
use unitinterval::UnitInterval;
@@ -18,14 +19,6 @@ use super::error::FilterError;
use super::input::Input;
use super::node::NodeFilter;
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct IRect {
- pub x0: i32,
- pub y0: i32,
- pub x1: i32,
- pub y1: i32,
-}
-
/// A filter primitive output.
#[derive(Debug, Clone)]
pub struct FilterOutput {
@@ -168,27 +161,6 @@ fn compute_effects_region(
bbox
}
-impl IRect {
- /// Returns true if the `IRect` contains the given coordinates.
- #[inline]
- pub fn contains(self, x: i32, y: i32) -> bool {
- x >= self.x0 && x < self.x1 && y >= self.y0 && y < self.y1
- }
-
- /// Returns an `IRect` scaled by the given amounts.
- ///
- /// The returned `IRect` encompasses all, even partially covered, pixels after the scaling.
- #[inline]
- pub fn scale(self, x: f64, y: f64) -> IRect {
- IRect {
- x0: (f64::from(self.x0) * x).floor() as i32,
- y0: (f64::from(self.y0) * y).floor() as i32,
- x1: (f64::from(self.x1) * x).ceil() as i32,
- y1: (f64::from(self.y1) * y).ceil() as i32,
- }
- }
-}
-
impl FilterContext {
/// Creates a new `FilterContext`.
pub fn new(
@@ -604,25 +576,6 @@ impl FilterInput {
}
}
-impl From<cairo::Rectangle> for IRect {
- #[inline]
- fn from(
- cairo::Rectangle {
- x,
- y,
- width,
- height,
- }: cairo::Rectangle,
- ) -> Self {
- Self {
- x0: x.floor() as i32,
- y0: y.floor() as i32,
- x1: (x + width).ceil() as i32,
- y1: (y + height).ceil() as i32,
- }
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rsvg_internals/src/filters/convolve_matrix.rs b/rsvg_internals/src/filters/convolve_matrix.rs
index cf4d39e6..98e7a1b5 100644
--- a/rsvg_internals/src/filters/convolve_matrix.rs
+++ b/rsvg_internals/src/filters/convolve_matrix.rs
@@ -10,6 +10,7 @@ use handle::RsvgHandle;
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers::{self, ListLength, NumberListError, ParseError};
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::{
iterators::{PixelRectangle, Pixels},
shared_surface::SharedImageSurface,
@@ -19,7 +20,7 @@ use surface_utils::{
};
use util::clamp;
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{Filter, FilterError, PrimitiveWithInput};
/// The `feConvolveMatrix` filter primitive.
diff --git a/rsvg_internals/src/filters/gaussian_blur.rs b/rsvg_internals/src/filters/gaussian_blur.rs
index ba782d06..b33fe4cc 100644
--- a/rsvg_internals/src/filters/gaussian_blur.rs
+++ b/rsvg_internals/src/filters/gaussian_blur.rs
@@ -12,12 +12,13 @@ use handle::RsvgHandle;
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers;
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::{
shared_surface::{BlurDirection, Horizontal, SharedImageSurface, Vertical},
EdgeMode,
};
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{Filter, FilterError, PrimitiveWithInput};
/// The maximum gaussian blur kernel size.
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index 4d84fbe1..ada5122d 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -13,10 +13,11 @@ use handle::{self, RsvgHandle};
use node::{CascadedValues, NodeResult, NodeTrait, RsvgNode};
use parsers::{parse, ParseError};
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
use super::bounds::BoundsBuilder;
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{Filter, FilterError, Primitive};
/// The `feImage` filter primitive.
diff --git a/rsvg_internals/src/filters/light/mod.rs b/rsvg_internals/src/filters/light/mod.rs
index 7b98eb0a..69e579c7 100644
--- a/rsvg_internals/src/filters/light/mod.rs
+++ b/rsvg_internals/src/filters/light/mod.rs
@@ -1,7 +1,7 @@
//! Light filters and nodes.
use nalgebra::Vector2;
-use filters::context::IRect;
+use rect::IRect;
use surface_utils::shared_surface::SharedImageSurface;
pub mod light_source;
diff --git a/rsvg_internals/src/filters/merge.rs b/rsvg_internals/src/filters/merge.rs
index d1e2e86d..9e504b76 100644
--- a/rsvg_internals/src/filters/merge.rs
+++ b/rsvg_internals/src/filters/merge.rs
@@ -7,9 +7,10 @@ use drawing_ctx::DrawingCtx;
use handle::RsvgHandle;
use node::{NodeResult, NodeTrait, NodeType, RsvgNode};
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::input::Input;
use super::{Filter, FilterError, Primitive};
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index 07cdbb64..7723cff7 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -10,6 +10,7 @@ use handle::RsvgHandle;
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers::{self, ParseError};
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::{
iterators::{PixelRectangle, Pixels},
shared_surface::SharedImageSurface,
@@ -18,7 +19,7 @@ use surface_utils::{
Pixel,
};
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{Filter, FilterError, PrimitiveWithInput};
/// Enumeration of the possible morphology operations.
diff --git a/rsvg_internals/src/filters/offset.rs b/rsvg_internals/src/filters/offset.rs
index 0180004c..a81c4ad6 100644
--- a/rsvg_internals/src/filters/offset.rs
+++ b/rsvg_internals/src/filters/offset.rs
@@ -9,10 +9,11 @@ use handle::RsvgHandle;
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers;
use property_bag::PropertyBag;
+use rect::IRect;
use surface_utils::shared_surface::SharedImageSurface;
use util::clamp;
-use super::context::{FilterContext, FilterOutput, FilterResult, IRect};
+use super::context::{FilterContext, FilterOutput, FilterResult};
use super::{Filter, FilterError, PrimitiveWithInput};
/// The `feOffset` filter primitive.
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 1e52fe53..dc9e54ff 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -21,10 +21,10 @@ use defs::{Fragment, Href};
use dpi::Dpi;
use drawing_ctx::{DrawingCtx, RsvgRectangle};
use error::{set_gerror, DefsLookupErrorKind, LoadingError, RenderingError};
-use filters::context::IRect;
use io;
use load::LoadContext;
use node::{Node, RsvgNode};
+use rect::IRect;
use structure::NodeSvg;
use surface_utils::{
iterators::Pixels,
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index 965b0ef4..b05a1efb 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -5,12 +5,12 @@ use attributes::Attribute;
use coord_units::CoordUnits;
use drawing_ctx::DrawingCtx;
use error::RenderingError;
-use filters::context::IRect;
use handle::RsvgHandle;
use length::{Length, LengthDir};
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers::{parse, parse_and_validate, Parse};
use property_bag::PropertyBag;
+use rect::IRect;
use state::Opacity;
use surface_utils::{
iterators::Pixels,
diff --git a/rsvg_internals/src/rect.rs b/rsvg_internals/src/rect.rs
index 21c74e16..dc43aec5 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -111,6 +111,54 @@ impl RectangleExt for cairo::Rectangle {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct IRect {
+ pub x0: i32,
+ pub y0: i32,
+ pub x1: i32,
+ pub y1: i32,
+}
+
+impl IRect {
+ /// Returns true if the `IRect` contains the given coordinates.
+ #[inline]
+ pub fn contains(self, x: i32, y: i32) -> bool {
+ x >= self.x0 && x < self.x1 && y >= self.y0 && y < self.y1
+ }
+
+ /// Returns an `IRect` scaled by the given amounts.
+ ///
+ /// The returned `IRect` encompasses all, even partially covered, pixels after the scaling.
+ #[inline]
+ pub fn scale(self, x: f64, y: f64) -> IRect {
+ IRect {
+ x0: (f64::from(self.x0) * x).floor() as i32,
+ y0: (f64::from(self.y0) * y).floor() as i32,
+ x1: (f64::from(self.x1) * x).ceil() as i32,
+ y1: (f64::from(self.y1) * y).ceil() as i32,
+ }
+ }
+}
+
+impl From<cairo::Rectangle> for IRect {
+ #[inline]
+ fn from(
+ cairo::Rectangle {
+ x,
+ y,
+ width,
+ height,
+ }: cairo::Rectangle,
+ ) -> Self {
+ Self {
+ x0: x.floor() as i32,
+ y0: y.floor() as i32,
+ x1: (x + width).ceil() as i32,
+ y1: (y + height).ceil() as i32,
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/rsvg_internals/src/srgb.rs b/rsvg_internals/src/srgb.rs
index b9da0c00..0b283162 100644
--- a/rsvg_internals/src/srgb.rs
+++ b/rsvg_internals/src/srgb.rs
@@ -3,7 +3,7 @@
//! The constant values in this module are taken from http://www.color.org/chardata/rgb/srgb.xalter
use cairo;
-use filters::context::IRect;
+use rect::IRect;
use surface_utils::{
iterators::Pixels,
shared_surface::{SharedImageSurface, SurfaceType},
diff --git a/rsvg_internals/src/surface_utils/iterators.rs b/rsvg_internals/src/surface_utils/iterators.rs
index 096f01c2..15c4b710 100644
--- a/rsvg_internals/src/surface_utils/iterators.rs
+++ b/rsvg_internals/src/surface_utils/iterators.rs
@@ -1,5 +1,5 @@
//! Pixel iterators for `SharedImageSurface`.
-use filters::context::IRect;
+use rect::IRect;
use util::clamp;
use super::shared_surface::SharedImageSurface;
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index db86cfe5..05c6a57d 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -11,7 +11,7 @@ use glib::translate::{Stash, ToGlibPtr};
use nalgebra::{storage::Storage, Dim, Matrix};
use rayon;
-use filters::context::IRect;
+use rect::IRect;
use srgb;
use util::clamp;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]