Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some optional serde implementations, as well as .clone on BVH #74

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rand = "0.8"
log = "0.4"
num = "0.4"
glam = "0.18"
serde = { optional = true, version = "1", features = ["derive"] }

[dev-dependencies]
proptest = "1.0"
Expand All @@ -28,6 +29,8 @@ criterion = "0.3"

[features]
bench = []
# Unfortunately can't use "serde" as the feature name until https://github.com/rust-lang/cargo/issues/5565 lands
serde_impls = ["serde", "glam/serde"]

[profile.release]
lto = true
Expand Down
1 change: 1 addition & 0 deletions src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::axis::Axis;

/// AABB struct.
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::upper_case_acronyms)]
pub struct AABB {
/// Minimum coordinates
Expand Down
3 changes: 3 additions & 0 deletions src/bvh/bvh_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::f32;
/// [`BVH`]: struct.BVHNode.html
///
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::upper_case_acronyms)]
pub enum BVHNode {
/// Leaf node.
Expand Down Expand Up @@ -402,6 +403,8 @@ impl BVHNode {
/// [`BVH`]: struct.BVH.html
///
#[allow(clippy::upper_case_acronyms)]
#[derive(Clone)]
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))]
pub struct BVH {
/// The list of nodes of the [`BVH`].
///
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
//! let hit_sphere_aabbs = bvh.traverse(&ray, &spheres);
//! ```
//!
//! ## Features
//!
//! - `serde_impls` (default **disabled**) - adds `Serialize` and `Deserialize` implementations for some types
//!

#![deny(missing_docs)]
#![cfg_attr(feature = "bench", feature(test))]
Expand Down