···2727impl DistributionType {
2828 #[deprecated(note = "Experimental. Does not consider random or limit in filter calculations.")]
2929 #[allow(deprecated)]
3030- fn compute_offset(
3030+ fn compute_beat_offset(
3131+ &self,
3232+ light_id: i32,
3333+ group_size: i32,
3434+ filter: &Filter,
3535+ dist_value: f32,
3636+ last_data_offset: Option<f32>,
3737+ easing: Option<Easing>,
3838+ ) -> f32 {
3939+ let filtered_id = filter.get_relative_index(light_id, group_size);
4040+4141+ let filtered_size = if let Some(limit_behaviour) = filter.limit_behaviour
4242+ && limit_behaviour.duration()
4343+ {
4444+ filter.count_filtered(group_size)
4545+ } else {
4646+ filter.count_filtered_without_limit(group_size)
4747+ };
4848+4949+ self.compute_offset(
5050+ filtered_id,
5151+ filtered_size,
5252+ dist_value,
5353+ last_data_offset,
5454+ easing,
5555+ )
5656+ }
5757+5858+ #[deprecated(note = "Experimental. Does not consider random or limit in filter calculations.")]
5959+ #[allow(deprecated)]
6060+ fn compute_value_offset(
3161 &self,
3262 light_id: i32,
3363 group_size: i32,
···3666 last_data_offset: Option<f32>,
3767 easing: Option<Easing>,
3868 ) -> f32 {
6969+ let filtered_id = filter.get_relative_index(light_id, group_size);
7070+7171+ let filtered_size = if let Some(limit_behaviour) = filter.limit_behaviour
7272+ && limit_behaviour.distribution()
7373+ {
7474+ filter.count_filtered(group_size)
7575+ } else {
7676+ filter.count_filtered_without_limit(group_size)
7777+ };
7878+7979+ self.compute_offset(
8080+ filtered_id,
8181+ filtered_size,
8282+ dist_value,
8383+ last_data_offset,
8484+ easing,
8585+ )
8686+ }
8787+8888+ #[deprecated(note = "Experimental. Does not consider random or limit in filter calculations.")]
8989+ #[allow(deprecated)]
9090+ #[inline(always)]
9191+ fn compute_offset(
9292+ &self,
9393+ filtered_id: i32,
9494+ filtered_size: i32,
9595+ dist_value: f32,
9696+ last_data_offset: Option<f32>,
9797+ easing: Option<Easing>,
9898+ ) -> f32 {
9999+ let filtered_id = filtered_id as f32;
100100+ let filtered_size = filtered_size as f32;
101101+39102 if dist_value == 0.0 {
40103 return 0.0;
41104 }
4242-4343- let filtered_size = filter.count_filtered(group_size) as f32;
4444- let filtered_id = filter.get_relative_index(light_id, group_size) as f32;
4510546106 match self {
47107 DistributionType::Wave => {
···61121 DistributionType::Unknown(_) => 0.0,
62122 }
63123 }
124124+125125+ /// Tests that both [`self.compute_beat_offset`] and [`self.compute_value_offset`] have the same return value, returning that value.
126126+ ///
127127+ /// This only makes sense if the [`LimitBehaviour`] is either `None` or `Both`.
128128+ #[cfg(test)]
129129+ #[allow(deprecated)]
130130+ fn compute_both(
131131+ &self,
132132+ light_id: i32,
133133+ group_size: i32,
134134+ filter: &Filter,
135135+ dist_value: f32,
136136+ last_data_offset: Option<f32>,
137137+ easing: Option<Easing>,
138138+ ) -> f32 {
139139+ assert!(
140140+ matches!(
141141+ filter.limit_behaviour,
142142+ None | Some(LimitBehaviour::None) | Some(LimitBehaviour::Both)
143143+ ),
144144+ "This test method only makes sense if LimitBehaviour is `None` or `Both`"
145145+ );
146146+147147+ let beat = self.compute_beat_offset(
148148+ light_id,
149149+ group_size,
150150+ filter,
151151+ dist_value,
152152+ last_data_offset,
153153+ easing,
154154+ );
155155+ let value = self.compute_value_offset(
156156+ light_id,
157157+ group_size,
158158+ filter,
159159+ dist_value,
160160+ last_data_offset,
161161+ easing,
162162+ );
163163+ assert_eq!(beat, value);
164164+ beat
165165+ }
64166}
6516766168loose_enum! {
···98200 fn wave() {
99201 for i in 0..12 {
100202 assert_eq!(
101101- DistributionType::Wave.compute_offset(i, 12, &Filter::default(), 12.0, None, None),
203203+ DistributionType::Wave.compute_both(i, 12, &Filter::default(), 12.0, None, None),
102204 i as f32
103205 );
104206 }
···108210 fn step() {
109211 for i in 0..12 {
110212 assert_eq!(
111111- DistributionType::Step.compute_offset(i, 12, &Filter::default(), 1.0, None, None),
213213+ DistributionType::Step.compute_both(i, 12, &Filter::default(), 1.0, None, None),
112214 i as f32
113215 );
114216 }
···118220 fn wave_negative() {
119221 for i in 0..12 {
120222 assert_eq!(
121121- DistributionType::Wave.compute_offset(i, 12, &Filter::default(), -12.0, None, None),
223223+ DistributionType::Wave.compute_both(i, 12, &Filter::default(), -12.0, None, None),
122224 -i as f32
123225 );
124226 }
···128230 fn step_negative() {
129231 for i in 0..12 {
130232 assert_eq!(
131131- DistributionType::Step.compute_offset(i, 12, &Filter::default(), -1.0, None, None),
233233+ DistributionType::Step.compute_both(i, 12, &Filter::default(), -1.0, None, None),
132234 -i as f32
133235 );
134236 }
···138240 fn wave_zero() {
139241 for i in 0..12 {
140242 assert_eq!(
141141- DistributionType::Wave.compute_offset(i, 12, &Filter::default(), 0.0, None, None),
243243+ DistributionType::Wave.compute_both(i, 12, &Filter::default(), 0.0, None, None),
142244 0.0
143245 );
144246 }
···148250 fn step_zero() {
149251 for i in 0..12 {
150252 assert_eq!(
151151- DistributionType::Step.compute_offset(i, 12, &Filter::default(), 0.0, None, None),
253253+ DistributionType::Step.compute_both(i, 12, &Filter::default(), 0.0, None, None),
152254 0.0
153255 );
154256 }
···158260 fn wave_with_division_filter() {
159261 for i in 0..6 {
160262 assert_eq!(
161161- DistributionType::Wave.compute_offset(
263263+ DistributionType::Wave.compute_both(
162264 i + 6,
163265 12,
164266 &Filter {
···180282 fn step_with_division_filter() {
181283 for i in 0..6 {
182284 assert_eq!(
183183- DistributionType::Step.compute_offset(
285285+ DistributionType::Step.compute_both(
184286 i + 6,
185287 12,
186288 &Filter {
···202304 fn wave_with_step_filter() {
203305 for i in 0..6 {
204306 assert_eq!(
205205- DistributionType::Wave.compute_offset(
307307+ DistributionType::Wave.compute_both(
206308 i * 2,
207309 12,
208310 &Filter {
···224326 fn step_with_step_filter() {
225327 for i in 0..6 {
226328 assert_eq!(
227227- DistributionType::Step.compute_offset(
329329+ DistributionType::Step.compute_both(
228330 i * 2,
229331 12,
230332 &Filter {
···246348 fn wave_with_reverse_filter() {
247349 for i in 0..12 {
248350 assert_eq!(
249249- DistributionType::Wave.compute_offset(
351351+ DistributionType::Wave.compute_both(
250352 i,
251353 12,
252354 &Filter {
···266368 fn step_with_reverse_filter() {
267369 for i in 0..12 {
268370 assert_eq!(
269269- DistributionType::Step.compute_offset(
371371+ DistributionType::Step.compute_both(
270372 i,
271373 12,
272374 &Filter {
···290392 ..Default::default()
291393 };
292394 assert_eq!(
293293- DistributionType::Wave.compute_offset(i * 2, 12, &filter, 6.0, None, None),
395395+ DistributionType::Wave.compute_both(i * 2, 12, &filter, 6.0, None, None),
294396 i as f32
295397 );
296398 assert_eq!(
297297- DistributionType::Wave.compute_offset(i * 2 + 1, 12, &filter, 6.0, None, None),
399399+ DistributionType::Wave.compute_both(i * 2 + 1, 12, &filter, 6.0, None, None),
298400 i as f32
299401 );
300402 }
···308410 ..Default::default()
309411 };
310412 assert_eq!(
311311- DistributionType::Step.compute_offset(i * 2, 12, &filter, 1.0, None, None),
413413+ DistributionType::Step.compute_both(i * 2, 12, &filter, 1.0, None, None),
312414 i as f32
313415 );
314416 assert_eq!(
315315- DistributionType::Step.compute_offset(i * 2 + 1, 12, &filter, 1.0, None, None),
417417+ DistributionType::Step.compute_both(i * 2 + 1, 12, &filter, 1.0, None, None),
316418 i as f32
317419 );
318420 }
···326428 ..Default::default()
327429 };
328430 assert_eq!(
329329- DistributionType::Wave.compute_offset(i, 12, &filter, 2.0, None, None),
431431+ DistributionType::Wave.compute_both(i, 12, &filter, 2.0, None, None),
330432 0.0
331433 );
332434 assert_eq!(
333333- DistributionType::Wave.compute_offset(i + 6, 12, &filter, 2.0, None, None),
435435+ DistributionType::Wave.compute_both(i + 6, 12, &filter, 2.0, None, None),
334436 1.0
335437 );
336438 }
···344446 ..Default::default()
345447 };
346448 assert_eq!(
347347- DistributionType::Step.compute_offset(i, 12, &filter, 1.0, None, None),
449449+ DistributionType::Step.compute_both(i, 12, &filter, 1.0, None, None),
348450 0.0
349451 );
350452 assert_eq!(
351351- DistributionType::Step.compute_offset(i + 6, 12, &filter, 1.0, None, None),
453453+ DistributionType::Step.compute_both(i + 6, 12, &filter, 1.0, None, None),
352454 1.0
353455 );
354456 }
···356458357459 #[test]
358460 fn wave_with_chunks_out_of_bounds() {
461461+ let filter = Filter {
462462+ chunks: Some(24),
463463+ ..Default::default()
464464+ };
465465+359466 for i in 0..12 {
360360- let filter = Filter {
361361- chunks: Some(24),
362362- ..Default::default()
363363- };
364467 assert_eq!(
365365- DistributionType::Wave.compute_offset(i, 12, &filter, 12.0, None, None),
468468+ DistributionType::Wave.compute_both(i, 12, &filter, 12.0, None, None),
366469 i as f32
367470 );
368471 }
···370473371474 #[test]
372475 fn step_with_chunks_out_of_bounds() {
476476+ let filter = Filter {
477477+ chunks: Some(24),
478478+ ..Default::default()
479479+ };
480480+373481 for i in 0..12 {
374374- let filter = Filter {
375375- chunks: Some(24),
376376- ..Default::default()
377377- };
482482+ assert_eq!(
483483+ DistributionType::Step.compute_both(i, 12, &filter, 1.0, None, None),
484484+ i as f32
485485+ );
486486+ }
487487+ }
488488+489489+ #[test]
490490+ fn wave_with_limit() {
491491+ let filter = Filter {
492492+ limit_percent: Some(0.5),
493493+ ..Default::default()
494494+ };
495495+496496+ for i in 0..6 {
497497+ assert_eq!(
498498+ DistributionType::Wave.compute_both(i, 12, &filter, 12.0, None, None),
499499+ i as f32
500500+ );
501501+ }
502502+ }
503503+504504+ #[test]
505505+ fn step_with_limit() {
506506+ let filter = Filter {
507507+ limit_percent: Some(0.5),
508508+ ..Default::default()
509509+ };
510510+511511+ for i in 0..6 {
378512 assert_eq!(
379379- DistributionType::Step.compute_offset(i, 12, &filter, 1.0, None, None),
513513+ DistributionType::Step.compute_both(i, 12, &filter, 1.0, None, None),
514514+ i as f32
515515+ );
516516+ }
517517+ }
518518+519519+ #[test]
520520+ fn wave_with_enabled_limit() {
521521+ let filter = Filter {
522522+ limit_behaviour: Some(LimitBehaviour::Both),
523523+ limit_percent: Some(0.5),
524524+ ..Default::default()
525525+ };
526526+527527+ for i in 0..6 {
528528+ assert_eq!(
529529+ DistributionType::Wave.compute_both(i, 12, &filter, 12.0, None, None),
530530+ (i * 2) as f32
531531+ );
532532+ }
533533+ }
534534+535535+ #[test]
536536+ fn step_with_enabled_limit() {
537537+ let filter = Filter {
538538+ limit_behaviour: Some(LimitBehaviour::Both),
539539+ limit_percent: Some(0.5),
540540+ ..Default::default()
541541+ };
542542+543543+ for i in 0..6 {
544544+ assert_eq!(
545545+ DistributionType::Step.compute_both(i, 12, &filter, 1.0, None, None),
380546 i as f32
381547 );
382548 }
+23-7
src/difficulty/lightshow/filter.rs
···114114 }
115115 }
116116117117- /// Returns the number of light chunks effected by the filter.
117117+ /// Returns the number of light chunks effected by the filter, but before applying the limit.
118118+ ///
119119+ /// This is required for distribution calculations.
118120 /// # Unknown
119121 /// If the [`FilterType`] is `Unknown` then the result will be the same as `group_size`.
120122 #[must_use]
121123 #[inline]
122124 #[deprecated(note = "Experimental. Does not consider random or limit in calculations.")]
123123- pub fn count_filtered(&self, mut group_size: i32) -> i32 {
125125+ pub(crate) fn count_filtered_without_limit(&self, mut group_size: i32) -> i32 {
124126 if let Some(chunks) = self.chunks
125127 && chunks > 0
126128 && chunks < group_size
···128130 group_size = chunks;
129131 }
130132131131- let mut filtered = match self.filter_type {
133133+ match self.filter_type {
132134 FilterType::Division => {
133135 let start = self.parameter2 * group_size / self.parameter1.max(1);
134136 let end = (self.parameter2 + 1) * group_size / self.parameter1.max(1);
···138140 group_size / self.parameter2.max(1) - self.parameter1 / self.parameter2.max(1)
139141 }
140142 FilterType::Unknown(_) => group_size,
141141- };
143143+ }
144144+ }
145145+146146+ /// Returns the number of light chunks effected by the filter.
147147+ /// # Unknown
148148+ /// If the [`FilterType`] is `Unknown` then the result will be the same as `group_size`.
149149+ #[must_use]
150150+ #[inline]
151151+ #[deprecated(note = "Experimental. Does not consider random or limit in calculations.")]
152152+ #[allow(deprecated)]
153153+ pub fn count_filtered(&self, group_size: i32) -> i32 {
154154+ let filtered = self.count_filtered_without_limit(group_size);
142155143156 if let Some(limit) = self.limit_percent {
144144- filtered = (filtered as f32 * limit) as i32;
157157+ (filtered as f32 * limit) as i32
158158+ } else {
159159+ filtered
145160 }
146146-147147- filtered
148161 }
149162150163 #[allow(deprecated)]
···488501 assert!((0..6).all(|i| filter.is_in_filter(i, 12)));
489502 assert!((6..12).all(|i| !filter.is_in_filter(i, 12)));
490503 assert_eq!(filter.count_filtered(12), 6);
504504+ assert_eq!(filter.count_filtered_without_limit(12), 12);
491505 assert!((0..6).all(|i| filter.get_relative_index(i, 12) == i));
492506 }
493507···500514501515 assert!((0..8).all(|i| !filter.is_in_filter(i, 8)));
502516 assert_eq!(filter.count_filtered(8), 0);
517517+ assert_eq!(filter.count_filtered_without_limit(8), 8);
503518 }
504519505520 #[test]
···512527 assert!((0..7).all(|i| filter.is_in_filter(i, 8)));
513528 assert!(!filter.is_in_filter(7, 8));
514529 assert_eq!(filter.count_filtered(8), 7);
530530+ assert_eq!(filter.count_filtered_without_limit(8), 8);
515531 assert!((0..7).all(|i| filter.get_relative_index(i, 8) == i));
516532 }
517533}