Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
Y, Z; otherwise, `Shape::bind` must be used. This removes a potential
`unwrap()` during rendering, because evaluation requires all variables to be
present.
- Rename `trait ImageSizeLike` to `trait RenderSize` in `fidget_raster`; remove
`width` and `height` from `trait RenderConfig` and add a `RenderConfig:
RenderSize` bound

# 0.4.3
- Fixed bug in x86 interval `OR` function ([#395](https://github.com/mkeeter/fidget/pull/395)),
Expand Down
34 changes: 16 additions & 18 deletions fidget-raster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,19 @@ where
}

/// Helper trait for tiled rendering configuration
pub(crate) trait RenderConfig {
fn width(&self) -> u32;
fn height(&self) -> u32;
pub(crate) trait RenderConfig: RenderSize {
fn threads(&self) -> Option<&ThreadPool>;
fn is_cancelled(&self) -> bool;
}

/// Trait for things that have a width and height in pixels
pub trait RenderSize {
/// Width of the render, in voxels or pixels
fn width(&self) -> u32;
/// Height of the render, in voxels or pixels
fn height(&self) -> u32;
}

/// Helper trait for a tiled renderer worker
pub(crate) trait RenderWorker<'a, F: Function> {
type Config: RenderConfig;
Expand Down Expand Up @@ -215,15 +221,7 @@ pub struct Image<P, S = ImageSize> {
size: S,
}

/// Helper trait to make images generic across image size types
pub trait ImageSizeLike {
/// Returns the width of the region, in pixels / voxels
fn width(&self) -> u32;
/// Returns the height of the region, in pixels / voxels
fn height(&self) -> u32;
}

impl ImageSizeLike for pixel::RenderSize {
impl RenderSize for pixel::RenderSize {
fn width(&self) -> u32 {
self.width()
}
Expand All @@ -232,7 +230,7 @@ impl ImageSizeLike for pixel::RenderSize {
}
}

impl ImageSizeLike for voxel::RenderSize {
impl RenderSize for voxel::RenderSize {
fn width(&self) -> u32 {
self.width()
}
Expand All @@ -241,7 +239,7 @@ impl ImageSizeLike for voxel::RenderSize {
}
}

impl<P: Send, S: ImageSizeLike + Sync> Image<P, S> {
impl<P: Send, S: RenderSize + Sync> Image<P, S> {
/// Generates an image by computing a per-pixel function
///
/// This should be called on the _output_ image; the closure takes `(x, y)`
Expand Down Expand Up @@ -282,7 +280,7 @@ impl<P, S: Default> Default for Image<P, S> {
}
}

impl<P: Default + Clone, S: ImageSizeLike> Image<P, S> {
impl<P: Default + Clone, S: RenderSize> Image<P, S> {
/// Builds a new image filled with `P::default()`
pub fn new(size: S) -> Self {
Self {
Expand Down Expand Up @@ -316,7 +314,7 @@ impl<P, S: Clone> Image<P, S> {
}
}

impl<P, S: ImageSizeLike> Image<P, S> {
impl<P, S: RenderSize> Image<P, S> {
/// Returns the image width
pub fn width(&self) -> usize {
self.size.width() as usize
Expand Down Expand Up @@ -434,15 +432,15 @@ define_image_index!(std::ops::RangeToInclusive<usize>);
define_image_index!(std::ops::RangeFull);

/// Indexes an image with `(row, col)`
impl<P, S: ImageSizeLike> std::ops::Index<(usize, usize)> for Image<P, S> {
impl<P, S: RenderSize> std::ops::Index<(usize, usize)> for Image<P, S> {
type Output = P;
fn index(&self, pos: (usize, usize)) -> &Self::Output {
let index = self.decode_position(pos);
&self.data[index]
}
}

impl<P, S: ImageSizeLike> std::ops::IndexMut<(usize, usize)> for Image<P, S> {
impl<P, S: RenderSize> std::ops::IndexMut<(usize, usize)> for Image<P, S> {
fn index_mut(&mut self, pos: (usize, usize)) -> &mut Self::Output {
let index = self.decode_position(pos);
&mut self.data[index]
Expand Down
20 changes: 11 additions & 9 deletions fidget-raster/src/pixel.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 2D bitmap rendering / rasterization
use super::RenderHandle;
use crate::{
Image as GenericImage, RenderConfig as RenderConfigLike, RenderWorker,
Tile, TileSizesRef,
Image as GenericImage, RenderSize as _, RenderWorker, Tile, TileSizesRef,
};
use fidget_core::{
eval::Function,
Expand Down Expand Up @@ -63,13 +62,7 @@ impl Default for RenderConfig<'_> {
}
}

impl RenderConfigLike for RenderConfig<'_> {
fn width(&self) -> u32 {
self.image_size.width()
}
fn height(&self) -> u32 {
self.image_size.height()
}
impl crate::RenderConfig for RenderConfig<'_> {
fn threads(&self) -> Option<&ThreadPool> {
self.threads
}
Expand All @@ -78,6 +71,15 @@ impl RenderConfigLike for RenderConfig<'_> {
}
}

impl crate::RenderSize for RenderConfig<'_> {
fn width(&self) -> u32 {
self.image_size.width()
}
fn height(&self) -> u32 {
self.image_size.height()
}
}

impl RenderConfig<'_> {
/// Render a shape in 2D using this configuration
///
Expand Down
20 changes: 11 additions & 9 deletions fidget-raster/src/voxel.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! 3D bitmap rendering / rasterization
use super::RenderHandle;
use crate::{
Image as GenericImage, RenderConfig as RenderConfigLike, RenderWorker,
Tile, TileSizesRef,
Image as GenericImage, RenderSize as _, RenderWorker, Tile, TileSizesRef,
};
use fidget_core::{
eval::Function,
Expand Down Expand Up @@ -62,13 +61,7 @@ impl Default for RenderConfig<'_> {
}
}

impl RenderConfigLike for RenderConfig<'_> {
fn width(&self) -> u32 {
self.image_size.width()
}
fn height(&self) -> u32 {
self.image_size.height()
}
impl crate::RenderConfig for RenderConfig<'_> {
fn threads(&self) -> Option<&ThreadPool> {
self.threads
}
Expand All @@ -77,6 +70,15 @@ impl RenderConfigLike for RenderConfig<'_> {
}
}

impl crate::RenderSize for RenderConfig<'_> {
fn width(&self) -> u32 {
self.image_size.width()
}
fn height(&self) -> u32 {
self.image_size.height()
}
}

impl RenderConfig<'_> {
/// Render a shape in 3D using this configuration
///
Expand Down
Loading
Loading