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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
pub mod rotor;
use {
crate::skelly::{Posture, Skelly},
core::ops::Add,
na::Scalar,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Status {
Solved,
Unsolved,
Infeasible,
}
pub struct StepResult<T> {
error: T,
status: Status,
}
impl<T> StepResult<T>
where
T: Add<Output = T>,
{
pub fn solved(error: T) -> Self {
StepResult {
error,
status: Status::Solved,
}
}
pub fn unsolved(error: T) -> Self {
StepResult {
error,
status: Status::Unsolved,
}
}
pub fn infeasible(error: T) -> Self {
StepResult {
error,
status: Status::Infeasible,
}
}
pub fn reduce(self, rhs: Self) -> Self {
let status = match (self.status, rhs.status) {
(Status::Infeasible, _) | (_, Status::Infeasible) => Status::Infeasible,
(Status::Unsolved, _) | (_, Status::Unsolved) => Status::Unsolved,
(Status::Solved, Status::Solved) => Status::Solved,
};
StepResult {
error: self.error + rhs.error,
status,
}
}
}
pub trait IkSolver<T: Scalar> {
fn new(error: T) -> Self;
fn solve_step<D>(&mut self, skelly: &Skelly<T, D>, posture: &mut Posture<T>) -> StepResult<T>;
}