111 lines
2.8 KiB
Rust
111 lines
2.8 KiB
Rust
//! # Enkou
|
|
#![no_std]
|
|
#![deny(missing_docs)]
|
|
#![allow(clippy::needless_range_loop)] // SPIR-V backend has issues with iteration over items
|
|
|
|
pub mod camera;
|
|
pub mod chaos_game;
|
|
mod rng;
|
|
pub mod transform;
|
|
pub mod variation;
|
|
|
|
use glam::Affine2;
|
|
|
|
/// Utility trait to convert between `flam3` notation and [`glam`].
|
|
#[allow(missing_docs)]
|
|
pub trait Coefficients2 {
|
|
/// Convert affine transformation coefficients to the [`glam`] representation.
|
|
/// Parameters use the following form:
|
|
///
|
|
/// ```text
|
|
/// (a * x + b * y + c, d * x + e * y + f)
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// # use glam::{Affine2, vec2};
|
|
/// # use crate::enkou_shaders::Coefficients2;
|
|
/// let coefs = Affine2::from_coefficients(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
|
|
/// let (x, y) = (7.0, 8.0);
|
|
/// assert_eq!(
|
|
/// coefs.transform_point2(vec2(x, y)),
|
|
/// vec2(
|
|
/// coefs.a() * x + coefs.b() * y + coefs.c(),
|
|
/// coefs.d() * x + coefs.e() * y + coefs.f()
|
|
/// )
|
|
/// );
|
|
/// ```
|
|
fn from_coefficients(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) -> Affine2;
|
|
|
|
/// Convert affine transformation coefficients to the [`glam`] representation.
|
|
/// Parameters use the following form:
|
|
///
|
|
/// ```text
|
|
/// (a * x + b * y + c, d * x + e * y + f)
|
|
/// ```
|
|
///
|
|
/// ```
|
|
/// # use glam::{Affine2, vec2};
|
|
/// # use crate::enkou_shaders::Coefficients2;
|
|
/// let coefs = Affine2::from_coefficients_arr([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
|
|
/// let (x, y) = (7.0, 8.0);
|
|
/// assert_eq!(
|
|
/// coefs.transform_point2(vec2(x, y)),
|
|
/// vec2(
|
|
/// coefs.a() * x + coefs.b() * y + coefs.c(),
|
|
/// coefs.d() * x + coefs.e() * y + coefs.f()
|
|
/// )
|
|
/// );
|
|
/// ```
|
|
fn from_coefficients_arr(coefficients: [f32; 6]) -> Affine2;
|
|
|
|
fn a(&self) -> f32;
|
|
fn b(&self) -> f32;
|
|
fn c(&self) -> f32;
|
|
fn d(&self) -> f32;
|
|
fn e(&self) -> f32;
|
|
fn f(&self) -> f32;
|
|
}
|
|
|
|
impl Coefficients2 for Affine2 {
|
|
#[inline]
|
|
fn from_coefficients(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) -> Affine2 {
|
|
Affine2::from_cols_array(&[a, d, b, e, c, f])
|
|
}
|
|
|
|
#[inline]
|
|
fn from_coefficients_arr(coefficients: [f32; 6]) -> Affine2 {
|
|
Affine2::from_coefficients(
|
|
coefficients[0],
|
|
coefficients[1],
|
|
coefficients[2],
|
|
coefficients[3],
|
|
coefficients[4],
|
|
coefficients[5],
|
|
)
|
|
}
|
|
|
|
fn a(&self) -> f32 {
|
|
self.matrix2.x_axis.x
|
|
}
|
|
|
|
fn b(&self) -> f32 {
|
|
self.matrix2.y_axis.x
|
|
}
|
|
|
|
fn c(&self) -> f32 {
|
|
self.translation.x
|
|
}
|
|
|
|
fn d(&self) -> f32 {
|
|
self.matrix2.x_axis.y
|
|
}
|
|
|
|
fn e(&self) -> f32 {
|
|
self.matrix2.y_axis.y
|
|
}
|
|
|
|
fn f(&self) -> f32 {
|
|
self.translation.y
|
|
}
|
|
}
|