forked from StudioInfinity/dyna3
Reorganize the shared example code
The new layout deviates from what the Rust book suggests https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests and uses the frowned-upon `#[path]` attribute, https://doc.rust-lang.org/style-guide/advice.html#modules but we've decided that having a descriptive module filename instead of `mod.rs` is worth the cost.
This commit is contained in:
parent
2137284358
commit
477d6a5064
5 changed files with 30 additions and 51 deletions
|
@ -4,11 +4,11 @@ use nalgebra::DMatrix;
|
|||
|
||||
use dyna3::engine::{Q, DescentHistory, RealizationResult};
|
||||
|
||||
pub fn print_title(title: &str) {
|
||||
pub fn title(title: &str) {
|
||||
println!("─── {title} ───");
|
||||
}
|
||||
|
||||
pub fn print_realization_diagnostics(realization_result: &RealizationResult) {
|
||||
pub fn realization_diagnostics(realization_result: &RealizationResult) {
|
||||
let RealizationResult { result, history } = realization_result;
|
||||
println!();
|
||||
if let Err(ref message) = result {
|
||||
|
@ -20,15 +20,15 @@ pub fn print_realization_diagnostics(realization_result: &RealizationResult) {
|
|||
println!("Loss: {}", history.scaled_loss.last().unwrap());
|
||||
}
|
||||
|
||||
pub fn print_gram_matrix(config: &DMatrix<f64>) {
|
||||
pub fn gram_matrix(config: &DMatrix<f64>) {
|
||||
println!("\nCompleted Gram matrix:{}", (config.tr_mul(&*Q) * config).to_string().trim_end());
|
||||
}
|
||||
|
||||
pub fn print_config(config: &DMatrix<f64>) {
|
||||
pub fn config(config: &DMatrix<f64>) {
|
||||
println!("\nConfiguration:{}", config.to_string().trim_end());
|
||||
}
|
||||
|
||||
pub fn print_loss_history(history: &DescentHistory) {
|
||||
pub fn loss_history(history: &DescentHistory) {
|
||||
println!("\nStep │ Loss\n─────┼────────────────────────────────");
|
||||
for (step, scaled_loss) in history.scaled_loss.iter().enumerate() {
|
||||
println!("{:<4} │ {}", step, scaled_loss);
|
|
@ -1,18 +1,13 @@
|
|||
mod common;
|
||||
#[path = "common/print.rs"]
|
||||
mod print;
|
||||
|
||||
use common::{
|
||||
print_gram_matrix,
|
||||
print_loss_history,
|
||||
print_realization_diagnostics,
|
||||
print_title
|
||||
};
|
||||
use dyna3::engine::{Realization, examples::realize_irisawa_hexlet};
|
||||
|
||||
fn main() {
|
||||
const SCALED_TOL: f64 = 1.0e-12;
|
||||
let realization_result = realize_irisawa_hexlet(SCALED_TOL);
|
||||
print_title("Irisawa hexlet");
|
||||
print_realization_diagnostics(&realization_result);
|
||||
print::title("Irisawa hexlet");
|
||||
print::realization_diagnostics(&realization_result);
|
||||
if let Ok(Realization { config, .. }) = realization_result.result {
|
||||
// print the diameters of the chain spheres
|
||||
println!("\nChain diameters:");
|
||||
|
@ -22,7 +17,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// print the completed Gram matrix
|
||||
print_gram_matrix(&config);
|
||||
print::gram_matrix(&config);
|
||||
}
|
||||
print_loss_history(&realization_result.history);
|
||||
print::loss_history(&realization_result.history);
|
||||
}
|
|
@ -1,24 +1,19 @@
|
|||
mod common;
|
||||
#[path = "common/print.rs"]
|
||||
mod print;
|
||||
|
||||
use nalgebra::{DMatrix, DVector};
|
||||
|
||||
use common::{
|
||||
print_config,
|
||||
print_gram_matrix,
|
||||
print_realization_diagnostics,
|
||||
print_title
|
||||
};
|
||||
use dyna3::engine::{Realization, examples::realize_kaleidocycle};
|
||||
|
||||
fn main() {
|
||||
const SCALED_TOL: f64 = 1.0e-12;
|
||||
let realization_result = realize_kaleidocycle(SCALED_TOL);
|
||||
print_title("Kaleidocycle");
|
||||
print_realization_diagnostics(&realization_result);
|
||||
print::title("Kaleidocycle");
|
||||
print::realization_diagnostics(&realization_result);
|
||||
if let Ok(Realization { config, tangent }) = realization_result.result {
|
||||
// print the completed Gram matrix and the realized configuration
|
||||
print_gram_matrix(&config);
|
||||
print_config(&config);
|
||||
print::gram_matrix(&config);
|
||||
print::config(&config);
|
||||
|
||||
// find the kaleidocycle's twist motion by projecting onto the tangent
|
||||
// space
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
mod common;
|
||||
#[path = "common/print.rs"]
|
||||
mod print;
|
||||
|
||||
use common::{
|
||||
print_config,
|
||||
print_gram_matrix,
|
||||
print_loss_history,
|
||||
print_realization_diagnostics,
|
||||
print_title
|
||||
};
|
||||
use dyna3::engine::{
|
||||
point,
|
||||
realize_gram,
|
||||
|
@ -29,11 +23,11 @@ fn main() {
|
|||
let realization_result = realize_gram(
|
||||
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
print_title("Point on a sphere");
|
||||
print_realization_diagnostics(&realization_result);
|
||||
print::title("Point on a sphere");
|
||||
print::realization_diagnostics(&realization_result);
|
||||
if let Ok(Realization{ config, .. }) = realization_result.result {
|
||||
print_gram_matrix(&config);
|
||||
print_config(&config);
|
||||
print::gram_matrix(&config);
|
||||
print::config(&config);
|
||||
}
|
||||
print_loss_history(&realization_result.history);
|
||||
print::loss_history(&realization_result.history);
|
||||
}
|
|
@ -1,11 +1,6 @@
|
|||
mod common;
|
||||
#[path = "common/print.rs"]
|
||||
mod print;
|
||||
|
||||
use common::{
|
||||
print_gram_matrix,
|
||||
print_loss_history,
|
||||
print_realization_diagnostics,
|
||||
print_title
|
||||
};
|
||||
use dyna3::engine::{realize_gram, sphere, ConstraintProblem, Realization};
|
||||
|
||||
fn main() {
|
||||
|
@ -25,10 +20,10 @@ fn main() {
|
|||
let realization_result = realize_gram(
|
||||
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
|
||||
);
|
||||
print_title("Three spheres");
|
||||
print_realization_diagnostics(&realization_result);
|
||||
print::title("Three spheres");
|
||||
print::realization_diagnostics(&realization_result);
|
||||
if let Ok(Realization{ config, .. }) = realization_result.result {
|
||||
print_gram_matrix(&config);
|
||||
print::gram_matrix(&config);
|
||||
}
|
||||
print_loss_history(&realization_result.history);
|
||||
print::loss_history(&realization_result.history);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue