From 442b876cb5feb6ce893fb98650904ce42c87a60f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 27 Dec 2020 11:24:08 +0100 Subject: [PATCH] Remove math::TAU and use std::f32::consts::TAU instead --- egui/src/containers/collapsing_header.rs | 1 + egui/src/demos/dancing_strings.rs | 2 +- egui/src/demos/demo_window.rs | 1 + egui/src/demos/fractal_clock.rs | 1 + egui/src/demos/widgets.rs | 2 +- egui/src/math/mod.rs | 7 ------- egui/src/paint/tessellator.rs | 1 + egui/src/painter.rs | 2 +- 8 files changed, 7 insertions(+), 10 deletions(-) diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index 0479acab..e8effc5e 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -109,6 +109,7 @@ pub fn paint_icon(ui: &mut Ui, openness: f32, response: &Response) { // Draw a pointy triangle arrow: let rect = Rect::from_center_size(rect.center(), vec2(rect.width(), rect.height()) * 0.75); let mut points = vec![rect.left_top(), rect.right_top(), rect.center_bottom()]; + use std::f32::consts::TAU; let rotation = Rot2::from_angle(remap(openness, 0.0..=1.0, -TAU / 4.0..=0.0)); for p in &mut points { *p = rect.center() + rotation * (*p - rect.center()); diff --git a/egui/src/demos/dancing_strings.rs b/egui/src/demos/dancing_strings.rs index 21a9fdd2..6928e1c5 100644 --- a/egui/src/demos/dancing_strings.rs +++ b/egui/src/demos/dancing_strings.rs @@ -44,7 +44,7 @@ impl View for DancingStrings { .map(|i| { let t = i as f32 / (n as f32); let amp = (time as f32 * speed * mode).sin() / mode; - let y = amp * (t * math::TAU / 2.0 * mode).sin(); + let y = amp * (t * std::f32::consts::TAU / 2.0 * mode).sin(); pos2( lerp(rect.x_range(), t), diff --git a/egui/src/demos/demo_window.rs b/egui/src/demos/demo_window.rs index e7611977..5ab08f5a 100644 --- a/egui/src/demos/demo_window.rs +++ b/egui/src/demos/demo_window.rs @@ -87,6 +87,7 @@ impl DemoWindow { .show(ui, |ui| { ui.horizontal(|ui| { ui.label("You can pretty easily paint your own small icons:"); + use std::f32::consts::TAU; let response = ui.allocate_response(Vec2::splat(16.0), Sense::hover()); let painter = ui.painter(); let c = response.rect.center(); diff --git a/egui/src/demos/fractal_clock.rs b/egui/src/demos/fractal_clock.rs index a170d401..bb4f3cb3 100644 --- a/egui/src/demos/fractal_clock.rs +++ b/egui/src/demos/fractal_clock.rs @@ -1,4 +1,5 @@ use crate::{containers::*, widgets::*, *}; +use std::f32::consts::TAU; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] diff --git a/egui/src/demos/widgets.rs b/egui/src/demos/widgets.rs index 08fc98cc..25f7281c 100644 --- a/egui/src/demos/widgets.rs +++ b/egui/src/demos/widgets.rs @@ -35,7 +35,7 @@ impl Default for Widgets { radio: Enum::First, count: 0, sliders: Default::default(), - angle: TAU / 3.0, + angle: std::f32::consts::TAU / 3.0, color: (Rgba::new(0.0, 1.0, 0.5, 1.0) * 0.75).into(), single_line_text_input: "Hello World!".to_owned(), multiline_text_input: "Text can both be so wide that it needs a line break, but you can also add manual line break by pressing enter, creating new paragraphs.\nThis is the start of the next paragraph.\n\nClick me to edit me!".to_owned(), diff --git a/egui/src/math/mod.rs b/egui/src/math/mod.rs index dbb5d218..e9a3663b 100644 --- a/egui/src/math/mod.rs +++ b/egui/src/math/mod.rs @@ -114,13 +114,6 @@ pub fn ease_in_ease_out(t: f32) -> f32 { 3.0 * t * t - 2.0 * t * t * t } -/// The circumference of a circle divided by its radius. -/// -/// Represents one turn in radian angles. Equal to `2 * pi`. -/// -/// See -pub const TAU: f32 = 2.0 * std::f32::consts::PI; - /// Round a value to the given number of decimal places. pub fn round_to_decimals(value: f64, decimal_places: usize) -> f64 { // This is a stupid way of doing this, but stupid works. diff --git a/egui/src/paint/tessellator.rs b/egui/src/paint/tessellator.rs index 7cc73c2b..58f0d46f 100644 --- a/egui/src/paint/tessellator.rs +++ b/egui/src/paint/tessellator.rs @@ -12,6 +12,7 @@ use { PaintCmd, Stroke, }, crate::math::*, + std::f32::consts::TAU, }; /// What texture to use in a `Triangles` mesh. diff --git a/egui/src/painter.rs b/egui/src/painter.rs index f5e88783..58eb1fb6 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -232,7 +232,7 @@ impl Painter { /// Show an arrow starting at `origin` and going in the direction of `vec`, with the length `vec.length()`. pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: Stroke) { use crate::math::*; - let rot = Rot2::from_angle(TAU / 10.0); + let rot = Rot2::from_angle(std::f32::consts::TAU / 10.0); let tip_length = vec.length() / 4.0; let tip = origin + vec; let dir = vec.normalized();