Implement basic variation support
CI / cargo fmt (push) Successful in 24s
CI / cargo test (push) Failing after 26s
CI / cargo test (GPU) (push) Successful in 17m57s

This commit is contained in:
2026-06-27 15:11:23 -04:00
parent df747855b6
commit 6671475c75
4 changed files with 127 additions and 8 deletions
+23 -4
View File
@@ -3,24 +3,43 @@
//! Transforms are the "functions" in an iterated function system. They take in a point,
//! and generate a new point. For fractal flames, transforms are always affine,
//! but produce more interesting images once we add variations.
use crate::variation::Variation;
use bytemuck::{Pod, Zeroable};
use glam::{Affine2, Vec2};
use rand::Rng;
/// Affine transform for use in the [`chaos_game`](crate::chaos_game).
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct Transform {
coefficients: Affine2,
variation_range: [u16; 2],
}
impl Transform {
/// Create a new transform from an affine transformation matrix
pub fn new(coefficients: Affine2) -> Self {
Transform { coefficients }
pub fn new(coefficients: Affine2, variation_range: [u16; 2]) -> Self {
Transform {
coefficients,
variation_range,
}
}
/// Apply this transform to a point in IFS coordinates, producing a new point
pub fn transform_point(&self, point: Vec2) -> Vec2 {
self.coefficients.transform_point2(point)
pub fn transform_point<R: Rng>(
&self,
rng: &mut R,
variations: &[Variation],
point: Vec2,
) -> Vec2 {
let point = self.coefficients.transform_point2(point);
let mut point_output = Vec2::ZERO;
let variation_range = self.variation_range[0] as usize..self.variation_range[1] as usize;
for variation in variations[variation_range].iter() {
point_output += variation.transform_point(point, rng, &self.coefficients)
}
point_output
}
}