wip
This commit is contained in:
parent
d11f8510b4
commit
ed6aa4b9c9
@ -51,12 +51,12 @@ codee = { version = "0.3" }
|
|||||||
error_reporter = { version = "1" }
|
error_reporter = { version = "1" }
|
||||||
getrandom = { version = "0.3.1" }
|
getrandom = { version = "0.3.1" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
test-try= "0.1"
|
||||||
|
|
||||||
[dev-dependencies.serde_json]
|
[dev-dependencies.serde_json]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
|
||||||
[dev-dependencies.test-try]
|
|
||||||
version = "0.1"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
hydrate = ["leptos/hydrate", "getrandom/wasm_js", "uuid/js"]
|
hydrate = ["leptos/hydrate", "getrandom/wasm_js", "uuid/js"]
|
||||||
ssr = [
|
ssr = [
|
||||||
|
@ -18,6 +18,7 @@ pub use v3::UserInteraction;
|
|||||||
pub use v4::DatedAttempt;
|
pub use v4::DatedAttempt;
|
||||||
pub use v4::Problem;
|
pub use v4::Problem;
|
||||||
pub use v4::ProblemHolds;
|
pub use v4::ProblemHolds;
|
||||||
|
pub use v4::Transformation;
|
||||||
|
|
||||||
mod semantics;
|
mod semantics;
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ pub mod v4 {
|
|||||||
pub transformation: Transformation,
|
pub transformation: Transformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Default)]
|
||||||
pub struct Transformation {
|
pub struct Transformation {
|
||||||
pub horizontal_shift: u64,
|
pub horizontal_shift: u64,
|
||||||
pub mirror: bool,
|
pub mirror: bool,
|
||||||
|
@ -11,8 +11,10 @@ impl Problem {
|
|||||||
transformation,
|
transformation,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let min_col = holds.0.iter().map(|(hold_position, _)| hold_position.col).min().unwrap_or(0);
|
let mut transformation = *transformation;
|
||||||
|
|
||||||
|
let min_col = holds.0.iter().map(|(hold_position, _)| hold_position.col).min().unwrap_or(0);
|
||||||
|
transformation.horizontal_shift += min_col;
|
||||||
let holds = {
|
let holds = {
|
||||||
let holds = holds
|
let holds = holds
|
||||||
.0
|
.0
|
||||||
@ -28,17 +30,17 @@ impl Problem {
|
|||||||
ProblemHolds(holds)
|
ProblemHolds(holds)
|
||||||
};
|
};
|
||||||
|
|
||||||
let transformation = {
|
let mut new = Self {
|
||||||
let mut transformation = *transformation;
|
|
||||||
transformation.horizontal_shift += min_col;
|
|
||||||
transformation
|
|
||||||
};
|
|
||||||
|
|
||||||
Self {
|
|
||||||
holds,
|
holds,
|
||||||
method: *method,
|
method: *method,
|
||||||
transformation,
|
transformation,
|
||||||
|
};
|
||||||
|
|
||||||
|
if new.transformation.mirror {
|
||||||
|
new = new.mirror();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mirror(&self) -> Self {
|
pub fn mirror(&self) -> Self {
|
||||||
@ -78,7 +80,6 @@ impl Problem {
|
|||||||
method: *method,
|
method: *method,
|
||||||
transformation,
|
transformation,
|
||||||
}
|
}
|
||||||
.normalize()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shift(&self, shift: i64) -> Self {
|
pub fn shift(&self, shift: i64) -> Self {
|
||||||
@ -186,3 +187,67 @@ impl Attempt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test_try::test_try]
|
||||||
|
fn normalize_empty_problem() {
|
||||||
|
let problem = Problem {
|
||||||
|
holds: ProblemHolds([].into_iter().collect()),
|
||||||
|
method: Method::FeetFollowHands,
|
||||||
|
transformation: Transformation::default(),
|
||||||
|
};
|
||||||
|
let normalized = problem.normalize();
|
||||||
|
assert_eq!(problem, normalized);
|
||||||
|
let mirrored = problem.mirror();
|
||||||
|
assert_eq!(problem, mirrored);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_try::test_try]
|
||||||
|
fn normalize_problem() {
|
||||||
|
let problem = Problem {
|
||||||
|
holds: ProblemHolds(
|
||||||
|
[
|
||||||
|
(HoldPosition { row: 0, col: 1 }, HoldRole::End),
|
||||||
|
(HoldPosition { row: 7, col: 6 }, HoldRole::Start),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
method: Method::FeetFollowHands,
|
||||||
|
transformation: Transformation::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let normalized = problem.normalize();
|
||||||
|
|
||||||
|
assert_eq!(normalized.holds.0[&HoldPosition { row: 0, col: 0 }], HoldRole::End);
|
||||||
|
assert_eq!(normalized.holds.0[&HoldPosition { row: 7, col: 5 }], HoldRole::Start);
|
||||||
|
assert_eq!(normalized.transformation.horizontal_shift, 1);
|
||||||
|
assert_eq!(normalized.transformation.mirror, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_try::test_try]
|
||||||
|
fn mirror_problem() {
|
||||||
|
let problem = Problem {
|
||||||
|
holds: ProblemHolds(
|
||||||
|
[
|
||||||
|
(HoldPosition { row: 0, col: 1 }, HoldRole::End),
|
||||||
|
(HoldPosition { row: 7, col: 6 }, HoldRole::Start),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
method: Method::FeetFollowHands,
|
||||||
|
transformation: Transformation::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let normalized = problem.normalize();
|
||||||
|
|
||||||
|
assert_eq!(normalized.holds.0[&HoldPosition { row: 0, col: 0 }], HoldRole::End);
|
||||||
|
assert_eq!(normalized.holds.0[&HoldPosition { row: 7, col: 5 }], HoldRole::Start);
|
||||||
|
assert_eq!(normalized.transformation.horizontal_shift, 1);
|
||||||
|
assert_eq!(normalized.transformation.mirror, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user