leibniz 0.2.0

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

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

use crate::base::geometry::Command;

/// Contour command arguments with shape `[commands, 2, 2]`.
pub type Arguments<B> = Tensor<B, 3>;

/// Contour commands and their argument tensor.
#[derive(Clone)]
pub struct Contour<B: Backend> {
    commands: Vec<Command>,
    arguments: Arguments<B>,
}

impl<B: Backend> Contour<B> {
    /// Create a contour.
    ///
    /// # Panics
    ///
    /// Panics if the command count does not match the argument sequence.
    pub fn new(commands: Vec<Command>, arguments: Arguments<B>) -> Self {
        assert!(
            commands.len() == arguments.dims()[0],
            "command count must match contour argument count"
        );

        Self {
            commands,
            arguments,
        }
    }

    /// Contour argument tensor.
    pub fn arguments(&self) -> Arguments<B> {
        self.arguments.clone()
    }

    /// Command at an index.
    pub fn command(&self, index: usize) -> Command {
        self.commands[index]
    }

    /// Contour commands.
    pub fn commands(&self) -> &[Command] {
        &self.commands
    }

    /// Detached contour.
    pub fn detach(&self) -> Self {
        Self {
            commands: self.commands.clone(),
            arguments: self.arguments.clone().detach(),
        }
    }

    /// Argument tensor device.
    pub fn device(&self) -> B::Device {
        self.arguments.device()
    }

    /// Argument tensor dimensions.
    pub fn dims(&self) -> [usize; 3] {
        self.arguments.dims()
    }
}