Trait hexasphere::BaseShape [−][src]
Defines the setup for a base shape, and the functions used in interpolation.
If you want to use a different interpolation function, implement this trait for a new type, and carry over only the properties you’d like to keep:
use hexasphere::{Triangle, shapes::IcoSphereBase}; use glam::Vec3A; // Uses linear interpolation instead of spherical. struct FlatIcosahedron; impl BaseShape for FlatIcosahedron { // Keep the initial parameters. fn initial_points(&self) -> Vec<Vec3A> { IcoSphereBase.initial_points() } fn triangles(&self) -> Box<[Triangle]> { IcoSphereBase.triangles() } const EDGES: usize = IcoSphereBase::EDGES; // Swap out what you'd like to change. fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A { hexasphere::interpolation::lerp(a, b, p) } fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A { hexasphere::interpolation::lerp_half(a, b) } fn interpolate_multiple(&self, a: Vec3A, b: Vec3A, indices: &[u32], points: &mut [Vec3A]) { hexasphere::interpolation::lerp_multiple(a, b, indices, points); } }
Or, create your own shape, by changing the values for
initial_points, triangles, and EDGES. Check
the documentation for these members individually on how
they should be implemented.
Associated Constants
const EDGES: usize[src]
Number of unique edges defined in the contents of
triangles(). This number is 5 for a square for
example:
a - 0 - b
| / |
3 4 1
| / |
d - 2 - c
Required methods
fn initial_points(&self) -> Vec<Vec3A>[src]
The initial vertices for the triangle. Note that
Vec3A::new is not a const fn(), hence I recommend
you use lazy_static. Check the source file for this
crate and look for the constants module at the bottom
for an example.
Constraints on the points depend on the interpolation function used:
slerprequires normalized (magnitude 1) data.lerpdoesn’t care.normalized_lerprequires normalized (magnitude 1) data.
fn triangles(&self) -> Box<[Triangle]>[src]
Base triangles for the shape.
- The fields
a,b, andcdefine the indices for the points of the triangles given the data present ininitial_points. Note that this crate assumes points are in a counter clockwise ordering. - The fields
ab_edge,bc_edge,ca_edgemark the index of the edge whicha/b,b/c, andc/aborder respectively. While theoretically you could give each triangle its own edge, minimizing edges saves on memory footprint and performance. - Triangles should be created through
Triangle::new.
fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A[src]
Basic function used for interpolation. When p is
0.0, a is expected. When p is 1.0, b is
expected. There are three options already implemented
in this crate:
lerpimplements linear interpolation.geometric_slerpimplements spherical interpolation. (Interpolates along an arc on a sphere)normalized_lerpimplements cheaper yet less accurate spherical interpolation. The accuracy decreases as the angle between the two points on the unit sphere increases.
Provided methods
fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A[src]
If an optimization is available for the case where p
is 0.5, this function should implement it. This defaults
to calling interpolate(a, b, 0.5) however.
fn interpolate_multiple(
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)[src]
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)
If an optimization is available for the case where p
varies but a and b don’t this function should implement
it.
Parameters
a: start.b: end.indices: list of indices to index intopoints.pointsat the index should contain the result. The index (n) of an index should correspond with the nth point in a distribution ofindices.len()points between (exclusive)aandb.points: list of points where the results of the calculation should end up. To be indexed by values inindices.
Implementors
impl BaseShape for CubeBase[src]
fn initial_points(&self) -> Vec<Vec3A>[src]
fn triangles(&self) -> Box<[Triangle]>[src]
const EDGES: usize[src]
fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A[src]
fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A[src]
fn interpolate_multiple(
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)[src]
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)
impl BaseShape for IcoSphereBase[src]
fn initial_points(&self) -> Vec<Vec3A>[src]
fn triangles(&self) -> Box<[Triangle]>[src]
const EDGES: usize[src]
fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A[src]
fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A[src]
fn interpolate_multiple(
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)[src]
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)
impl BaseShape for SquareBase[src]
fn initial_points(&self) -> Vec<Vec3A>[src]
fn triangles(&self) -> Box<[Triangle]>[src]
const EDGES: usize[src]
fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A[src]
fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A[src]
fn interpolate_multiple(
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)[src]
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)
impl BaseShape for TetraSphereBase[src]
fn initial_points(&self) -> Vec<Vec3A>[src]
fn triangles(&self) -> Box<[Triangle]>[src]
const EDGES: usize[src]
fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A[src]
fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A[src]
fn interpolate_multiple(
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)[src]
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)
impl BaseShape for TriangleBase[src]
fn initial_points(&self) -> Vec<Vec3A>[src]
fn triangles(&self) -> Box<[Triangle]>[src]
const EDGES: usize[src]
fn interpolate(&self, a: Vec3A, b: Vec3A, p: f32) -> Vec3A[src]
fn interpolate_half(&self, a: Vec3A, b: Vec3A) -> Vec3A[src]
fn interpolate_multiple(
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)[src]
&self,
a: Vec3A,
b: Vec3A,
indices: &[u32],
points: &mut [Vec3A]
)