conspire/geometry/ntree/rescale/
mod.rs1use crate::{
2 geometry::{Coordinate, Coordinates, ntree::Orthotree},
3 math::{Scalar, Tensor},
4};
5use std::array::from_fn;
6
7pub struct Rescaling<const D: usize> {
8 pub(crate) center: [Scalar; D],
9 pub(crate) cell: Scalar,
10 pub(crate) half: Scalar,
11}
12
13impl<const D: usize> Rescaling<D> {
14 pub fn apply(&self, coordinate: &Coordinate<D>) -> Coordinate<D> {
15 from_fn(|ax| (coordinate[ax] - self.half) * self.cell + self.center[ax]).into()
16 }
17}
18
19impl<const D: usize, const L: usize, const M: usize, const N: usize, T, U, V>
20 Orthotree<D, L, M, N, T, U, V>
21{
22 pub fn rescale(&self) -> &Rescaling<D> {
23 &self.rescale
24 }
25 pub fn rescale_coordinates(&self, coordinates: &mut Coordinates<D>) {
26 coordinates
27 .iter_mut()
28 .for_each(|coordinate| *coordinate = self.rescale.apply(coordinate));
29 }
30}