1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Phase-polarity authorization shared by processing operations.
/// Polarity requested for phase-sensitive processing.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum ExpectedPolarity {
/// Positive and negative peaks are both expected; 180-degree polarity is unknown.
#[default]
Signed,
/// The caller explicitly asserts that expected peaks are positive.
Positive,
}
/// Current authorization for phase-sensitive scalar projection.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum PolarityState {
/// The spectrum may be globally inverted by 180 degrees.
#[default]
Ambiguous180,
/// The public caller explicitly asserts positive expected peaks.
UserAssertedPositive,
}
impl PolarityState {
/// Resolves a public caller's requested polarity.
pub fn from_request(expected: ExpectedPolarity) -> Self {
match expected {
ExpectedPolarity::Signed => Self::Ambiguous180,
ExpectedPolarity::Positive => Self::UserAssertedPositive,
}
}
/// Returns whether positive polarity is established.
pub fn is_established(self) -> bool {
matches!(self, Self::UserAssertedPositive)
}
}