Commit 2478d114 authored by Bastien Orivel's avatar Bastien Orivel Committed by Federico Mena Quintero

Update float-cmp

I chose to change the signature of approx_eq_cairo to take a `f64` instead
of a `&f64` to avoid having to dereference it in the function as it looks
better when calling that method.
parent 253512d5
Pipeline #102816 failed with stages
in 3 minutes
......@@ -337,7 +337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "float-cmp"
version = "0.4.0"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -935,7 +935,7 @@ dependencies = [
"data-url 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"downcast-rs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"float-cmp 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-pixbuf 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-pixbuf-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -1248,7 +1248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
"checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600"
"checksum float-cmp 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ef4eee449a2818084dad09f4fcd6e6e8932c482d8d94298493226782bb45b5e"
"checksum fragile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f8140122fa0d5dcb9fc8627cfce2b37cc1500f752636d46ea28bc26785c2f9"
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
"checksum futf 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b"
......
......@@ -25,7 +25,7 @@ cssparser = "0.25.5"
data-url = "0.1"
downcast-rs = "^1.0.0"
encoding = "0.2.33"
float-cmp = "= 0.4.0"
float-cmp = "0.5.2"
gdk-pixbuf = "0.7.0"
gdk-pixbuf-sys = "0.9.0"
gio = { version="0.7.0", features=["v2_48"] } # per configure.ac
......
......@@ -132,7 +132,7 @@ mod tests {
let i = Angle::from_vector(incoming_vx, incoming_vy);
let o = Angle::from_vector(outgoing_vx, outgoing_vy);
let bisected = i.bisect(o);
assert!(expected.approx_eq(&bisected.radians(), 2.0 * PI * f64::EPSILON, 1));
assert!(expected.approx_eq(bisected.radians(), (2.0 * PI * f64::EPSILON, 1)));
}
#[test]
......
......@@ -161,14 +161,14 @@ impl AspectRatio {
// https://www.w3.org/TR/SVG/struct.html#ImageElementWidthAttribute
// https://www.w3.org/TR/SVG/painting.html#MarkerWidthAttribute
if viewport.width.approx_eq_cairo(&0.0) || viewport.height.approx_eq_cairo(&0.0) {
if viewport.width.approx_eq_cairo(0.0) || viewport.height.approx_eq_cairo(0.0) {
return None;
}
// the preserveAspectRatio attribute is only used if viewBox is specified
// https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
if let Some(vbox) = vbox {
if vbox.width.approx_eq_cairo(&0.0) || vbox.height.approx_eq_cairo(&0.0) {
if vbox.width.approx_eq_cairo(0.0) || vbox.height.approx_eq_cairo(0.0) {
// Width or height of 0 for the viewBox disables rendering of the element
// https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
None
......
......@@ -141,7 +141,7 @@ impl Image {
),
);
if w.approx_eq_cairo(&0.0) || h.approx_eq_cairo(&0.0) {
if w.approx_eq_cairo(0.0) || h.approx_eq_cairo(0.0) {
return Ok(output_surface);
}
......
......@@ -53,13 +53,13 @@ impl FixedEqCairo for f64 {
/// and finally allow a difference of 1 unit-in-the-last-place (ULP)
/// for very large f64 values.
pub trait ApproxEqCairo: ApproxEq {
fn approx_eq_cairo(&self, other: &Self) -> bool;
fn approx_eq_cairo(self, other: Self) -> bool;
}
impl ApproxEqCairo for f64 {
fn approx_eq_cairo(&self, other: &f64) -> bool {
fn approx_eq_cairo(self, other: f64) -> bool {
let cairo_smallest_fraction = 1.0 / f64::from(1 << CAIRO_FIXED_FRAC_BITS);
self.approx_eq(other, cairo_smallest_fraction, 1)
self.approx_eq(other, (cairo_smallest_fraction, 1))
}
}
......@@ -67,7 +67,7 @@ impl ApproxEqCairo for f64 {
#[macro_export]
macro_rules! assert_approx_eq_cairo {
($left:expr, $right:expr) => {{
match (&$left, &$right) {
match ($left, $right) {
(l, r) => {
if !l.approx_eq_cairo(r) {
panic!(
......@@ -98,28 +98,28 @@ mod tests {
#[test]
fn numbers_approx_equal() {
// 0 == 1/256 - cairo can represent it, so not equal
assert!(!0.0_f64.approx_eq_cairo(&0.00390635_f64));
assert!(!0.0_f64.approx_eq_cairo(0.00390635_f64));
// 1 == 1 + 1/256 - cairo can represent it, so not equal
assert!(!1.0_f64.approx_eq_cairo(&1.00390635_f64));
assert!(!1.0_f64.approx_eq_cairo(1.00390635_f64));
// 0 == 1/256 - cairo can represent it, so not equal
assert!(!0.0_f64.approx_eq_cairo(&-0.00390635_f64));
assert!(!0.0_f64.approx_eq_cairo(-0.00390635_f64));
// 1 == 1 - 1/256 - cairo can represent it, so not equal
assert!(!1.0_f64.approx_eq_cairo(&0.99609365_f64));
assert!(!1.0_f64.approx_eq_cairo(0.99609365_f64));
// 0 == 1/512 - cairo approximates to 0, so equal
assert!(0.0_f64.approx_eq_cairo(&0.001953125_f64));
assert!(0.0_f64.approx_eq_cairo(0.001953125_f64));
// 1 == 1 + 1/512 - cairo approximates to 1, so equal
assert!(1.0_f64.approx_eq_cairo(&1.001953125_f64));
assert!(1.0_f64.approx_eq_cairo(1.001953125_f64));
// 0 == -1/512 - cairo approximates to 0, so equal
assert!(0.0_f64.approx_eq_cairo(&-0.001953125_f64));
assert!(0.0_f64.approx_eq_cairo(-0.001953125_f64));
// 1 == 1 - 1/512 - cairo approximates to 1, so equal
assert!(1.0_f64.approx_eq_cairo(&0.998046875_f64));
assert!(1.0_f64.approx_eq_cairo(0.998046875_f64));
// This is 2^53 compared to (2^53 + 2). When represented as
// f64, they are 1 unit-in-the-last-place (ULP) away from each
......@@ -135,8 +135,8 @@ mod tests {
//
// In the second assertion, we compare 2^53 with (2^53 + 4). Those are
// 2 ULPs away, and we don't consider them equal.
assert!(9_007_199_254_740_992.0.approx_eq_cairo(&9_007_199_254_740_994.0));
assert!(!9_007_199_254_740_992.0.approx_eq_cairo(&9_007_199_254_740_996.0));
assert!(9_007_199_254_740_992.0.approx_eq_cairo(9_007_199_254_740_994.0));
assert!(!9_007_199_254_740_992.0.approx_eq_cairo(9_007_199_254_740_996.0));
}
#[test]
......
......@@ -74,7 +74,7 @@ impl NodeTrait for NodeImage {
let w = self.w.normalize(values, &params);
let h = self.h.normalize(values, &params);
if w.approx_eq_cairo(&0.0) || h.approx_eq_cairo(&0.0) {
if w.approx_eq_cairo(0.0) || h.approx_eq_cairo(0.0) {
return Ok(());
}
......
......@@ -133,7 +133,7 @@ impl NodeMarker {
let marker_width = self.width.normalize(&values, &params);
let marker_height = self.height.normalize(&values, &params);
if marker_width.approx_eq_cairo(&0.0) || marker_height.approx_eq_cairo(&0.0) {
if marker_width.approx_eq_cairo(0.0) || marker_height.approx_eq_cairo(0.0) {
// markerWidth or markerHeight set to 0 disables rendering of the element
// https://www.w3.org/TR/SVG/painting.html#MarkerWidthAttribute
return Ok(());
......@@ -161,7 +161,7 @@ impl NodeMarker {
&Rectangle::new(0.0, 0.0, marker_width, marker_height),
);
if vbox.width.approx_eq_cairo(&0.0) || vbox.height.approx_eq_cairo(&0.0) {
if vbox.width.approx_eq_cairo(0.0) || vbox.height.approx_eq_cairo(0.0) {
return Ok(());
}
......@@ -317,7 +317,7 @@ impl Segment {
}
fn points_equal(x1: f64, y1: f64, x2: f64, y2: f64) -> bool {
x1.approx_eq_cairo(&x2) && y1.approx_eq_cairo(&y2)
x1.approx_eq_cairo(x2) && y1.approx_eq_cairo(y2)
}
enum SegmentState {
......@@ -647,7 +647,7 @@ pub fn render_markers_for_path_builder(
.0
.normalize(values, &draw_ctx.get_view_params());
if line_width.approx_eq_cairo(&0.0) {
if line_width.approx_eq_cairo(0.0) {
return Ok(());
}
......
......@@ -88,7 +88,7 @@ impl EllipticalArc {
} = self;
// If the end points are identical, omit the arc segment entirely.
if x1.approx_eq_cairo(&x2) && y1.approx_eq_cairo(&y2) {
if x1.approx_eq_cairo(x2) && y1.approx_eq_cairo(y2) {
return ArcParameterization::Omit;
}
......
......@@ -308,7 +308,7 @@ impl PaintSource for NodePattern {
draw_ctx.get_view_params()
};
if !scwscale.approx_eq_cairo(&1.0) || !schscale.approx_eq_cairo(&1.0) {
if !scwscale.approx_eq_cairo(1.0) || !schscale.approx_eq_cairo(1.0) {
let mut scalematrix = cairo::Matrix::identity();
scalematrix.scale(scwscale, schscale);
caffine = cairo::Matrix::multiply(&caffine, &scalematrix);
......
......@@ -22,7 +22,7 @@ impl RectangleExt for cairo::Rectangle {
}
fn is_empty(&self) -> bool {
self.width.approx_eq_cairo(&0.0) || self.height.approx_eq_cairo(&0.0)
self.width.approx_eq_cairo(0.0) || self.height.approx_eq_cairo(0.0)
}
fn intersect(&self, rect: &cairo::Rectangle) -> cairo::Rectangle {
......
......@@ -352,7 +352,7 @@ impl NodeTrait for NodeUse {
// width or height set to 0 disables rendering of the element
// https://www.w3.org/TR/SVG/struct.html#UseElementWidthAttribute
if nw.approx_eq_cairo(&0.0) || nh.approx_eq_cairo(&0.0) {
if nw.approx_eq_cairo(0.0) || nh.approx_eq_cairo(0.0) {
return Ok(());
}
......
......@@ -291,7 +291,7 @@ impl PositionedSpan {
cr.move_to(self.rendered_position.0, self.rendered_position.1);
let rotation = unsafe { pango_sys::pango_gravity_to_rotation(gravity.to_glib()) };
if !rotation.approx_eq_cairo(&0.0) {
if !rotation.approx_eq_cairo(0.0) {
cr.rotate(-rotation);
}
......
......@@ -255,12 +255,12 @@ mod tests {
fn assert_matrix_eq(a: &cairo::Matrix, b: &cairo::Matrix) {
let epsilon = 8.0 * f64::EPSILON; // kind of arbitrary, but allow for some sloppiness
assert!(a.xx.approx_eq(&b.xx, epsilon, 1));
assert!(a.yx.approx_eq(&b.yx, epsilon, 1));
assert!(a.xy.approx_eq(&b.xy, epsilon, 1));
assert!(a.yy.approx_eq(&b.yy, epsilon, 1));
assert!(a.x0.approx_eq(&b.x0, epsilon, 1));
assert!(a.y0.approx_eq(&b.y0, epsilon, 1));
assert!(a.xx.approx_eq(b.xx, (epsilon, 1)));
assert!(a.yx.approx_eq(b.yx, (epsilon, 1)));
assert!(a.xy.approx_eq(b.xy, (epsilon, 1)));
assert!(a.yy.approx_eq(b.yy, (epsilon, 1)));
assert!(a.x0.approx_eq(b.x0, (epsilon, 1)));
assert!(a.y0.approx_eq(b.y0, (epsilon, 1)));
}
#[test]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment