Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Fix impl PartialOrd for Fraction being totally wrong.
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed Dec 21, 2019
1 parent 9b09d9a commit b5a8bb5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 37,5 @@ categories = ["data-structures", "encoding", "parser-implementations"]
muon-rs = "0.2"
serde = "1.0"
serde_derive = "1.0"
cala = { version = "0.7", default-features = false, features = [] }
# devout = "0.0"
10 changes: 3 additions & 7 deletions src/fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 130,10 @@ impl PartialEq for Fraction {

impl PartialOrd for Fraction {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let den = gcd_i(self.den, other.den);
let self_int = self.num as i32 * other.den as i32;
let other_int = other.num as i32 * self.den as i32;

let self_mul = (den / self.den) as i32;
let other_mul = (den / other.den) as i32;

let num = self.num as i32 * self_mul - other.num as i32 * other_mul;

num.partial_cmp(&0)
(self_int-other_int).partial_cmp(&0)
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,8 @@ use muon_rs as muon;
use serde_derive::{Deserialize, Serialize};
use std::str::FromStr;

use cala;

pub mod note;
mod fraction;

Expand Down Expand Up @@ -549,18 551,23 @@ impl Scof {
pub fn set_duration(&mut self, cursor: &Cursor, dur: Fraction) {
let mut note = self.note(cursor).unwrap();
let old = note.duration;
cala::info!("AAAA1");
note.set_duration(dur);
cala::info!("AAAA2");
if old > dur {
cala::info!("Shorter {} - {}", old, dur);
// FIXME: Note is becoming shorter.
let _rests = old - dur;


} else {
cala::info!("Longer {} - {}", dur, old);
// FIXME: Note is becoming longer.
let _tied_value = dur - old;


}
cala::info!("AAAA3");
let m = self.marking_str_mut(cursor).unwrap();
*m = note.to_string();
}
Expand Down

0 comments on commit b5a8bb5

Please sign in to comment.