Skip to content

Commit

Permalink
Merge pull request #54 from NREL/fix/pyi-updates
Browse files Browse the repository at this point in the history
added `new` and `__new__` methods for Elev
  • Loading branch information
calbaker authored Apr 16, 2024
2 parents 4a2e6b0 + 446c30e commit 2d30702
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions python/altrios/altrios_pyo3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,22 @@ class Link(SerdeAPI):
def default(cls) -> Self: ...


class Elev(SerdeAPI):
offset_meters: float
elev_meters: float
@classmethod
def default(cls) -> Self: ...


class Heading(SerdeAPI):
offset_meters: float
heading: float
lat: Optional[float]
lon: Optional[float]
@classmethod
def default(cls) -> Self: ...


def import_locations(filename: str) -> Dict[str, List[Location]]: ...
def import_rail_vehicles(filename: str) -> Dict[str, RailVehicle]: ...

Expand Down
16 changes: 15 additions & 1 deletion rust/altrios-core/src/track/link/elev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ use crate::imports::*;

/// Struct containing elevation for a particular offset w.r.t. `Link`
#[derive(Clone, Copy, Default, Debug, PartialEq, PartialOrd, Serialize, Deserialize, SerdeAPI)]
#[altrios_api]
#[altrios_api(
#[new]
fn __new__(
offset_meters: f64,
elev_meters: f64,
) -> PyResult<Self> {
Ok(Self::new(offset_meters * uc::M, elev_meters * uc::M))
}
)]
pub struct Elev {
pub offset: si::Length,
pub elev: si::Length,
}

impl Elev {
pub fn new(offset: si::Length, elev: si::Length) -> Self {
Self { offset, elev }
}
}

impl Valid for Elev {}

impl ObjState for Elev {
Expand Down

0 comments on commit 2d30702

Please sign in to comment.