diff --git a/Cargo.toml b/Cargo.toml index b896d4b..5c1a53b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui-gizmo" -version = "0.15.0" +version = "0.16.0" authors = ["Urho Laukkarinen "] edition = "2021" @@ -17,7 +17,7 @@ exclude = ["/docs"] members = ["demo"] [dependencies] -egui = "0.25.0" +egui = "0.26" glam = { version = "0.25.0", features = ["mint"] } mint = "0.5" @@ -176,4 +176,6 @@ undocumented_unsafe_blocks = "allow" unwrap_used = "allow" wildcard_imports = "allow" large-types-passed-by-value = "allow" -needless-pass-by-value = "allow" \ No newline at end of file +needless-pass-by-value = "allow" +needless_pass_by_ref_mut = "allow" +redundant_pub_crate = "allow" \ No newline at end of file diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 7d34fc9..5f96a92 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" license = "MIT" [dependencies] -egui = "0.25" +bevy_egui_next = "0.26" +egui = "0.26" egui-gizmo = { path = ".." } [dependencies.bevy] @@ -17,10 +18,6 @@ version = "0.12.1" version = "0.12.1" features = ["mint"] -[dependencies.bevy_egui] -git = "https://github.com/urholaukkarinen/bevy_egui.git" -rev="bc3dd1559e24ca0178ed1d2dfef07cb784437505" - [dependencies.bevy_infinite_grid] git = "https://github.com/pcwalton/bevy_infinite_grid.git" rev = "c752a23063b2b05163e307889eb276d6574115ab" diff --git a/demo/src/main.rs b/demo/src/main.rs index 780b98c..1cc7e11 100644 --- a/demo/src/main.rs +++ b/demo/src/main.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; use bevy::render::texture::{CompressedImageFormats, ImageFormat, ImageSampler, ImageType}; use bevy::window::PresentMode; -use bevy_egui::{egui, EguiContexts, EguiPlugin}; +use bevy_egui_next::{egui, EguiContexts, EguiPlugin}; use bevy_infinite_grid::{InfiniteGridBundle, InfiniteGridPlugin, InfiniteGridSettings}; use egui::color_picker::Alpha; use egui::{pos2, Align2, Color32, FontId, LayerId, Ui, Widget}; diff --git a/src/lib.rs b/src/lib.rs index 939ad51..62a8ed1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,49 +83,49 @@ impl Gizmo { } /// Bounds of the viewport in pixels - pub fn viewport(mut self, viewport: Rect) -> Self { + pub const fn viewport(mut self, viewport: Rect) -> Self { self.config.viewport = viewport; self } /// Gizmo mode to use - pub fn mode(mut self, mode: GizmoMode) -> Self { + pub const fn mode(mut self, mode: GizmoMode) -> Self { self.config.mode = mode; self } /// Gizmo orientation to use - pub fn orientation(mut self, orientation: GizmoOrientation) -> Self { + pub const fn orientation(mut self, orientation: GizmoOrientation) -> Self { self.config.orientation = orientation; self } /// Whether snapping is enabled - pub fn snapping(mut self, snapping: bool) -> Self { + pub const fn snapping(mut self, snapping: bool) -> Self { self.config.snapping = snapping; self } /// Snap angle to use for rotation when snapping is enabled - pub fn snap_angle(mut self, snap_angle: f32) -> Self { + pub const fn snap_angle(mut self, snap_angle: f32) -> Self { self.config.snap_angle = snap_angle; self } /// Snap distance to use for translation when snapping is enabled - pub fn snap_distance(mut self, snap_distance: f32) -> Self { + pub const fn snap_distance(mut self, snap_distance: f32) -> Self { self.config.snap_distance = snap_distance; self } /// Snap distance to use for scaling when snapping is enabled - pub fn snap_scale(mut self, snap_scale: f32) -> Self { + pub const fn snap_scale(mut self, snap_scale: f32) -> Self { self.config.snap_scale = snap_scale; self } /// Visual configuration of the gizmo, such as colors and size - pub fn visuals(mut self, visuals: GizmoVisuals) -> Self { + pub const fn visuals(mut self, visuals: GizmoVisuals) -> Self { self.config.visuals = visuals; self } diff --git a/src/math.rs b/src/math.rs index 3a61989..84b900c 100644 --- a/src/math.rs +++ b/src/math.rs @@ -59,7 +59,7 @@ pub fn segment_to_segment(a1: DVec3, a2: DVec3, b1: DVec3, b2: DVec3) -> (f64, f let d1 = a1 - b1; let d = da.dot(d1); let e = db.dot(d1); - let n = la * lb - dd * dd; + let n = la.mul_add(lb, -dd * dd); let mut sn; let mut tn; @@ -72,8 +72,8 @@ pub fn segment_to_segment(a1: DVec3, a2: DVec3, b1: DVec3, b2: DVec3) -> (f64, f tn = e; td = lb; } else { - sn = dd * e - lb * d; - tn = la * e - dd * d; + sn = dd.mul_add(e, -lb * d); + tn = la.mul_add(e, -dd * d); if sn < 0.0 { sn = 0.0; tn = e; @@ -176,8 +176,8 @@ pub fn world_to_screen(viewport: Rect, mvp: DMat4, pos: DVec3) -> Option { /// Calculates 3d world coordinates from 2d screen coordinates pub fn screen_to_world(viewport: Rect, mat: DMat4, pos: Pos2, z: f64) -> DVec3 { - let x = (((pos.x - viewport.min.x) / viewport.width()) * 2.0 - 1.0) as f64; - let y = (((pos.y - viewport.min.y) / viewport.height()) * 2.0 - 1.0) as f64; + let x = ((pos.x - viewport.min.x) / viewport.width()).mul_add(2.0, -1.0) as f64; + let y = ((pos.y - viewport.min.y) / viewport.height()).mul_add(2.0, -1.0) as f64; let mut world_pos = mat * DVec4::new(x, -y, z, 1.0); diff --git a/src/painter.rs b/src/painter.rs index 019c057..df4dda2 100644 --- a/src/painter.rs +++ b/src/painter.rs @@ -15,7 +15,7 @@ pub struct Painter3d { } impl Painter3d { - pub fn new(painter: egui::Painter, mvp: DMat4, viewport: Rect) -> Self { + pub const fn new(painter: egui::Painter, mvp: DMat4, viewport: Rect) -> Self { Self { painter, mvp, diff --git a/src/subgizmo/common.rs b/src/subgizmo/common.rs index 863bb23..5255a0e 100644 --- a/src/subgizmo/common.rs +++ b/src/subgizmo/common.rs @@ -32,8 +32,8 @@ pub(crate) fn pick_arrow( let width = (subgizmo.config.scale_factor * subgizmo.config.visuals.stroke_width) as f64; let dir = gizmo_normal(&subgizmo.config, direction); - let start = - subgizmo.config.translation + (dir * (width * 0.5 + inner_circle_radius(&subgizmo.config))); + let start = subgizmo.config.translation + + (dir * (width.mul_add(0.5, inner_circle_radius(&subgizmo.config)))); let length = (subgizmo.config.scale_factor * subgizmo.config.visuals.gizmo_size) as f64; @@ -154,7 +154,7 @@ pub(crate) fn draw_arrow( let width = (subgizmo.config.scale_factor * subgizmo.config.visuals.stroke_width) as f64; let length = (subgizmo.config.scale_factor * subgizmo.config.visuals.gizmo_size) as f64; - let start = direction * (width * 0.5 + inner_circle_radius(&subgizmo.config)); + let start = direction * width.mul_add(0.5, inner_circle_radius(&subgizmo.config)); let end = direction * length; painter.line_segment(start, end, (subgizmo.config.visuals.stroke_width, color)); @@ -257,7 +257,7 @@ pub(crate) fn draw_circle( } } -pub(crate) fn plane_bitangent(direction: GizmoDirection) -> DVec3 { +pub(crate) const fn plane_bitangent(direction: GizmoDirection) -> DVec3 { match direction { GizmoDirection::X => DVec3::Y, GizmoDirection::Y => DVec3::Z, @@ -266,7 +266,7 @@ pub(crate) fn plane_bitangent(direction: GizmoDirection) -> DVec3 { } } -pub(crate) fn plane_tangent(direction: GizmoDirection) -> DVec3 { +pub(crate) const fn plane_tangent(direction: GizmoDirection) -> DVec3 { match direction { GizmoDirection::X => DVec3::Z, GizmoDirection::Y => DVec3::X, @@ -276,8 +276,11 @@ pub(crate) fn plane_tangent(direction: GizmoDirection) -> DVec3 { } pub(crate) fn plane_size(config: &GizmoConfig) -> f64 { - (config.scale_factor * (config.visuals.gizmo_size * 0.1 + config.visuals.stroke_width * 2.0)) - as f64 + (config.scale_factor + * config + .visuals + .gizmo_size + .mul_add(0.1, config.visuals.stroke_width * 2.0)) as f64 } pub(crate) fn plane_local_origin(config: &GizmoConfig, direction: GizmoDirection) -> DVec3 { diff --git a/src/subgizmo/rotation.rs b/src/subgizmo/rotation.rs index f55d141..00d3db7 100644 --- a/src/subgizmo/rotation.rs +++ b/src/subgizmo/rotation.rs @@ -159,7 +159,7 @@ impl SubGizmo for RotationSubGizmo { if config.snapping { let stroke_width = stroke.0 / 2.0; for i in 0..((TAU / config.snap_angle as f64) as usize + 1) { - let angle = i as f64 * config.snap_angle as f64 + end_angle; + let angle = (i as f64).mul_add(config.snap_angle as f64, end_angle); let pos = DVec3::new(angle.cos(), 0.0, angle.sin()); painter.line_segment( pos * radius * 1.1, @@ -182,8 +182,8 @@ fn arc_angle(subgizmo: &SubGizmoConfig) -> f64 { let min_dot = 0.990; let max_dot = 0.995; - let mut angle = - f64::min(1.0, f64::max(0.0, dot - min_dot) / (max_dot - min_dot)) * FRAC_PI_2 + FRAC_PI_2; + let mut angle = f64::min(1.0, f64::max(0.0, dot - min_dot) / (max_dot - min_dot)) + .mul_add(FRAC_PI_2, FRAC_PI_2); if (angle - PI).abs() < 1e-2 { angle = PI; }