Skip to content

Commit

Permalink
fix apvd.d.ts Step collision
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Oct 9, 2023
1 parent ad77c51 commit 4dca40d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ use std::{path::Path, collections::BTreeMap};
use polars::{prelude::*, series::SeriesIter};
use serde::{Serialize, Deserialize};
use tsify::Tsify;
use wasm_bindgen::prelude::wasm_bindgen;

use crate::{shape::Shape, step, model::Model};
use crate::{shape::Shape, step::Step, model::Model};

/// Namespacing apparently necessary to avoid colliding with step::Step in apvd.d.ts: https://github.com/madonoharu/tsify/issues/36
#[derive(Debug, Clone, PartialEq, Tsify, Serialize, Deserialize)]
pub struct Step {
pub struct HistoryStep {
pub error: f64,
pub shapes: Vec<Shape<f64>>,
}

impl From<step::Step> for Step {
fn from(s: step::Step) -> Self {
Step {
impl From<Step> for HistoryStep {
fn from(s: Step) -> Self {
HistoryStep {
error: s.error.v(),
shapes: s.shapes.into_iter().map(|s| s.into()).collect(),
}
}
}

impl Step {
impl HistoryStep {
pub fn names(&self) -> Vec<String> {
self
.shapes
Expand All @@ -42,7 +44,7 @@ impl Step {
}

#[derive(Debug, Clone, derive_more::Deref, Tsify, Serialize, Deserialize)]
pub struct History(pub Vec<Step>);
pub struct History(pub Vec<HistoryStep>);

impl From<Model> for History {
fn from(m: Model) -> Self {
Expand Down Expand Up @@ -89,7 +91,7 @@ impl History {
}

let num_rows = df.height();
let mut steps: Vec<Step> = Vec::new();
let mut steps: Vec<HistoryStep> = Vec::new();
let next = |row_idx: usize, col_idx: usize, iter: &mut SeriesIter| -> Result<f64, LoadErr> {
match iter.next().expect(&format!("col {} should have at least {} rows, found {}", col_idx, num_rows, row_idx)) {
Float64(f) => Ok(f),
Expand All @@ -112,7 +114,7 @@ impl History {
}).collect();
Shape::from_coords(coords)
}).collect();
steps.push(Step { error, shapes });
steps.push(HistoryStep { error, shapes });
}
Ok(Self(steps))
}
Expand Down
4 changes: 2 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Model {
mod tests {
use std::{env, f64::consts::PI};

use crate::{duals::{D, Z}, scene::tests::ellipses4, shape::{circle, InputSpec, xyrr, xyrrt}, to::To, transform::{CanTransform, Transform::Rotate}, coord_getter::CoordGetters, history::{History, self}};
use crate::{duals::{D, Z}, scene::tests::ellipses4, shape::{circle, InputSpec, xyrr, xyrrt}, to::To, transform::{CanTransform, Transform::Rotate}, coord_getter::CoordGetters, history::{History, HistoryStep}};

use super::*;
use test_log::test;
Expand Down Expand Up @@ -166,7 +166,7 @@ mod tests {
let steps = model.steps;
assert_eq!(steps.len(), expecteds.len());
for (idx, (step, expected)) in steps.into_iter().zip(expecteds.into_iter()).enumerate() {
let actual: history::Step = step.into();
let actual: HistoryStep = step.into();
assert_eq!(actual, expected, "Step {}", idx);
}
}
Expand Down

0 comments on commit 4dca40d

Please sign in to comment.