Skip to content

Commit 9c2601d

Browse files
committed
replaced fraction with num
1 parent e8a4a5b commit 9c2601d

File tree

5 files changed

+39
-46
lines changed

5 files changed

+39
-46
lines changed

Cargo.lock

+13-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ egui_dock = "0.12"
5757
egui_extras = { version = "*", features = ["all_loaders"] }
5858
image = { version = "0.24", features = ["jpeg", "png"] }
5959

60-
fraction = "0.15.1"
61-
6260
serde = { version = "1.0.197", features = ["derive"] }
6361
serde_json = "1.0.114"
6462
serde_repr = "0.1"
6563

6664
iyes_perf_ui = "0.2.3"
6765
bevy-inspector-egui = "0.24.0"
6866
url = "2.5.0"
67+
num = "0.4.3"

src/chart/beat.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
1-
use fraction::prelude::*;
1+
use num::{Rational32, FromPrimitive};
22

33
#[derive(Clone, Copy, Debug)]
4-
pub struct Beat(pub Fraction);
4+
pub struct Beat(pub Rational32);
55

66
impl Into<f32> for Beat {
77
fn into(self) -> f32 {
8-
self.0.try_into().unwrap()
8+
*self.0.numer() as f32 / *self.0.denom() as f32
99
}
1010
}
1111

12-
impl Into<Fraction> for Beat {
13-
fn into(self) -> Fraction {
12+
impl Into<Rational32> for Beat {
13+
fn into(self) -> Rational32 {
1414
self.0
1515
}
1616
}
1717

18-
impl<T> From<T> for Beat where Fraction: From<T> {
19-
fn from(value: T) -> Self {
20-
Self(Fraction::from(value))
18+
impl From<f32> for Beat {
19+
fn from(value: f32) -> Self {
20+
Self(Rational32::from_f32(value).unwrap())
21+
}
22+
}
23+
24+
impl From<Rational32> for Beat {
25+
fn from(value: Rational32) -> Self {
26+
Self(value)
2127
}
2228
}
2329

2430
impl Beat {
25-
pub fn beat(&self) -> u32 {
26-
self.0.trunc().try_into().unwrap()
31+
pub fn beat(&self) -> i32 {
32+
*self.0.trunc().numer()
2733
}
2834

29-
pub fn numer(&self) -> u32 {
30-
*self.0.fract().numer().unwrap() as u32
35+
pub fn numer(&self) -> i32 {
36+
*self.0.fract().numer()
3137
}
3238

33-
pub fn denom(&self) -> u32 {
34-
*self.0.fract().denom().unwrap() as u32
39+
pub fn denom(&self) -> i32 {
40+
*self.0.fract().denom()
3541
}
3642

3743
pub fn value(&self) -> f32 {

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use bevy_mod_picking::prelude::*;
3838
use chart::beat::Beat;
3939
use chart::line::{LineOpacity, LinePosition, LineRotation};
4040
use egui_dock::{DockArea, DockState, NodeIndex, Style};
41-
use fraction::prelude::*;
41+
use num::{Rational32, FromPrimitive};
4242

4343
fn main() {
4444
App::new()
@@ -337,7 +337,7 @@ fn compute_line_system(
337337
let beat = time.0 / (60.0 / 174.0);
338338
for (mut position, mut rotation, mut opacity, entity) in &mut line_query {
339339
let mut events: Vec<_> = event_query.iter().filter(|e| e.line_id == entity).collect();
340-
events.sort_by_key(|e| <Beat as Into<Fraction>>::into(e.start_beat));
340+
events.sort_by_key(|e| <Beat as Into<Rational32>>::into(e.start_beat));
341341
for event in events {
342342
let value = event.evaluate(beat);
343343
if let Some(value) = value {
@@ -396,7 +396,7 @@ fn update_note_y_system(
396396
.map(|(s, _)| *s)
397397
.collect();
398398
speed_events
399-
.sort_by(|a, b| Fraction::from(a.start_time).cmp(&Fraction::from(b.start_time)));
399+
.sort_by(|a, b| Rational32::from_f32(a.start_time).cmp(&Rational32::from_f32(b.start_time)));
400400

401401
let distance = |time| {
402402
distance_at(&speed_events, time) * (game_viewport.0.height() * (120.0 / 900.0))

src/tab/inspector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::prelude::*;
22
use egui::Ui;
3-
use fraction::Fraction;
3+
use num::Rational32;
44

55
use crate::{chart::{beat::Beat, note::Note}, selection::Selected};
66

@@ -18,7 +18,7 @@ pub fn inspector_ui_system(In(ui): In<&mut Ui>, mut selected_notes: Query<&mut N
1818
ui.add(egui::DragValue::new(&mut denom).clamp_range(1..=u32::MAX).speed(1));
1919

2020
if beat != selected_note.beat.beat() || numer != selected_note.beat.numer() || denom != selected_note.beat.denom() {
21-
selected_note.beat = Beat::from(Fraction::new(beat * denom + numer, denom));
21+
selected_note.beat = Beat::from(Rational32::new_raw(beat * denom + numer, denom));
2222
}
2323
});
2424
}

0 commit comments

Comments
 (0)