Skip to content

Commit

Permalink
[rem] Removed trait ApproxF32
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-lua committed Mar 10, 2024
1 parent d1787a5 commit 434cd2e
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions crates/bevy_dev_tools/src/debug_overlay/inset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ use bevy_utils::HashMap;

use super::{CameraQuery, LayoutRect};

trait ApproxF32 {
fn is(self, other: f32) -> bool;
}
impl ApproxF32 for f32 {
fn is(self, other: f32) -> bool {
let diff = (self - other).abs();
diff < 0.001
}
// Function used here so we don't need to redraw lines that are fairly close to each other.
fn approx_eq(compared: f32, other: f32) -> bool {
(compared - other).abs() < 0.001
}

fn rect_border_axis(rect: LayoutRect) -> (f32, f32, f32, f32) {
Expand Down Expand Up @@ -148,10 +143,10 @@ impl<'w, 's> InsetGizmo<'w, 's> {
position.xy()
}
fn line_2d(&mut self, mut start: Vec2, mut end: Vec2, color: Color) {
if start.x.is(end.x) {
if approx_eq(start.x, end.x) {
start.x = self.known_x.inset(start.x);
end.x = start.x;
} else if start.y.is(end.y) {
} else if approx_eq(start.y, end.y) {
start.y = self.known_y.inset(start.y);
end.y = start.y;
}
Expand All @@ -174,9 +169,9 @@ impl<'w, 's> InsetGizmo<'w, 's> {
}
pub(super) fn rect_2d(&mut self, rect: LayoutRect, color: Color) {
let (left, right, top, bottom) = rect_border_axis(rect);
if left.is(right) {
if approx_eq(left, right) {
self.line_2d(Vec2::new(left, top), Vec2::new(left, bottom), color);
} else if top.is(bottom) {
} else if approx_eq(top, bottom) {
self.line_2d(Vec2::new(left, top), Vec2::new(right, top), color);
} else {
let inset_x = |v| self.known_x.inset(v);
Expand Down

0 comments on commit 434cd2e

Please sign in to comment.