diff --git a/crates/egui/src/layout.rs b/crates/egui/src/layout.rs index c97652e8d..15152f47b 100644 --- a/crates/egui/src/layout.rs +++ b/crates/egui/src/layout.rs @@ -1,4 +1,4 @@ -use emath::GuiRounding as _; +use emath::{GuiRounding as _, fast_midpoint}; use crate::{ Align, Direction, @@ -477,12 +477,12 @@ impl Layout { // Make sure it isn't negative: if avail.max.x < avail.min.x { - let x = 0.5 * (avail.min.x + avail.max.x); + let x = fast_midpoint(avail.min.x, avail.max.x); avail.min.x = x; avail.max.x = x; } if avail.max.y < avail.min.y { - let y = 0.5 * (avail.min.y + avail.max.y); + let y = fast_midpoint(avail.min.y, avail.max.y); avail.min.y = y; avail.max.y = y; } diff --git a/crates/egui_demo_lib/src/demo/misc_demo_window.rs b/crates/egui_demo_lib/src/demo/misc_demo_window.rs index d035f5186..6b9584dd2 100644 --- a/crates/egui_demo_lib/src/demo/misc_demo_window.rs +++ b/crates/egui_demo_lib/src/demo/misc_demo_window.rs @@ -143,9 +143,7 @@ impl View for MiscDemoWindow { ) .changed() { - for check in &mut self.checklist { - *check = all_checked; - } + self.checklist.fill(all_checked); } for (i, checked) in self.checklist.iter_mut().enumerate() { ui.checkbox(checked, format!("Item {}", i + 1)); diff --git a/crates/emath/src/easing.rs b/crates/emath/src/easing.rs index 95fc7250d..6a98cad80 100644 --- a/crates/emath/src/easing.rs +++ b/crates/emath/src/easing.rs @@ -7,6 +7,8 @@ //! Derived from . use std::f32::consts::PI; +use crate::fast_midpoint; + #[inline] fn powf(base: f32, exp: f32) -> f32 { base.powf(exp) @@ -116,7 +118,7 @@ pub fn circular_in_out(t: f32) -> f32 { if t < 0.5 { 0.5 * (1. - (1. - 4. * t * t).sqrt()) } else { - 0.5 * ((-(2. * t - 3.) * (2. * t - 1.)).sqrt() + 1.) + fast_midpoint((-(2. * t - 3.) * (2. * t - 1.)).sqrt(), 1.) } } diff --git a/crates/emath/src/range.rs b/crates/emath/src/range.rs index 26d5f6f2c..be6072c71 100644 --- a/crates/emath/src/range.rs +++ b/crates/emath/src/range.rs @@ -1,5 +1,7 @@ use std::ops::{RangeFrom, RangeFull, RangeInclusive, RangeToInclusive}; +use crate::fast_midpoint; + /// Inclusive range of floats, i.e. `min..=max`, but more ergonomic than [`RangeInclusive`]. #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq)] @@ -52,7 +54,7 @@ impl Rangef { /// The center of the range #[inline] pub fn center(self) -> f32 { - 0.5 * (self.min + self.max) + fast_midpoint(self.min, self.max) } #[inline] diff --git a/crates/epaint/src/shapes/bezier_shape.rs b/crates/epaint/src/shapes/bezier_shape.rs index dfeaae5ec..b8c78f273 100644 --- a/crates/epaint/src/shapes/bezier_shape.rs +++ b/crates/epaint/src/shapes/bezier_shape.rs @@ -3,7 +3,7 @@ use std::ops::Range; use crate::{Color32, PathShape, PathStroke, Shape}; -use emath::{Pos2, Rect, RectTransform}; +use emath::{Pos2, Rect, RectTransform, fast_midpoint}; // ---------------------------------------------------------------------------- @@ -689,8 +689,8 @@ fn single_curve_approximation(curve: &CubicBezierShape) -> QuadraticBezierShape let c2_x = (curve.points[2].x * 3.0 - curve.points[3].x) * 0.5; let c2_y = (curve.points[2].y * 3.0 - curve.points[3].y) * 0.5; let c = Pos2 { - x: (c1_x + c2_x) * 0.5, - y: (c1_y + c2_y) * 0.5, + x: fast_midpoint(c1_x, c2_x), + y: fast_midpoint(c1_y, c2_y), }; QuadraticBezierShape { points: [curve.points[0], c, curve.points[3]], diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index 9a90636a4..716fe5424 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -5,7 +5,9 @@ #![expect(clippy::identity_op)] -use emath::{GuiRounding as _, NumExt as _, Pos2, Rect, Rot2, Vec2, pos2, remap, vec2}; +use emath::{ + GuiRounding as _, NumExt as _, Pos2, Rect, Rot2, Vec2, fast_midpoint, pos2, remap, vec2, +}; use crate::{ CircleShape, ClippedPrimitive, ClippedShape, Color32, CornerRadiusF32, CubicBezierShape, @@ -1074,7 +1076,7 @@ fn stroke_and_fill_path( */ let inner_rad = 0.5 * (stroke.width - feathering); - let outer_rad = 0.5 * (stroke.width + feathering); + let outer_rad = fast_midpoint(stroke.width, feathering); match path_type { PathType::Closed => {