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
use crate::{
defaults,
options::{Intersections, Lines, Triangle, Color},
pattern_utils::Angle,
};
use super::{defaults::constants, CollisionOption, Point};
#[derive(Clone, Debug, PartialEq, PartialOrd)]
///Main struct for all pattern rendering options
pub struct GridOptions {
///Thickness of line in relation to distance between points
/// eg. if the line_thickness = 0.1, and the distance between points is 10 pixels,
/// then the line_thickness would be 1 pixel
pub line_thickness: f32,
///Further options for how to render each pattern
pub pattern_options: GridPatternOptions,
///Optional point to place in the center of each pattern (helps with determining pattern size at a glance)
pub center_dot: Point,
}
#[allow(dead_code)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
///Struct that holds the different variations of GridPatterns
pub enum GridPatternOptions {
///Uniform means that all patterns will be rendered in the same way
/// (This excludes the difference with PatternVariant)
Uniform(Intersections, Lines),
///Changes what pattern renderer to use when finding an introspect or retrospect pattern
/// That way you can change colors/renderers for embedded patterns
Changing {
///Variations to use, starts at the first and goes up when it reaches an intro, goes down when reaching a retro
variations: Vec<(Intersections, Lines)>,
///Vec of the angle_sigs of intro patterns
intros: Vec<Vec<Angle>>,
///Vec of angle_sigs of retro patterns
retros: Vec<Vec<Angle>>,
},
}
impl GridOptions {
///Helper function that creates a new [GridOptions] using the default line_thickness: [constants::LINE_THICKNESS]
pub fn generate(pattern_options: GridPatternOptions, center_dot: Point) -> Self {
Self {
line_thickness: constants::LINE_THICKNESS,
pattern_options,
center_dot,
}
}
}
impl GridPatternOptions {
///Generates a changing [GridPatternOptions] where the [Intersections] options are copied among all variations
pub fn generate_changing(
intersection: Intersections,
lines: Vec<Lines>,
intros: Vec<Vec<Angle>>,
retros: Vec<Vec<Angle>>,
) -> Self {
let mut parts = Vec::new();
for line in lines {
parts.push((intersection, line));
}
Self::Changing {
variations: parts,
intros,
retros,
}
}
///Same as generate_changing except it uses the angle_sigs for Introspection and Retrospection
pub fn generate_default_changing(intersection: Intersections, lines: Vec<Lines>) -> Self {
Self::generate_changing(
intersection,
lines,
defaults::INTRO_ANGLES.to_vec(),
defaults::RETRO_ANGLES.to_vec(),
)
}
///Generates a changing [GridPatternOptions] where all the variations are a Monocolor renderer
pub fn gen_changing_monocolor(
intersection: Intersections,
colors: Vec<Color>,
bent: bool,
) -> Self {
GridPatternOptions::generate_default_changing(
intersection,
colors
.into_iter()
.map(|color| Lines::Monocolor { color, bent })
.collect(),
)
}
///Generates a changing [GridPatternOptions] where all the variations are a Gradient renderer
pub fn gen_changing_gradient(
intersection: Intersections,
colors: Vec<Vec<Color>>,
bent: bool,
) -> Self {
GridPatternOptions::generate_default_changing(
intersection,
colors
.into_iter()
.map(|colors| Lines::Gradient {
colors,
segments_per_color: constants::SEGS_PER_COLOR,
bent,
})
.collect(),
)
}
///Generates a changing [GridPatternOptions] where all the variations are a Segment renderer
pub fn gen_changing_segment(
intersection: Intersections,
colors: Vec<Vec<Color>>,
triangles: Triangle,
collisions: CollisionOption,
) -> Self {
Self::generate_default_changing(
intersection,
colors
.into_iter()
.map(|colors| Lines::SegmentColors {
colors,
triangles,
collisions,
})
.collect(),
)
}
}
impl GridOptions {
pub fn get_max_radius(&self) -> f32 {
self.line_thickness
.max(self.center_dot.get_max_radius())
.max(self.pattern_options.get_max_radius())
}
}
impl GridPatternOptions {
pub fn get_max_radius(&self) -> f32 {
match self {
GridPatternOptions::Uniform(intersection, line) => {
intersection.get_max_radius().max(line.get_max_radius())
}
GridPatternOptions::Changing {
variations,
intros: _,
retros: _,
} => variations
.iter()
.map(|part| part.0.get_max_radius().max(part.1.get_max_radius()))
.fold(0.0, |a, b| a.max(b)),
}
}
}