[librsvg: 3/12] Clear cast_lossless clippy warnings.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/12] Clear cast_lossless clippy warnings.
- Date: Mon, 8 Jan 2018 15:21:27 +0000 (UTC)
commit 26509f13fc84f39f390f7779ca213be81eeebf2d
Author: Jordan Petridis <jordanpetridis protonmail com>
Date: Sun Dec 17 09:18:34 2017 +0200
Clear cast_lossless clippy warnings.
For more see:
https://rust-lang-nursery.github.io/rust-clippy/v0.0.176/index.html#cast_lossless
rust/src/bbox.rs | 8 ++++----
rust/src/color.rs | 8 ++++----
rust/src/gradient.rs | 8 ++++----
rust/src/image.rs | 4 ++--
rust/src/length.rs | 6 +++---
rust/src/opacity.rs | 4 ++--
rust/src/parsers.rs | 14 +++++++-------
rust/src/path_builder.rs | 6 +++---
rust/src/path_parser.rs | 6 +++---
rust/src/pattern.rs | 4 ++--
rust/src/stop.rs | 8 ++++----
rust/src/text.rs | 2 +-
12 files changed, 39 insertions(+), 39 deletions(-)
---
diff --git a/rust/src/bbox.rs b/rust/src/bbox.rs
index ba17908..5a5dc13 100644
--- a/rust/src/bbox.rs
+++ b/rust/src/bbox.rs
@@ -71,8 +71,8 @@ pub extern fn rsvg_bbox_insert (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox
* the width/height to the first point src.rect.(x, y).
*/
for i in 0..4 {
- let rx: f64 = src.rect.x + src.rect.width * (i % 2) as f64;
- let ry: f64 = src.rect.y + src.rect.height * (i / 2) as f64;
+ let rx: f64 = src.rect.x + src.rect.width * f64::from(i % 2);
+ let ry: f64 = src.rect.y + src.rect.height * f64::from(i / 2);
let x: f64 = affine.xx * rx + affine.xy * ry + affine.x0;
let y: f64 = affine.yx * rx + affine.yy * ry + affine.y0;
@@ -132,8 +132,8 @@ pub extern fn rsvg_bbox_clip (raw_dst: *mut RsvgBbox, raw_src: *const RsvgBbox)
/* This is a trick. See rsvg_bbox_insert() for a description of how it works. */
for i in 0..4 {
- let rx: f64 = src.rect.x + src.rect.width * (i % 2) as f64;
- let ry: f64 = src.rect.y + src.rect.height * (i / 2) as f64;
+ let rx: f64 = src.rect.x + src.rect.width * f64::from(i % 2);
+ let ry: f64 = src.rect.y + src.rect.height * f64::from(i / 2);
let x = affine.xx * rx + affine.xy * ry + affine.x0;
let y = affine.yx * rx + affine.yy * ry + affine.y0;
diff --git a/rust/src/color.rs b/rust/src/color.rs
index 5928e41..5e12892 100644
--- a/rust/src/color.rs
+++ b/rust/src/color.rs
@@ -147,10 +147,10 @@ impl From<Result<Color, AttributeError>> for ColorSpec {
Ok (Color::RGBA (rgba)) =>
ColorSpec {
kind: ColorKind::ARGB,
- argb: ((rgba.alpha as u32) << 24 |
- (rgba.red as u32) << 16 |
- (rgba.green as u32) << 8 |
- (rgba.blue as u32))
+ argb: (u32::from(rgba.alpha) << 24 |
+ u32::from(rgba.red) << 16 |
+ u32::from(rgba.green) << 8 |
+ u32::from(rgba.blue))
},
_ =>
diff --git a/rust/src/gradient.rs b/rust/src/gradient.rs
index c52a07c..9b89270 100644
--- a/rust/src/gradient.rs
+++ b/rust/src/gradient.rs
@@ -276,10 +276,10 @@ impl Gradient {
for stop in stops {
let rgba = stop.rgba;
pattern.add_color_stop_rgba (stop.offset,
- ((rgba >> 24) & 0xff) as f64 / 255.0,
- ((rgba >> 16) & 0xff) as f64 / 255.0,
- ((rgba >> 8) & 0xff) as f64 / 255.0,
- (((rgba >> 0) & 0xff) * opacity as u32) as f64 / 255.0 / 255.0);
+ (f64::from((rgba >> 24) & 0xff)) / 255.0,
+ (f64::from((rgba >> 16) & 0xff)) / 255.0,
+ (f64::from((rgba >> 8) & 0xff)) / 255.0,
+ f64::from(((rgba >> 0) & 0xff) * u32::from(opacity)) / 255.0 /
255.0);
}
}
}
diff --git a/rust/src/image.rs b/rust/src/image.rs
index 6b415e4..c1da15b 100644
--- a/rust/src/image.rs
+++ b/rust/src/image.rs
@@ -103,8 +103,8 @@ impl NodeTrait for NodeImage {
}
}
- let (x, y, w, h) = aspect.compute (surface.get_width() as f64,
- surface.get_height() as f64,
+ let (x, y, w, h) = aspect.compute (f64::from(surface.get_width()),
+ f64::from(surface.get_height()),
x, y, w, h);
drawing_ctx::render_surface(draw_ctx, &surface, x, y, w, h);
diff --git a/rust/src/length.rs b/rust/src/length.rs
index 0c098b4..aee3772 100644
--- a/rust/src/length.rs
+++ b/rust/src/length.rs
@@ -200,16 +200,16 @@ impl RsvgLength {
.map_err (|_| AttributeError::Parse (ParseError::new ("expected number and optional symbol,
or number and percentage")))?;
match *token {
- Token::Number { value, .. } => RsvgLength { length: value as f64,
+ Token::Number { value, .. } => RsvgLength { length: f64::from(value),
unit: LengthUnit::Default,
dir: dir },
- Token::Percentage { unit_value, .. } => RsvgLength { length: unit_value as f64,
+ Token::Percentage { unit_value, .. } => RsvgLength { length: f64::from(unit_value),
unit: LengthUnit::Percent,
dir: dir },
Token::Dimension { value, ref unit, .. } => {
- let value = value as f64;
+ let value = f64::from(value);
match unit.as_ref () {
"em" => RsvgLength { length: value,
diff --git a/rust/src/opacity.rs b/rust/src/opacity.rs
index 1408679..50b3b55 100644
--- a/rust/src/opacity.rs
+++ b/rust/src/opacity.rs
@@ -93,7 +93,7 @@ impl FromStr for Opacity {
} else if value > 1.0 {
Opacity::Specified (1.0)
} else {
- Opacity::Specified (value as f64)
+ Opacity::Specified (f64::from(value))
}
},
@@ -112,7 +112,7 @@ impl Opacity {
match *spec {
OpacitySpec { kind: OpacityKind::Inherit, .. } => Ok (Opacity::Inherit),
- OpacitySpec { kind: OpacityKind::Specified, opacity } => Ok (Opacity::Specified (opacity as f64
/ 255.0)),
+ OpacitySpec { kind: OpacityKind::Specified, opacity } => Ok (Opacity::Specified
(f64::from(opacity) / 255.0)),
OpacitySpec { kind: OpacityKind::ParseError, .. } => Err (AttributeError::Parse (ParseError::new
("parse error")))
}
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 27067d1..49e43a5 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -49,10 +49,10 @@ pub fn angle_degrees (s: &str) -> Result <f64, ParseError> {
.map_err (|_| ParseError::new ("expected angle"))?;
match *token {
- Token::Number { value, .. } => value as f64,
+ Token::Number { value, .. } => f64::from(value),
Token::Dimension { value, ref unit, .. } => {
- let value = value as f64;
+ let value = f64::from(value);
match unit.as_ref () {
"deg" => value,
@@ -84,7 +84,7 @@ pub fn number_optional_number (s: &str) -> Result <(f64, f64), ParseError> {
let mut input = ParserInput::new (s);
let mut parser = Parser::new (&mut input);
- let x = parser.expect_number ()? as f64;
+ let x = f64::from(parser.expect_number ()?);
if !parser.is_exhausted () {
let position = parser.position ();
@@ -94,7 +94,7 @@ pub fn number_optional_number (s: &str) -> Result <(f64, f64), ParseError> {
_ => parser.reset (position)
};
- let y = parser.expect_number ()? as f64;
+ let y = f64::from(parser.expect_number ()?);
parser.expect_exhausted ()?;
@@ -144,11 +144,11 @@ pub fn list_of_points (string: &str) -> Result <Vec<(f64, f64)>, ParseError> {
let mut v = Vec::new ();
loop {
- let x = parser.expect_number ()? as f64;
+ let x = f64::from(parser.expect_number ()?);
optional_comma (&mut parser);
- let y = parser.expect_number ()? as f64;
+ let y = f64::from(parser.expect_number ()?);
v.push ((x, y));
@@ -192,7 +192,7 @@ pub fn number_list (s: &str, length: ListLength) -> Result <Vec<f64>, NumberList
let mut v = Vec::<f64>::with_capacity (n);
for i in 0..n {
- v.push (parser.expect_number ().map_err (|_| NumberListError::Parse (ParseError::new ("expected
number")))? as f64);
+ v.push (f64::from(parser.expect_number ().map_err (|_| NumberListError::Parse (ParseError::new
("expected number")))?));
if i != n - 1 {
optional_comma (&mut parser);
diff --git a/rust/src/path_builder.rs b/rust/src/path_builder.rs
index f4361df..f1434c5 100644
--- a/rust/src/path_builder.rs
+++ b/rust/src/path_builder.rs
@@ -186,12 +186,12 @@ impl RsvgPathBuilder {
/* Now draw the arc */
n_segs = (delta_theta / (PI * 0.5 + 0.001)).abs ().ceil () as i32;
- let n_segs_dbl = n_segs as f64;
+ let n_segs_dbl = f64::from(n_segs);
for i in 0 .. n_segs {
self.arc_segment (cx, cy,
- theta1 + i as f64 * delta_theta / n_segs_dbl,
- theta1 + (i + 1) as f64 * delta_theta / n_segs_dbl,
+ theta1 + f64::from(i) * delta_theta / n_segs_dbl,
+ theta1 + f64::from(i + 1) * delta_theta / n_segs_dbl,
rx, ry,
x_axis_rotation);
}
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index ad3b35b..72b7f1f 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -219,7 +219,7 @@ impl<'b> PathParser<'b> {
/* Integer part */
while self.lookahead_is_digit (&mut c) {
- value = value * 10.0 + char_to_digit (c) as f64;
+ value = value * 10.0 + f64::from(char_to_digit (c));
assert! (self.match_char (c));
}
@@ -233,7 +233,7 @@ impl<'b> PathParser<'b> {
while self.lookahead_is_digit (&mut c) {
fraction = fraction / 10.0;
- value += fraction * char_to_digit (c) as f64;
+ value += fraction * f64::from(char_to_digit (c));
assert! (self.match_char (c));
}
@@ -254,7 +254,7 @@ impl<'b> PathParser<'b> {
if self.lookahead_is_digit (&mut c) {
while self.lookahead_is_digit (&mut c) {
- exponent = exponent * 10.0 + char_to_digit (c) as f64;
+ exponent = exponent * 10.0 + f64::from(char_to_digit (c));
assert! (self.match_char (c));
}
diff --git a/rust/src/pattern.rs b/rust/src/pattern.rs
index 5822ee6..111f2a9 100644
--- a/rust/src/pattern.rs
+++ b/rust/src/pattern.rs
@@ -323,8 +323,8 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
return false;
}
- scwscale = pw as f64 / scaled_width;
- schscale = ph as f64 / scaled_height;
+ scwscale = f64::from(pw) / scaled_width;
+ schscale = f64::from(ph) / scaled_height;
let mut affine: cairo::Matrix = cairo::Matrix::identity ();
diff --git a/rust/src/stop.rs b/rust/src/stop.rs
index cc396f5..8defca7 100644
--- a/rust/src/stop.rs
+++ b/rust/src/stop.rs
@@ -166,10 +166,10 @@ impl NodeTrait for NodeStop {
}
fn u32_from_rgba (rgba: cssparser::RGBA) -> u32 {
- ((rgba.red as u32) << 24) |
- ((rgba.green as u32) << 16) |
- ((rgba.blue as u32) << 8) |
- (rgba.alpha as u32)
+ (u32::from(rgba.red) << 24) |
+ (u32::from(rgba.green) << 16) |
+ (u32::from(rgba.blue) << 8) |
+ u32::from(rgba.alpha)
}
extern "C" {
diff --git a/rust/src/text.rs b/rust/src/text.rs
index 24d7823..04ee437 100644
--- a/rust/src/text.rs
+++ b/rust/src/text.rs
@@ -15,7 +15,7 @@ fn gravity_is_vertical(gravity: pango::Gravity) -> bool {
}
fn to_pango_units(v: f64) -> i32 {
- (v * pango::SCALE as f64) as i32
+ (v * f64::from(pango::SCALE)) as i32
}
fn create_pango_layout(draw_ctx: *const RsvgDrawingCtx, text: &str) -> pango::Layout {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]