Skip to content

Commit

Permalink
Various import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Canleskis committed Jan 15, 2024
1 parent 0674ac3 commit cb23e5a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
6 changes: 4 additions & 2 deletions particular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ gravitational forces between [`PointMass`]es, with variants optimised for scalar
##### Example

```rust
use particular::math::Vec2;

use storage::PointMass;

let p1 = PointMass::new(Vec2::new(0.0, 1.0), 1.0);
Expand Down Expand Up @@ -184,7 +186,7 @@ mass when computing the gravitational forces of particles.
##### Example

```rust
use storage::{ParticleOrdered, ParticleSystem, ParticleTree};
use particular::math::Vec3;

let particles = vec![
// ...
Expand Down Expand Up @@ -221,7 +223,7 @@ want to implement other algorithms.
##### Example

```rust
use storage::{ParticleReordered, ParticleSystem};
use particular::math::Vec3;

struct MyComputeMethod;

Expand Down
6 changes: 5 additions & 1 deletion particular/src/compute_method/gpu_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ impl WgpuResources {
buffer.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap());

device.poll(wgpu::Maintain::Wait);
receiver.recv_async().await.unwrap().unwrap();
receiver
.recv_async()
.await
.unwrap()
.expect("Could not read buffer");

let view = buffer.get_mapped_range();
// vec3<f32> is 16 byte aligned so we need to cast to a slice of `Vec4`.
Expand Down
13 changes: 7 additions & 6 deletions particular/src/compute_method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ pub mod parallel;
/// Compute methods that use one CPU thread.
pub mod sequential;

pub use storage::*;

/// Trait to perform a computation of values between objects contained in a storage of type `S`.
///
/// # Example
///
/// ```
/// # use particular::prelude::*;
/// # use ultraviolet::Vec3;
/// # use particular::math::Vec3;
///
/// struct AccelerationCalculator;
///
/// impl ComputeMethod<&[storage::PointMass<Vec3, f32>]> for AccelerationCalculator {
/// impl ComputeMethod<&[PointMass<Vec3, f32>]> for AccelerationCalculator {
/// type Output = Vec<Vec3>;
///
/// fn compute(&mut self, storage: &[storage::PointMass<Vec3, f32>]) -> Self::Output {
/// fn compute(&mut self, storage: &[PointMass<Vec3, f32>]) -> Self::Output {
/// // ...
/// # Vec::new()
/// # Vec::new()
/// }
/// }
/// ```
Expand All @@ -47,8 +49,7 @@ pub trait ComputeMethod<Storage> {

#[cfg(test)]
pub(crate) mod tests {
use crate::{compute_method::storage::PointMass, compute_method::ComputeMethod};
use ultraviolet::Vec3;
use crate::{math::Vec3, ComputeMethod, PointMass};

pub fn acceleration_error<C>(mut cm: C, epsilon: f32)
where
Expand Down
9 changes: 7 additions & 2 deletions particular/src/compute_method/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/// Bounding box related traits and types.
pub mod partition;

pub use partition::*;

use crate::compute_method::math::Float;
use partition::{BoundingBox, SizedOrthant, SubDivide};

/// Index of a [`Node`] in a [`Tree`].
pub type NodeID = u32;
Expand All @@ -22,6 +23,7 @@ pub struct Tree<Node, Data> {

impl<Node, Data> Tree<Node, Data> {
/// Creates a new empty [`Tree`].
#[inline]
pub fn new() -> Self {
Self {
nodes: Vec::new(),
Expand All @@ -31,6 +33,7 @@ impl<Node, Data> Tree<Node, Data> {

/// Creates a new empty [`Tree`] with at least the specified capacity in the `nodes` and `data`
/// vectors.
#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Self {
nodes: Vec::with_capacity(capacity),
Expand All @@ -40,6 +43,7 @@ impl<Node, Data> Tree<Node, Data> {
}

impl<Node, Data> Default for Tree<Node, Data> {
#[inline]
fn default() -> Self {
Self::new()
}
Expand All @@ -61,7 +65,8 @@ pub type Orthtree<const X: usize, const D: usize, S, Data> =

impl<const X: usize, const D: usize, S, Data> Orthtree<X, D, S, Data> {
/// Recursively inserts new [`Nodes`](Node) in the current [`Orthtree`] from the given input and
/// functions until the created square bounding box stops subdividing.
/// functions until the computed square bounding box stops subdividing.
#[inline]
pub fn build_node<I, P, C>(&mut self, input: &[I], position: P, compute: C) -> Option<NodeID>
where
I: Copy,
Expand Down
31 changes: 16 additions & 15 deletions particular/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
//! between two distinct collections of particles, or both at the same time.
//! In that case, you can use the backend directly by calling [compute] on a struct implementing
//! [`ComputeMethod`], passing in an appropriate storage.
//!
//!
//! #### The [`PointMass`] type
//!
//! The underlying type used in storages is the [`PointMass`], a simple representation in
Expand All @@ -178,8 +178,7 @@
//!
//! ```
//! # use particular::prelude::*;
//! # use ultraviolet::Vec2;
//! use storage::PointMass;
//! use particular::math::Vec2;
//!
//! let p1 = PointMass::new(Vec2::new(0.0, 1.0), 1.0);
//! let p2 = PointMass::new(Vec2::new(0.0, 0.0), 1.0);
Expand Down Expand Up @@ -207,10 +206,8 @@
//!
//! ```
//! # use particular::prelude::*;
//! # use storage::PointMass;
//! # use ultraviolet::Vec3;
//! use storage::{ParticleOrdered, ParticleSystem, ParticleTree};
//!
//! use particular::math::Vec3;
//!
//! let particles = vec![
//! // ...
//! # PointMass::new(Vec3::new(-10.0, 0.0, 0.0), 5.0),
Expand Down Expand Up @@ -252,8 +249,7 @@
//!
//! ```
//! # use particular::prelude::*;
//! # use ultraviolet::Vec3;
//! use storage::{ParticleReordered, ParticleSystem};
//! use particular::math::Vec3;
//!
//! struct MyComputeMethod;
//!
Expand Down Expand Up @@ -289,18 +285,23 @@
pub mod compute_method;
/// Traits for particle representation of objects and computing their acceleration.
pub mod particle;
/// Derive macro for the [`Particle`](crate::particle::Particle) trait.
pub mod particular_derive {
pub use particular_derive::Particle;
/// Built-in [`ComputeMethod`](crate::compute_method::ComputeMethod) implementations.
pub mod compute_methods {
#[cfg(feature = "gpu")]
pub use crate::compute_method::gpu;
#[cfg(feature = "parallel")]
pub use crate::compute_method::parallel;
pub use crate::compute_method::sequential;
}

pub use compute_method::*;
pub use particular_derive;

/// Most commonly used re-exported types.
/// Commonly used types, re-exported.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
compute_method::*,
compute_method::{storage::*, ComputeMethod},
compute_methods::*,
particle::{Accelerations, IntoPointMass, Particle},
particular_derive::Particle,
};
Expand Down

0 comments on commit cb23e5a

Please sign in to comment.