1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//! # 2D Endomorphisms
//!
//! Mathematical transformations that map points from the unit square to itself.
//! These functions are commonly used in fractal systems, particularly Iterated
//! Function Systems (IFS), and provide various artistic and mathematical effects
//! for generative art applications.
//!
//! ## What are Endomorphisms?
//!
//! An endomorphism is a mathematical function that maps a space to itself.
//! In this context, all functions map points within or around the unit square
//! `[-1, 1] × [-1, 1]` to new positions, creating various visual effects.
//!
//! ## Available Transformations
//!
//! ### Trigonometric Functions
//! - [`sinusoid()`]: Applies sine function to both coordinates
//! - [`hankerchief()`]: Creates handkerchief-like distortions
//! - [`heart()`]: Creates heart-shaped transformations
//!
//! ### Geometric Transformations
//! - [`spherical()`]: Spherical inversion transformation
//! - [`swirl()`]: Creates swirling, spiral effects
//! - [`horseshoe()`]: Horseshoe-shaped transformation
//! - [`disc()`]: Disc-based coordinate transformation
//!
//! ### Coordinate System Changes
//! - [`to_polar()`]: Converts to polar coordinate representation
//!
//! ## Usage in Fractal Systems
//!
//! ```no_run
//! use wassily_algorithms::*;
//! use wassily_core::*;
//!
//! // Create an IFS (Iterated Function System)
//! let mut point = pt(0.5, 0.3);
//! let mut canvas = Canvas::new(800, 600);
//!
//! // Apply transformations iteratively
//! for _ in 0..10000 {
//! // Randomly choose a transformation
//! point = match rand::random::<u8>() % 3 {
//! 0 => swirl(point),
//! 1 => heart(point),
//! _ => spherical(point),
//! };
//!
//! // Plot the transformed point
//! let screen_x = (point.x + 1.0) * 400.0;
//! let screen_y = (point.y + 1.0) * 300.0;
//! canvas.dot(screen_x, screen_y, *WHITE);
//! }
//! ```
//!
//! ## Mathematical Properties
//!
//! Each transformation has unique mathematical properties:
//!
//! - **Continuous**: All transformations are continuous functions
//! - **Bounded**: Most transformations keep points within reasonable bounds
//! - **Differentiable**: Most functions are smooth and differentiable
//! - **Invertible**: Some transformations are invertible, others are not
//!
//! ## Applications
//!
//! - **Fractal Generation**: IFS fractals and strange attractors
//! - **Artistic Effects**: Distortion effects for images and shapes
//! - **Mathematical Visualization**: Studying function behavior
//! - **Animation**: Creating organic, flowing motion patterns
use ;
use Point;
use PI;
/// Applies the sine function to both x and y coordinates.
///
/// This transformation creates a grid-like pattern with curved boundaries,
/// mapping the input coordinates through sine functions.
///
/// # Example
/// ```no_run
/// use wassily_algorithms::sinusoid;
/// use wassily_core::pt;
///
/// let input = pt(1.0, 0.5);
/// let result = sinusoid(input);
/// ```
/// Spherical inversion transformation.
///
/// This transformation scales the point by its magnitude, creating a radial
/// distortion effect that resembles looking at the plane through a spherical lens.
///
/// # Example
/// ```no_run
/// use wassily_algorithms::spherical;
/// use wassily_core::pt;
///
/// let input = pt(0.5, 0.3);
/// let result = spherical(input);
/// ```
/// Creates a swirling, spiral transformation.
///
/// This transformation rotates points around the origin with the rotation
/// angle proportional to the square of the distance from the origin,
/// creating a spiral or whirlpool effect.
///
/// # Example
/// ```no_run
/// use wassily_algorithms::swirl;
/// use wassily_core::pt;
///
/// let input = pt(0.8, 0.2);
/// let result = swirl(input);
/// ```