From 90663563f879025d65c48418a8812104e43f083b Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 15 Nov 2024 08:19:00 -0500 Subject: [PATCH] Working on docs --- CHANGELOG.md | 6 +++--- fidget/src/mesh/octree.rs | 3 +-- fidget/src/render/config.rs | 15 ++++++++++----- fidget/src/render/region.rs | 17 ++++++++--------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eca781a..be4ad403 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,11 @@ - Add a new `RegionSize` type (with `ImageSize` and `VoxelSize` aliases), representing a render region. This type is responsible for the screen-to-world transform - - Add a new `Camera` type, which stores the world-to-model + - Add `View2` and `View3` types, which stores the world-to-model transform (scaling, panning, etc) - - Image rendering uses both `RegionSize` and `Camera`; this means that we + - Image rendering uses both `RegionSize` and `ViewX`; this means that we can now render non-square images! - - Meshing uses just the `Camera`, to position the model within the ±1 bounds + - Meshing uses just a `View3`, to position the model within the ±1 bounds - The previous `fidget::shape::Bounds` type is removed - Remove `fidget::render::render2d/3d` from the public API, as they're equivalent to the functions on `ImageRenderConfig` / `VoxelRenderConfig` diff --git a/fidget/src/mesh/octree.rs b/fidget/src/mesh/octree.rs index 5aa2661c..a21a3ac7 100644 --- a/fidget/src/mesh/octree.rs +++ b/fidget/src/mesh/octree.rs @@ -1581,11 +1581,10 @@ mod test { ..Default::default() }; let octree = Octree::build(&shape, settings); - let tc = threads.get().unwrap_or(1); assert_eq!( octree.cells[0], Cell::Empty.into(), - "failed to collapse octree with {tc} threads" + "failed to collapse octree with {threads} threads" ); } } diff --git a/fidget/src/render/config.rs b/fidget/src/render/config.rs index 0a52e9bd..12b5b9a5 100644 --- a/fidget/src/render/config.rs +++ b/fidget/src/render/config.rs @@ -1,6 +1,6 @@ use crate::{ eval::Function, - render::{RegionSize, RenderMode, View2, View3}, + render::{ImageSize, RenderMode, View2, View3, VoxelSize}, shape::{Shape, TileSizes}, }; use nalgebra::{Const, Matrix3, Matrix4, OPoint, Point2, Vector2}; @@ -15,6 +15,10 @@ pub enum ThreadCount { One, /// Spawn some number of worker threads for evaluation + /// + /// This can be set to `1`, in which case a single worker thread will be + /// spawned; this is different from doing work in the main thread, but not + /// particularly useful! #[cfg(not(target_arch = "wasm32"))] Many(std::num::NonZeroUsize), } @@ -30,6 +34,7 @@ impl From for ThreadCount { } } +/// Single-threaded mode is shown as `-`; otherwise, an integer impl std::fmt::Display for ThreadCount { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -68,7 +73,7 @@ impl Default for ThreadCount { /// Settings for 2D rendering pub struct ImageRenderConfig { /// Render size - pub image_size: RegionSize<2>, + pub image_size: ImageSize, /// World-to-model transform pub view: View2, @@ -87,7 +92,7 @@ pub struct ImageRenderConfig { impl Default for ImageRenderConfig { fn default() -> Self { Self { - image_size: RegionSize::from(512), + image_size: ImageSize::from(512), tile_sizes: TileSizes::new(&[128, 32, 8]).unwrap(), view: View2::default(), threads: ThreadCount::default(), @@ -117,7 +122,7 @@ pub struct VoxelRenderConfig { /// The resulting image will have the given width and height; depth sets the /// number of voxels to evaluate within each pixel of the image (stacked /// into a column going into the screen). - pub image_size: RegionSize<3>, + pub image_size: VoxelSize, /// World-to-model transform pub view: View3, @@ -136,7 +141,7 @@ pub struct VoxelRenderConfig { impl Default for VoxelRenderConfig { fn default() -> Self { Self { - image_size: RegionSize::from(512), + image_size: VoxelSize::from(512), tile_sizes: TileSizes::new(&[128, 64, 32, 16, 8]).unwrap(), view: View3::default(), diff --git a/fidget/src/render/region.rs b/fidget/src/render/region.rs index 9f41d317..66dcbc70 100644 --- a/fidget/src/render/region.rs +++ b/fidget/src/render/region.rs @@ -3,7 +3,7 @@ use nalgebra::{ DimNameSum, OMatrix, OVector, Vector2, Vector3, U1, }; -/// Image size in pixels, used to generate a screen to world matrix +/// Image size in pixels, used to generate a screen-to-world matrix /// /// The screen coordinate space is the following: /// @@ -36,17 +36,14 @@ use nalgebra::{ /// /// (with `+z` pointing out of the screen) /// -/// Note that the Y axis flips between screen and world coordinates: screen -/// coordinates have `+y` pointing down, but world coordinates have it pointing -/// up. For both X and Y coordinates, the `+1` value is located one pixel -/// beyond the edge of the screen region (off the right edge for X, and off the -/// top edge for Y). +/// Note that the Y axis is reversed between screen and world coordinates: +/// screen coordinates have `+y` pointing down, but world coordinates have it +/// pointing up. For both X and Y coordinates, the `+1` value is located one +/// pixel beyond the edge of the screen region (off the right edge for X, and +/// off the top edge for Y). /// /// If the render region is not square, then the shorter axis is clamped to ±1 /// and the longer axis will exceed that value. -/// -/// Apologies for the terrible trait bounds; they're necessary to persuade the -/// internals to type-check, but shouldn't be noticeable to library users. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct RegionSize where @@ -59,6 +56,8 @@ where size: OVector as DimNameAdd>>::Output as DimNameSub>>::Output>, } +/// Apologies for the terrible trait bounds; they're necessary to persuade the +/// internals to type-check, but shouldn't be noticeable to library users. impl RegionSize where Const: DimNameAdd,