use crate::integ::Gauss;
use crate::shapes::Scratchpad;
use crate::StrError;
use russell_lab::Vector;
pub fn get_points_coords(pad: &mut Scratchpad, gauss: &Gauss) -> Result<Vec<Vector>, StrError> {
let space_ndim = pad.xxt.dims().0;
let mut all_coords = Vec::new();
let ngauss = gauss.npoint();
for p in 0..ngauss {
let mut x = Vector::new(space_ndim);
pad.calc_coords(&mut x, gauss.coords(p))?;
all_coords.push(x);
}
Ok(all_coords)
}
#[cfg(test)]
mod tests {
use super::get_points_coords;
use crate::integ::Gauss;
use crate::shapes::{GeoKind, Scratchpad};
use russell_lab::approx_eq;
#[test]
pub fn points_coords_works() {
let (w, h) = (20.0, 10.0);
let space_ndim = 2;
let mut pad = Scratchpad::new(space_ndim, GeoKind::Qua4).unwrap();
pad.set_xx(0, 0, 0.0);
pad.set_xx(0, 1, 0.0);
pad.set_xx(1, 0, w);
pad.set_xx(1, 1, 0.0);
pad.set_xx(2, 0, w);
pad.set_xx(2, 1, h);
pad.set_xx(3, 0, 0.0);
pad.set_xx(3, 1, h);
let gauss = Gauss::new_sized(pad.kind.class(), 4).unwrap();
let x_ips = get_points_coords(&mut pad, &gauss).unwrap();
approx_eq(x_ips[0][0], w * (1.0 - f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[0][1], h * (1.0 - f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[1][0], w * (1.0 + f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[1][1], h * (1.0 - f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[2][0], w * (1.0 - f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[2][1], h * (1.0 + f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[3][0], w * (1.0 + f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
approx_eq(x_ips[3][1], h * (1.0 + f64::sqrt(3.0) / 3.0) / 2.0, 1e-15);
}
}