Implement a basic Sierpinski Gasket IFS
CI / cargo fmt (push) Failing after 1m23s
CI / cargo test (push) Failing after 33s
CI / cargo test (GPU) (push) Successful in 20m4s

This commit is contained in:
2026-06-22 20:46:47 -04:00
parent 90f886f971
commit beb1c8526f
8 changed files with 1103 additions and 56 deletions
+20 -1
View File
@@ -5,6 +5,7 @@ use libm::powf;
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct Camera {
dimensions: UVec2,
transform: Affine2,
}
@@ -39,7 +40,10 @@ impl Camera {
* zoom_transform
* ifs_center_transform;
Camera { transform }
Camera {
dimensions,
transform,
}
}
/// Map a point from IFS coordinates to pixel coordinates.
@@ -62,6 +66,21 @@ impl Camera {
pub fn transform_point(&self, point: Vec2) -> IVec2 {
self.transform.transform_point2(point).as_ivec2()
}
/// Map a point from IFS coordinates to pixel coordinates (like [`transform_point`]),
/// and check that the result is within the provided image dimensions.
pub fn transform_point_to_image(&self, point: Vec2) -> Option<UVec2> {
let pixel_coordinates = self.transform_point(point);
if pixel_coordinates.x < 0
|| pixel_coordinates.y < 0
|| (pixel_coordinates.x as u32) >= self.dimensions.x
|| (pixel_coordinates.y as u32) >= self.dimensions.y
{
None
} else {
Some(pixel_coordinates.as_uvec2())
}
}
}
#[cfg(test)]