leibniz 0.2.0

The package provides a differentiable vector graphics rasterization loss.
Documentation
//! Points.

use ::burn::tensor::{Tensor, backend::Backend};

/// Coordinate columns with shapes `[samples]`.
pub type Coordinates<B> = (Tensor<B, 1>, Tensor<B, 1>);

/// Two-dimensional point with shape `[2]`.
pub type Point<B> = Tensor<B, 1>;

/// Distance to another point.
pub fn distance<B: Backend>(point: Point<B>, other: Point<B>) -> Tensor<B, 1> {
    length(point - other)
}

/// Unit left normal coordinate columns for tangent coordinate columns.
pub fn left_normals<B: Backend>(
    tangents: Coordinates<B>,
    lengths: Tensor<B, 1>,
    minimum_length: f32,
) -> Coordinates<B> {
    let (x, y) = tangents;
    let lengths = lengths.clamp_min(minimum_length);

    (-y / lengths.clone(), x / lengths)
}

/// Length as a vector.
pub fn length<B: Backend>(point: Point<B>) -> Tensor<B, 1> {
    point.powi_scalar(2).sum().sqrt()
}