dyna3/app-proto/examples/point-on-sphere.rs
Aaron Fenyes 477d6a5064 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.
2025-07-18 10:59:41 -07:00

33 lines
No EOL
880 B
Rust

#[path = "common/print.rs"]
mod print;
use dyna3::engine::{
point,
realize_gram,
sphere,
ConstraintProblem,
Realization
};
fn main() {
let mut problem = ConstraintProblem::from_guess(&[
point(0.0, 0.0, 2.0),
sphere(0.0, 0.0, 0.0, 1.0)
]);
for j in 0..2 {
for k in j..2 {
problem.gram.push_sym(j, k, if (j, k) == (1, 1) { 1.0 } else { 0.0 });
}
}
problem.frozen.push(3, 0, problem.guess[(3, 0)]);
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);
if let Ok(Realization{ config, .. }) = realization_result.result {
print::gram_matrix(&config);
print::config(&config);
}
print::loss_history(&realization_result.history);
}