Skip to main content

RegularTernaryScalarField

Struct RegularTernaryScalarField 

Source
pub struct RegularTernaryScalarField { /* private fields */ }
Expand description

A scalar field sampled on the regular ternary lattice i+j+k=n.

Values use row-major (i,j) ordering: i increases from zero to n, and for each i, j increases from zero to n-i; k=n-i-j.

Implementations§

Source§

impl RegularTernaryScalarField

Source

pub fn from_fn<F>( subdivisions: usize, value_at: F, ) -> Result<RegularTernaryScalarField, FieldError>
where F: FnMut([f64; 3]) -> f64,

Construct a field by evaluating one scalar value at every canonical grid composition.

The callback receives normalized [a, b, c] compositions in the same order as RegularTernaryGrid::compositions. The produced values are validated exactly as they are by Self::new.

Example:

use ternary_contours::RegularTernaryScalarField;

let field = RegularTernaryScalarField::from_fn(2, |[a, b, c]| {
    2.0 * a - 3.0 * b + 5.0 * c
})?;
assert_eq!(field.vertex_count(), 6);
Source

pub fn try_from_fn<F, E>( subdivisions: usize, value_at: F, ) -> Result<RegularTernaryScalarField, GridEvaluationError<E>>
where F: FnMut([f64; 3]) -> Result<f64, E>,

Fallibly construct a field by evaluating canonical grid compositions.

Callback failures retain their source error, stable vertex identifier, and normalized composition in GridEvaluationError::Evaluation. Grid and field validation failures are returned as GridEvaluationError::Grid.

Example:

use ternary_contours::{
    GridEvaluationError, GridVertexId, RegularTernaryScalarField,
};

let error = RegularTernaryScalarField::try_from_fn(2, |composition| {
    if composition == [0.0, 0.5, 0.5] {
        Err("sample unavailable")
    } else {
        Ok(composition[0])
    }
})
.unwrap_err();
assert!(matches!(
    error,
    GridEvaluationError::Evaluation {
        index: GridVertexId(1),
        source: "sample unavailable",
        ..
    }
));
Source

pub fn new( subdivisions: usize, values: Vec<f64>, ) -> Result<RegularTernaryScalarField, FieldError>

Source

pub const fn subdivisions(&self) -> usize

Source

pub fn values(&self) -> &[f64]

Source

pub const fn vertex_count(&self) -> usize

Source

pub fn triangle_count(&self) -> Result<usize, FieldError>

Source

pub fn edge_count(&self) -> Result<usize, FieldError>

Source

pub fn value(&self, id: GridVertexId) -> Result<f64, FieldError>

Source

pub fn vertex_id( &self, coordinate: LatticeCoordinate, ) -> Result<GridVertexId, FieldError>

Source

pub fn lattice_coordinate( &self, id: GridVertexId, ) -> Result<LatticeCoordinate, FieldError>

Source

pub fn composition(&self, id: GridVertexId) -> Result<[f64; 3], FieldError>

Source

pub fn index_of( &self, i: usize, j: usize, k: usize, ) -> Result<usize, FieldError>

Source

pub fn coordinate_of( &self, index: usize, ) -> Result<LatticeCoordinate, FieldError>

Source

pub fn composition_at(&self, index: usize) -> Result<[f64; 3], FieldError>

Source

pub fn elementary_triangles(&self) -> Result<Vec<GridTriangle>, FieldError>

Trait Implementations§

Source§

impl Clone for RegularTernaryScalarField

Source§

fn clone(&self) -> RegularTernaryScalarField

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RegularTernaryScalarField

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RegularTernaryScalarField

Source§

fn eq(&self, other: &RegularTernaryScalarField) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RegularTernaryScalarField

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.