music21/graph/mod.rs
1//! Graphs of a score's data: music21's `graph`, the data side.
2//!
3//! What a plot shows is worked out here: the ticks and labels of an axis
4//! ([`axis`]), the plot a format and a list of quantities ask for
5//! ([`find`]), the layout numbers a graph primitive draws with
6//! ([`primitives`]), and colours and accidentals as matplotlib takes them
7//! ([`utilities`]). Drawing is matplotlib's, and is the wheel's to drive.
8
9pub mod axis;
10pub mod find;
11pub mod primitives;
12pub mod utilities;
13
14/// Python's `range(start, stop, step)`, which the tick rules count with.
15///
16/// ```
17/// use music21::graph::py_range;
18///
19/// assert_eq!(py_range(0, 10, 4), vec![0, 4, 8]);
20/// assert_eq!(py_range(5, 0, -2), vec![5, 3, 1]);
21/// assert!(py_range(0, 10, -1).is_empty());
22/// ```
23///
24/// # Panics
25///
26/// Never; a step of nought gives nothing, where Python raises.
27pub fn py_range(start: i64, stop: i64, step: i64) -> Vec<i64> {
28 let mut out = Vec::new();
29 if step == 0 {
30 return out;
31 }
32 let mut value = start;
33 while (step > 0 && value < stop) || (step < 0 && value > stop) {
34 out.push(value);
35 value += step;
36 }
37 out
38}