1use crate::base::js_state_convert::*;
6use js_sys::Array;
7use oxmpl::base::{
8 planner::Path as OxmplPath,
9 state::{CompoundState, RealVectorState, SE2State, SE3State, SO2State, SO3State},
10};
11use wasm_bindgen::prelude::*;
12
13pub enum PathVariant {
14 RealVector(OxmplPath<RealVectorState>),
15 SO2(OxmplPath<SO2State>),
16 SO3(OxmplPath<SO3State>),
17 Compound(OxmplPath<CompoundState>),
18 SE2(OxmplPath<SE2State>),
19 SE3(OxmplPath<SE3State>),
20}
21
22#[wasm_bindgen(js_name = Path)]
23pub struct JsPath {
24 pub(crate) inner: PathVariant,
25}
26
27#[wasm_bindgen(js_class = Path)]
28impl JsPath {
29 #[wasm_bindgen(js_name = getStates)]
30 pub fn get_states(&self) -> Array {
31 match &self.inner {
32 PathVariant::RealVector(path) => path.0.iter().map(|s| s.to_js_value()).collect(),
33 PathVariant::SO2(path) => path.0.iter().map(|s| s.to_js_value()).collect(),
34 PathVariant::SO3(path) => path.0.iter().map(|s| s.to_js_value()).collect(),
35 PathVariant::Compound(path) => path.0.iter().map(|s| s.to_js_value()).collect(),
36 PathVariant::SE2(path) => path.0.iter().map(|s| s.to_js_value()).collect(),
37 PathVariant::SE3(path) => path.0.iter().map(|s| s.to_js_value()).collect(),
38 }
39 }
40
41 #[wasm_bindgen(js_name = getLength)]
42 pub fn get_length(&self) -> usize {
43 match &self.inner {
44 PathVariant::RealVector(path) => path.0.len(),
45 PathVariant::SO2(path) => path.0.len(),
46 PathVariant::SO3(path) => path.0.len(),
47 PathVariant::Compound(path) => path.0.len(),
48 PathVariant::SE2(path) => path.0.len(),
49 PathVariant::SE3(path) => path.0.len(),
50 }
51 }
52}
53
54impl From<OxmplPath<RealVectorState>> for JsPath {
55 fn from(path: OxmplPath<RealVectorState>) -> Self {
56 Self {
57 inner: PathVariant::RealVector(path),
58 }
59 }
60}
61
62impl From<OxmplPath<SO2State>> for JsPath {
63 fn from(path: OxmplPath<SO2State>) -> Self {
64 Self {
65 inner: PathVariant::SO2(path),
66 }
67 }
68}
69
70impl From<OxmplPath<SO3State>> for JsPath {
71 fn from(path: OxmplPath<SO3State>) -> Self {
72 Self {
73 inner: PathVariant::SO3(path),
74 }
75 }
76}
77
78impl From<OxmplPath<CompoundState>> for JsPath {
79 fn from(path: OxmplPath<CompoundState>) -> Self {
80 Self {
81 inner: PathVariant::Compound(path),
82 }
83 }
84}
85
86impl From<OxmplPath<SE2State>> for JsPath {
87 fn from(path: OxmplPath<SE2State>) -> Self {
88 Self {
89 inner: PathVariant::SE2(path),
90 }
91 }
92}
93
94impl From<OxmplPath<SE3State>> for JsPath {
95 fn from(path: OxmplPath<SE3State>) -> Self {
96 Self {
97 inner: PathVariant::SE3(path),
98 }
99 }
100}