Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
matrix:
os: [macOS-latest, ubuntu-latest, windows-latest]
toolchain:
- 1.43.0 # Minimum.
- 1.51.0 # Minimum.
- stable
- beta
- nightly
Expand All @@ -58,4 +58,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=plexus/Cargo.toml --all-features --verbose
args: --manifest-path=plexus/Cargo.toml --all-features --verbose
23 changes: 12 additions & 11 deletions pictor/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ where
}
}

impl<T> Into<Vector4<T>> for Color4<T>
impl<T> From<Color4<T>> for Vector4<T>
where
T: Scalar,
{
fn into(self) -> Vector4<T> {
self.0
fn from(color: Color4<T>) -> Self {
color.0
}
}

Expand Down Expand Up @@ -340,14 +340,15 @@ impl Application for RenderApplication {

fn react(&mut self, event: WindowEvent) -> Reaction {
match event {
WindowEvent::KeyboardInput { input, .. } => match input {
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
state: ElementState::Pressed,
..
} => Abort,
_ => Continue,
},
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
state: ElementState::Pressed,
..
},
..
} => Abort,
_ => Continue,
}
}
Expand Down
4 changes: 2 additions & 2 deletions plexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ geometry-ultraviolet = ["theon/geometry-ultraviolet"]
unstable = []

[dependencies]
approx = "^0.3.0"
approx = "^0.4.0"
ahash = "^0.6.0"
arrayvec = "^0.5.0"
arrayvec = "^0.6.0"
decorum = "^0.3.1"
derivative = "^2.1.1"
itertools = "^0.9.0"
Expand Down
21 changes: 13 additions & 8 deletions plexus/src/buffer/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use num::{Integer, NumCast, Unsigned};
use std::hash::Hash;
use typenum::{self, NonZero};
use typenum::NonZero;

use crate::buffer::{BufferError, MeshBuffer};
use crate::builder::{FacetBuilder, MeshBuilder, SurfaceBuilder};
use crate::constant::{Constant, ToType, TypeOf};
use crate::geometry::{FromGeometry, IntoGeometry};
use crate::index::{Flat, Grouping, IndexBuffer};
use crate::primitive::Topological;
Expand Down Expand Up @@ -46,28 +47,32 @@ where
type Input = ();
}

impl<A, N, G> FacetBuilder<N> for BufferBuilder<Flat<A, N>, G>
impl<K, G, const N: usize> FacetBuilder<K> for BufferBuilder<Flat<K, N>, G>
where
A: NonZero + typenum::Unsigned,
N: Copy + Hash + Integer + Unsigned,
Vec<N>: IndexBuffer<Flat<A, N>>,
Constant<N>: ToType,
TypeOf<N>: NonZero,
K: Copy + Hash + Integer + Unsigned,
Vec<K>: IndexBuffer<Flat<K, N>>,
{
type Facet = ();
type Key = ();

fn insert_facet<T, U>(&mut self, keys: T, _: U) -> Result<Self::Key, Self::Error>
where
Self::Facet: FromGeometry<U>,
T: AsRef<[N]>,
T: AsRef<[K]>,
{
let keys = keys.as_ref();
if keys.len() == A::USIZE {
if keys.len() == N {
self.indices.extend(keys.iter());
Ok(())
}
else {
// TODO: These numbers do not necessarily represent arity (i.e., the
// number of edges of each topological structure). Use a
// different error variant to express this.
Err(BufferError::ArityConflict {
expected: A::USIZE,
expected: N,
actual: keys.len(),
})
}
Expand Down
84 changes: 45 additions & 39 deletions plexus/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ use std::fmt::Debug;
use std::hash::Hash;
use std::iter::FromIterator;
use std::vec;
use theon::adjunct::{FromItems, Map};
use theon::adjunct::Map;
use thiserror::Error;
use typenum::{self, NonZero, Unsigned as _, U3, U4};

use crate::buffer::builder::BufferBuilder;
use crate::builder::{Buildable, MeshBuilder};
use crate::constant::{Constant, ToType, TypeOf};
use crate::encoding::{FaceDecoder, FromEncoding, VertexDecoder};
use crate::geometry::{FromGeometry, IntoGeometry};
use crate::index::{
Expand All @@ -109,7 +110,7 @@ use crate::primitive::{
BoundedPolygon, IntoIndexed, IntoPolygons, Polygonal, Tetragon, Topological, Trigon,
UnboundedPolygon,
};
use crate::{Arity, DynamicArity, MeshArity, Monomorphic, StaticArity};
use crate::{Arity, DynamicArity, MeshArity, Monomorphic, StaticArity, TryFromIterator};

/// Errors concerning raw buffers and [`MeshBuffer`]s.
///
Expand Down Expand Up @@ -223,13 +224,14 @@ pub trait FromRawBuffersWithArity<N, G>: Sized {

// TODO: Provide a similar trait for index buffers instead. `MeshBuffer` could
// use such a trait to provide this API.
pub trait IntoFlatIndex<A, G>
pub trait IntoFlatIndex<G, const N: usize>
where
A: NonZero + typenum::Unsigned,
Constant<N>: ToType,
TypeOf<N>: NonZero,
{
type Item: Copy + Integer + Unsigned;

fn into_flat_index(self) -> MeshBuffer<Flat<A, Self::Item>, G>;
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, N>, G>;
}

// TODO: Provide a similar trait for index buffers instead. `MeshBuffer` could
Expand Down Expand Up @@ -258,7 +260,7 @@ where
/// The `R` type parameter specifies the [`Grouping`] of the index buffer. See
/// the [`index`] module documention for more information.
///
/// [`Grouping`]: crate::buffer::Grouping
/// [`Grouping`]: crate::index::Grouping
/// [`index`]: crate::index
#[derive(Debug)]
pub struct MeshBuffer<R, G>
Expand Down Expand Up @@ -419,15 +421,16 @@ where
}
}

impl<A, N, G> DynamicArity for MeshBuffer<Flat<A, N>, G>
impl<T, G, const N: usize> DynamicArity for MeshBuffer<Flat<T, N>, G>
where
A: NonZero + typenum::Unsigned,
N: Copy + Integer + Unsigned,
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + Unsigned,
{
type Dynamic = <Flat<A, N> as StaticArity>::Static;
type Dynamic = <Flat<T, N> as StaticArity>::Static;

fn arity(&self) -> Self::Dynamic {
Flat::<A, N>::ARITY
Flat::<T, N>::ARITY
}
}

Expand Down Expand Up @@ -476,10 +479,11 @@ where
const ARITY: Self::Static = R::ARITY;
}

impl<A, N, G> MeshBuffer<Flat<A, N>, G>
impl<T, G, const N: usize> MeshBuffer<Flat<T, N>, G>
where
A: NonZero + typenum::Unsigned,
N: Copy + Integer + NumCast + Unsigned,
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
{
/// Appends the contents of a flat `MeshBuffer` into another `MeshBuffer`.
/// The source buffer is drained.
Expand All @@ -491,9 +495,9 @@ where
where
G: FromGeometry<H>,
R: Grouping,
R::Group: Into<<Flat<A, N> as Grouping>::Group>,
R::Group: Into<<Flat<T, N> as Grouping>::Group>,
{
let offset = N::from(self.vertices.len()).ok_or(BufferError::IndexOverflow)?;
let offset = T::from(self.vertices.len()).ok_or(BufferError::IndexOverflow)?;
self.vertices.extend(
buffer
.vertices
Expand Down Expand Up @@ -637,11 +641,12 @@ where
}
}

impl<A, N, M, G, H> FromRawBuffers<M, H> for MeshBuffer<Flat<A, N>, G>
impl<T, U, G, H, const N: usize> FromRawBuffers<U, H> for MeshBuffer<Flat<T, N>, G>
where
A: NonZero + typenum::Unsigned,
N: Copy + Integer + NumCast + Unsigned,
M: Copy + Integer + NumCast + Unsigned,
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + NumCast + Unsigned,
U: Copy + Integer + NumCast + Unsigned,
G: FromGeometry<H>,
{
type Error = BufferError;
Expand Down Expand Up @@ -686,22 +691,22 @@ where
/// ```
fn from_raw_buffers<I, J>(indices: I, vertices: J) -> Result<Self, BufferError>
where
I: IntoIterator<Item = M>,
I: IntoIterator<Item = U>,
J: IntoIterator<Item = H>,
{
let indices = indices
.into_iter()
.map(|index| <N as NumCast>::from(index).ok_or(BufferError::IndexOverflow))
.map(|index| <T as NumCast>::from(index).ok_or(BufferError::IndexOverflow))
.collect::<Result<Vec<_>, _>>()?;
if indices.len() % A::USIZE != 0 {
if indices.len() % N != 0 {
Err(BufferError::IndexUnaligned)
}
else {
let vertices: Vec<_> = vertices
.into_iter()
.map(|vertex| vertex.into_geometry())
.collect();
let len = N::from(vertices.len()).unwrap();
let len = T::from(vertices.len()).unwrap();
if indices.iter().any(|index| *index >= len) {
Err(BufferError::IndexOutOfBounds)
}
Expand Down Expand Up @@ -774,19 +779,20 @@ where
}
}

impl<A, N, G> IntoFlatIndex<A, G> for MeshBuffer<Flat<A, N>, G>
impl<T, G, const N: usize> IntoFlatIndex<G, N> for MeshBuffer<Flat<T, N>, G>
where
A: NonZero + typenum::Unsigned,
N: Copy + Integer + Unsigned,
Constant<N>: ToType,
TypeOf<N>: NonZero,
T: Copy + Integer + Unsigned,
{
type Item = N;
type Item = T;

fn into_flat_index(self) -> MeshBuffer<Flat<A, Self::Item>, G> {
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, N>, G> {
self
}
}

impl<N, G> IntoFlatIndex<U3, G> for MeshBuffer<Trigon<N>, G>
impl<N, G> IntoFlatIndex<G, 3> for MeshBuffer<Trigon<N>, G>
where
N: Copy + Integer + Unsigned,
{
Expand Down Expand Up @@ -821,7 +827,7 @@ where
/// // ...
/// }
/// ```
fn into_flat_index(self) -> MeshBuffer<Flat<U3, Self::Item>, G> {
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, 3>, G> {
let MeshBuffer { indices, vertices } = self;
MeshBuffer {
indices: indices
Expand All @@ -833,7 +839,7 @@ where
}
}

impl<N, G> IntoFlatIndex<U4, G> for MeshBuffer<Tetragon<N>, G>
impl<N, G> IntoFlatIndex<G, 4> for MeshBuffer<Tetragon<N>, G>
where
N: Copy + Integer + Unsigned,
{
Expand Down Expand Up @@ -868,7 +874,7 @@ where
/// // ...
/// }
/// ```
fn into_flat_index(self) -> MeshBuffer<Flat<U4, Self::Item>, G> {
fn into_flat_index(self) -> MeshBuffer<Flat<Self::Item, 4>, G> {
let MeshBuffer { indices, vertices } = self;
MeshBuffer {
indices: indices
Expand Down Expand Up @@ -901,7 +907,7 @@ where
.into_iter()
.map(|chunk| {
// These conversions should never fail.
Trigon::from_items(chunk.map(|index| {
Trigon::try_from_iter(chunk.map(|index| {
let index = <usize as NumCast>::from(index).expect("index overflow");
vertices[index].clone()
}))
Expand Down Expand Up @@ -960,7 +966,7 @@ where
.into_iter()
.map(|chunk| {
// These conversions should never fail.
Tetragon::from_items(chunk.map(|index| {
Tetragon::try_from_iter(chunk.map(|index| {
let index = <usize as NumCast>::from(index).expect("index overflow");
vertices[index].clone()
}))
Expand Down Expand Up @@ -1086,8 +1092,8 @@ where
.into_iter()
.chunks(U3::USIZE)
.into_iter()
.map(<Self::Item as Grouping>::Group::from_items)
.collect::<Option<Vec<_>>>()
.map(<Self::Item as Grouping>::Group::try_from_iter)
.collect::<Result<Vec<_>, _>>()
.expect("inconsistent index buffer");
MeshBuffer { indices, vertices }
}
Expand Down Expand Up @@ -1134,8 +1140,8 @@ where
.into_iter()
.chunks(U4::USIZE)
.into_iter()
.map(<Self::Item as Grouping>::Group::from_items)
.collect::<Option<Vec<_>>>()
.map(<Self::Item as Grouping>::Group::try_from_iter)
.collect::<Result<Vec<_>, _>>()
.expect("inconsistent index buffer");
MeshBuffer { indices, vertices }
}
Expand Down
Loading