Skip to content

Commit

Permalink
Working on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Nov 15, 2024
1 parent e6fe8a5 commit 9066356
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
- Add a new `RegionSize<const N: usize>` type (with `ImageSize` and
`VoxelSize` aliases), representing a render region. This type is
responsible for the screen-to-world transform
- Add a new `Camera<const N: usize>` 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`
Expand Down
3 changes: 1 addition & 2 deletions fidget/src/mesh/octree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Expand Down
15 changes: 10 additions & 5 deletions fidget/src/render/config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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),
}
Expand All @@ -30,6 +34,7 @@ impl From<std::num::NonZeroUsize> 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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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(),

Expand Down
17 changes: 8 additions & 9 deletions fidget/src/render/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down Expand Up @@ -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<const N: usize>
where
Expand All @@ -59,6 +56,8 @@ where
size: OVector<u32, <<Const<N> as DimNameAdd<Const<1>>>::Output as DimNameSub<Const<1>>>::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<const N: usize> RegionSize<N>
where
Const<N>: DimNameAdd<U1>,
Expand Down

0 comments on commit 9066356

Please sign in to comment.