[librsvg: 4/10] rect: add (x|y)_range methods to IRect
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/10] rect: add (x|y)_range methods to IRect
- Date: Mon, 25 Nov 2019 01:59:28 +0000 (UTC)
commit 6d1aa33dca438e2d11c7cac0fc0f0c813fa547b1
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Nov 24 15:11:05 2019 +0100
rect: add (x|y)_range methods to IRect
Inspired from euclid's Rect
rsvg_internals/benches/pixel_iterators.rs | 8 ++++----
rsvg_internals/benches/srgb.rs | 4 ++--
rsvg_internals/src/filters/turbulence.rs | 4 ++--
rsvg_internals/src/rect.rs | 11 +++++++++++
4 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/rsvg_internals/benches/pixel_iterators.rs b/rsvg_internals/benches/pixel_iterators.rs
index 765f825d..b3708173 100644
--- a/rsvg_internals/benches/pixel_iterators.rs
+++ b/rsvg_internals/benches/pixel_iterators.rs
@@ -34,8 +34,8 @@ fn bench_pixel_iterators(c: &mut Criterion) {
let mut b = 0usize;
let mut a = 0usize;
- for y in bounds.y0..bounds.y1 {
- for x in bounds.x0..bounds.x1 {
+ for y in bounds.y_range() {
+ for x in bounds.x_range() {
let base = (y * stride + x * 4) as usize;
r += data[base + 0] as usize;
@@ -62,8 +62,8 @@ fn bench_pixel_iterators(c: &mut Criterion) {
let mut b = 0usize;
let mut a = 0usize;
- for y in bounds.y0..bounds.y1 {
- for x in bounds.x0..bounds.x1 {
+ for y in bounds.y_range() {
+ for x in bounds.x_range() {
let pixel = surface.get_pixel(x as u32, y as u32);
r += pixel.r as usize;
diff --git a/rsvg_internals/benches/srgb.rs b/rsvg_internals/benches/srgb.rs
index 37b67748..ec54b073 100644
--- a/rsvg_internals/benches/srgb.rs
+++ b/rsvg_internals/benches/srgb.rs
@@ -32,8 +32,8 @@ fn bench_srgb_linearization(c: &mut Criterion) {
let stride = surface.get_stride() as usize;
{
let mut data = surface.get_data().unwrap();
- for y in BOUNDS.y0..BOUNDS.y1 {
- for x in BOUNDS.x0..BOUNDS.x1 {
+ for y in BOUNDS.y_range() {
+ for x in BOUNDS.x_range() {
data.set_pixel(
stride,
Pixel {
diff --git a/rsvg_internals/src/filters/turbulence.rs b/rsvg_internals/src/filters/turbulence.rs
index 765efbfd..2c39ee2a 100644
--- a/rsvg_internals/src/filters/turbulence.rs
+++ b/rsvg_internals/src/filters/turbulence.rs
@@ -366,8 +366,8 @@ impl FilterEffect for FeTurbulence {
{
let mut output_data = output_surface.get_data().unwrap();
- for y in bounds.y0..bounds.y1 {
- for x in bounds.x0..bounds.x1 {
+ for y in bounds.y_range() {
+ for x in bounds.x_range() {
let point = affine.transform_point(f64::from(x), f64::from(y));
let point = [point.0, point.1];
diff --git a/rsvg_internals/src/rect.rs b/rsvg_internals/src/rect.rs
index 85c17a54..c8c34971 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -1,4 +1,5 @@
use cairo;
+use core::ops::Range;
use crate::float_eq_cairo::ApproxEqCairo;
@@ -137,6 +138,16 @@ pub struct IRect {
}
impl IRect {
+ #[inline]
+ pub fn x_range(&self) -> Range<i32> {
+ self.x0..self.x1
+ }
+
+ #[inline]
+ pub fn y_range(&self) -> Range<i32> {
+ self.y0..self.y1
+ }
+
/// Returns true if the `IRect` contains the given coordinates.
#[inline]
pub fn contains(self, x: i32, y: i32) -> bool {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]