use ::burn::tensor::{Tensor, backend::Backend};
use crate::burn::tensor::column;
pub type Coordinates<B> = (Tensor<B, 1>, Tensor<B, 1>);
pub type Point<B> = Tensor<B, 1>;
pub fn distance<B: Backend>(point: Point<B>, other: Point<B>) -> Tensor<B, 1> {
length(point - other)
}
pub fn left_normals<B: Backend>(
vectors: Tensor<B, 2>,
lengths: Tensor<B, 1>,
minimum_length: f32,
) -> Coordinates<B> {
let x = column(vectors.clone(), 0);
let y = column(vectors, 1);
let lengths = lengths.clamp_min(minimum_length);
(-y / lengths.clone(), x / lengths)
}
pub fn length<B: Backend>(point: Point<B>) -> Tensor<B, 1> {
point.powi_scalar(2).sum().sqrt()
}
pub fn row_lengths<B: Backend>(vectors: Tensor<B, 2>) -> Tensor<B, 1> {
vectors.powi_scalar(2).sum_dim(1).squeeze_dim::<1>(1).sqrt()
}