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
impl RegularTernaryScalarField
Sourcepub fn from_fn<F>(
subdivisions: usize,
value_at: F,
) -> Result<RegularTernaryScalarField, FieldError>
pub fn from_fn<F>( subdivisions: usize, value_at: F, ) -> Result<RegularTernaryScalarField, FieldError>
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);Sourcepub fn try_from_fn<F, E>(
subdivisions: usize,
value_at: F,
) -> Result<RegularTernaryScalarField, GridEvaluationError<E>>
pub fn try_from_fn<F, E>( subdivisions: usize, value_at: F, ) -> Result<RegularTernaryScalarField, GridEvaluationError<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",
..
}
));pub fn new( subdivisions: usize, values: Vec<f64>, ) -> Result<RegularTernaryScalarField, FieldError>
pub const fn subdivisions(&self) -> usize
pub fn values(&self) -> &[f64]
pub const fn vertex_count(&self) -> usize
pub fn triangle_count(&self) -> Result<usize, FieldError>
pub fn edge_count(&self) -> Result<usize, FieldError>
pub fn value(&self, id: GridVertexId) -> Result<f64, FieldError>
pub fn vertex_id( &self, coordinate: LatticeCoordinate, ) -> Result<GridVertexId, FieldError>
pub fn lattice_coordinate( &self, id: GridVertexId, ) -> Result<LatticeCoordinate, FieldError>
pub fn composition(&self, id: GridVertexId) -> Result<[f64; 3], FieldError>
pub fn index_of( &self, i: usize, j: usize, k: usize, ) -> Result<usize, FieldError>
pub fn coordinate_of( &self, index: usize, ) -> Result<LatticeCoordinate, FieldError>
pub fn composition_at(&self, index: usize) -> Result<[f64; 3], FieldError>
pub fn elementary_triangles(&self) -> Result<Vec<GridTriangle>, FieldError>
Trait Implementations§
Source§impl Clone for RegularTernaryScalarField
impl Clone for RegularTernaryScalarField
Source§fn clone(&self) -> RegularTernaryScalarField
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RegularTernaryScalarField
impl Debug for RegularTernaryScalarField
impl StructuralPartialEq for RegularTernaryScalarField
Auto Trait Implementations§
impl Freeze for RegularTernaryScalarField
impl RefUnwindSafe for RegularTernaryScalarField
impl Send for RegularTernaryScalarField
impl Sync for RegularTernaryScalarField
impl Unpin for RegularTernaryScalarField
impl UnsafeUnpin for RegularTernaryScalarField
impl UnwindSafe for RegularTernaryScalarField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more