Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions crates/cherry-rs/src/core/sequential_model/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ impl SequentialModelBuilder {
if self.paths.is_some() {
let paths = self.paths.unwrap();
let wavelengths = self.wavelengths.unwrap();
let stop_surface = self.stop_surface;
#[cfg(feature = "serde")]
let model = SequentialModel::from_path_specs(
paths,
&wavelengths,
stop_surface,
self.registry.as_ref(),
)?;
let model =
SequentialModel::from_path_specs(paths, &wavelengths, self.registry.as_ref())?;
#[cfg(not(feature = "serde"))]
let model = SequentialModel::from_path_specs(paths, &wavelengths, stop_surface)?;
let model = SequentialModel::from_path_specs(paths, &wavelengths)?;
return Ok(BuildResult {
model,
gap_specs: vec![],
Expand Down Expand Up @@ -609,6 +604,7 @@ mod tests {
refractive_index: n!(1.0),
}],
beam_splitter_arms: vec![],
stop_surface: None,
}
}

Expand All @@ -633,6 +629,7 @@ mod tests {
refractive_index: n!(1.0),
}],
beam_splitter_arms: vec![],
stop_surface: None,
};
let result = SequentialModelBuilder::new()
.paths(vec![bad_path])
Expand All @@ -654,6 +651,7 @@ mod tests {
refractive_index: n!(1.0),
}],
beam_splitter_arms: vec![],
stop_surface: None,
};
let result = SequentialModelBuilder::new()
.paths(vec![bad_path])
Expand Down Expand Up @@ -686,6 +684,7 @@ mod tests {
},
],
beam_splitter_arms: vec![],
stop_surface: None,
};
let result = SequentialModelBuilder::new()
.paths(vec![bad_path])
Expand All @@ -712,6 +711,7 @@ mod tests {
refractive_index: n!(1.0),
}],
beam_splitter_arms: vec![],
stop_surface: None,
};
let result = SequentialModelBuilder::new()
.paths(vec![path0, bad_path1])
Expand Down Expand Up @@ -754,6 +754,7 @@ mod tests {
},
],
beam_splitter_arms: vec![], // missing arm declaration for the BS
stop_surface: None,
};
let result = SequentialModelBuilder::new()
.paths(vec![path])
Expand Down Expand Up @@ -832,6 +833,7 @@ mod tests {
},
],
beam_splitter_arms: vec![],
stop_surface: None,
};
let model_new = SequentialModelBuilder::new()
.paths(vec![path])
Expand Down
26 changes: 26 additions & 0 deletions crates/cherry-rs/src/core/sequential_model/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ impl Cursor {
}
}

/// Create a new cursor from an explicit position and frame (right, up,
/// forward). Used by the builder to seed a secondary path's cursor from
/// another path's cursor frame (e.g. `ObjectLinkedTo`). `track` is reset
/// to `0.0`.
pub(crate) fn from_frame(pos: Vec3, right: Vec3, up: Vec3, forward: Vec3) -> Self {
Self {
pos,
right,
up,
forward,
track: 0.0,
}
}

/// Advance the cursor by a given distance along the z-direction.
pub fn advance(&mut self, distance: Float) {
// Edge case for advancing from negative infinity to 0.
Expand Down Expand Up @@ -135,6 +149,18 @@ mod test {
);
}

#[test]
fn from_frame_sets_all_fields() {
let pos = Vec3::new(1.0, 2.0, 3.0);
let right = Vec3::new(1.0, 0.0, 0.0);
let up = Vec3::new(0.0, 0.0, -1.0);
let forward = Vec3::new(0.0, -1.0, 0.0);
let cursor = Cursor::from_frame(pos, right, up, forward);
assert_eq!(cursor.pos(), pos);
assert_eq!(cursor.forward(), forward);
assert_eq!(cursor.track(), 0.0);
}

#[test]
fn cursor_start_from_neg_infinity() {
let mut cursor = Cursor::new(Float::NEG_INFINITY);
Expand Down
Loading
Loading