Trait Geometry

Source
pub trait Geometry: Sized {
    type Vertex: Clone;
    type Arc: Clone + Default;
    type Edge: Clone + Default;
    type Face: Clone + Default;
}
Expand description

Graph geometry.

Specifies the types used to represent geometry for vertices, arcs, edges, and faces in a graph. Arbitrary types can be used, including () for no geometry at all.

Geometry is vertex-based. Geometric operations depend on understanding the positional data in vertices, and operational traits mostly apply to such positional data.

§Examples

use decorum::R64;
use nalgebra::{Point3, Vector4};
use num::One;
use plexus::geometry::convert::{AsPosition, IntoGeometry};
use plexus::geometry::Geometry;
use plexus::graph::MeshGraph;
use plexus::prelude::*;
use plexus::primitive::sphere::UvSphere;

// Vertex-only geometry with a position and color.
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct VertexGeometry {
    pub position: Point3<R64>,
    pub color: Vector4<R64>,
}

impl Geometry for VertexGeometry {
    type Vertex = Self;
    type Arc = ();
    type Edge = ();
    type Face = ();
}

impl AsPosition for VertexGeometry {
    type Target = Point3<R64>;

    fn as_position(&self) -> &Self::Target {
        &self.position
    }

    fn as_position_mut(&mut self) -> &mut Self::Target {
        &mut self.position
    }
}

// Create a mesh from a sphere primitive and map the geometry data.
let mut graph = UvSphere::new(8, 8)
    .polygons_with_position()
    .map_vertices(|position| VertexGeometry {
        position: position.into_geometry(),
        color: Vector4::new(One::one(), One::one(), One::one(), One::one()),
    })
    .collect::<MeshGraph<VertexGeometry>>();

Required Associated Types§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Geometry for ()

Source§

impl<T> Geometry for Point2<T>
where T: Clone,

Source§

impl<T> Geometry for Point3<T>
where T: Clone,

Source§

impl<T> Geometry for Point2<T>
where T: Clone,

Source§

impl<T> Geometry for Point3<T>
where T: Clone,

Source§

impl<T> Geometry for Point2<T>
where T: Scalar,

Source§

impl<T> Geometry for Point3<T>
where T: Scalar,

Implementors§

Source§

impl<T> Geometry for Duplet<T>
where T: Clone,

Source§

impl<T> Geometry for Triplet<T>
where T: Clone,