Skip to main content

astroimsim_data/
test.rs

1use astroimsim_geometry::coordinate_system::{CoordinateSystem, Coordinates};
2use astroimsim_geometry::coordinate_system::Coordinates::RELATIVE;
3use astroimsim_geometry::grid2d::GRID2D;
4use astroimsim_geometry::*;
5use astroimsim_geometry::points::Point;
6
7use crate::spatial_effect::SpatialEffect;
8
9pub fn test_2d_interpolation() {
10    let coordinates = CoordinateSystem::new(
11        (0.0, 1.0),
12        (1.0, 0.0),
13        (0.0, 0.0),
14        "test coords",
15        "red",
16    );
17
18    let test_grid = GRID2D::new_empty((100, 100), (0.010, 0.010), (10.0, 10.0), 0.45, RELATIVE(coordinates));
19    let mut matrix = Vec::new();
20    for row in 0..test_grid.y_num{
21        let mut row_vec = Vec::new();
22        for column in 0..test_grid.x_num{
23            let point = test_grid.locate(test_grid.grid_number(column,row));
24            row_vec.push(test_function(&point))
25
26        }
27        matrix.push(row_vec)
28    }
29
30    let data_grid = SpatialEffect::from_matrix("data grid", test_grid.clone(), "NA", matrix);
31
32    println!("data grid is :{:?}",data_grid);
33
34
35    for i in 0..100{
36        let point = test_grid.random();
37        let datum1 = data_grid.get_data(&point);
38        let datum2 = test_function(&point);
39        println!(" {:?} {:?}   {:?}  {:?}",test_grid.fit_grid(&point), datum1,datum2, 100.0*(datum2-datum1)/datum2)
40    }
41}
42
43pub fn test_function(point: &Point)-> f64{
44    let (x,y) = point.to_absolute().values();
45    let result = x.powi(3) + y.powi(2);
46    if result.is_nan(){
47        println!("{:?} gave NaN",(x,y))
48    }
49    result
50}