made control point types pub
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
## Upcoming
|
||||
|
||||
Nothing as of now
|
||||
- __Additions__:
|
||||
- Added the `ControlPoint` and `ControlPointerIter` types to the public interface, aswell as the `Beatmap::control_points` method
|
||||
|
||||
# v0.5.2 (2022-06-14)
|
||||
|
||||
|
||||
@@ -5,8 +5,9 @@ use crate::{
|
||||
|
||||
use std::{iter::Copied, slice::Iter};
|
||||
|
||||
/// Iterator for a [`Beatmap`]'s timing- and difficulty points sorted by timestamp
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ControlPointIter<'p> {
|
||||
pub struct ControlPointIter<'p> {
|
||||
timing_points: Copied<Iter<'p, TimingPoint>>,
|
||||
difficulty_points: Copied<Iter<'p, DifficultyPoint>>,
|
||||
|
||||
@@ -30,15 +31,19 @@ impl<'p> ControlPointIter<'p> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Control point for a [`Beatmap`].
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) enum ControlPoint {
|
||||
pub enum ControlPoint {
|
||||
/// A timing point containing the current beat length.
|
||||
Timing(TimingPoint),
|
||||
/// A difficulty point containing the current speed multiplier.
|
||||
Difficulty(DifficultyPoint),
|
||||
}
|
||||
|
||||
impl ControlPoint {
|
||||
/// Provides the timestamp of the control point.
|
||||
#[inline]
|
||||
pub(crate) fn time(&self) -> f64 {
|
||||
pub fn time(&self) -> f64 {
|
||||
match self {
|
||||
Self::Timing(point) => point.time,
|
||||
Self::Difficulty(point) => point.time,
|
||||
@@ -49,6 +54,7 @@ impl ControlPoint {
|
||||
impl<'p> Iterator for ControlPointIter<'p> {
|
||||
type Item = ControlPoint;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match (self.next_timing, self.next_difficulty) {
|
||||
(Some(timing), Some(difficulty)) if timing.time <= difficulty.time => {
|
||||
|
||||
+2
-3
@@ -206,9 +206,8 @@ pub use stars::AnyStars;
|
||||
mod curve;
|
||||
mod mods;
|
||||
|
||||
pub(crate) mod control_point_iter;
|
||||
|
||||
pub(crate) use control_point_iter::{ControlPoint, ControlPointIter};
|
||||
mod control_point_iter;
|
||||
pub use control_point_iter::{ControlPoint, ControlPointIter};
|
||||
|
||||
pub use catch::{CatchPP, CatchStars};
|
||||
pub use mania::{ManiaPP, ManiaStars};
|
||||
|
||||
@@ -32,6 +32,8 @@ use std::path::Path;
|
||||
#[cfg(feature = "async_std")]
|
||||
use async_std::{fs::File, io::Read as AsyncRead, path::Path};
|
||||
|
||||
use crate::control_point_iter::ControlPointIter;
|
||||
|
||||
fn sort_unstable<T: PartialOrd>(slice: &mut [T]) {
|
||||
slice.sort_unstable_by(|p1, p2| p1.partial_cmp(p2).unwrap_or(Ordering::Equal));
|
||||
}
|
||||
@@ -681,6 +683,12 @@ impl Beatmap {
|
||||
None => 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an iterator over the map's timing- and difficulty points sorted by timestamp.
|
||||
#[inline]
|
||||
pub fn control_points(&self) -> ControlPointIter<'_> {
|
||||
ControlPointIter::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
mod slider_parsing {
|
||||
|
||||
Reference in New Issue
Block a user