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