@@ -114,107 +114,109 @@ pub fn draw_overlays(
114
114
}
115
115
}
116
116
}
117
- }
118
- }
119
-
120
- for wall in circ_walls_overlay. iter ( ) {
121
- let mut b_x = 0i32 ;
122
- let mut b_y = wall. radius as i32 ;
123
- let mut d = 1 - wall. radius as i32 ;
124
- // TODO: don't name this var _thickness_, also it is in px
125
- let thickness = 5 ;
126
- while b_x <= b_y {
127
- for ( x, y, t_x, t_y) in [
128
- (
129
- wall. center . x as i32 + b_x,
130
- wall. center . y as i32 + b_y,
131
- 1 ,
132
- -thickness,
133
- ) , // 0
134
- (
135
- wall. center . x as i32 + b_x,
136
- wall. center . y as i32 - b_y,
137
- 1 ,
138
- thickness,
139
- ) , // 1
140
- (
141
- wall. center . x as i32 - b_x,
142
- wall. center . y as i32 + b_y,
143
- 1 ,
144
- -thickness,
145
- ) , // 2
146
- (
147
- wall. center . x as i32 - b_x,
148
- wall. center . y as i32 - b_y,
149
- 1 ,
150
- thickness,
151
- ) , // 3
152
- (
153
- wall. center . x as i32 + b_y,
154
- wall. center . y as i32 + b_x,
155
- -thickness,
156
- 1 ,
157
- ) , // 4
158
- (
159
- wall. center . x as i32 + b_y,
160
- wall. center . y as i32 - b_x,
161
- -thickness,
162
- 1 ,
163
- ) , // 5
164
- (
165
- wall. center . x as i32 - b_y,
166
- wall. center . y as i32 + b_x,
167
- thickness,
168
- 1 ,
169
- ) , // 6
170
- (
171
- wall. center . x as i32 - b_y,
172
- wall. center . y as i32 - b_x,
173
- thickness,
174
- 1 ,
175
- ) , // 7
176
- ] {
177
- if x >= 0 && x < SIMULATION_WIDTH as i32 && y >= 0 && y < SIMULATION_HEIGHT as i32 {
178
- // angle in [0, 2pi)
179
- let mut angle = if ( y - wall. center . y as i32 ) <= 0 {
180
- ( ( x as f32 - wall. center . x as f32 ) / wall. radius as f32 ) . acos ( )
181
- } else {
182
- TAU - ( ( x as f32 - wall. center . x as f32 ) / wall. radius as f32 ) . acos ( )
183
- } ;
184
-
185
- angle = ( angle + wall. rotation_angle . to_radians ( ) ) % TAU ;
186
-
187
- if angle >= wall. open_circ_segment . to_radians ( ) / 2.
188
- && angle <= TAU - wall. open_circ_segment . to_radians ( ) / 2.
189
- || !wall. is_hollow
117
+ } else {
118
+ let mut b_x = 0i32 ;
119
+ let mut b_y = wall. radius as i32 ;
120
+ let mut d = 1 - wall. radius as i32 ;
121
+ // TODO: don't name this var _thickness_, also it is in px
122
+ let thickness = 5 ;
123
+ while b_x <= b_y {
124
+ for ( x, y, t_x, t_y) in [
125
+ (
126
+ wall. center . x as i32 + b_x,
127
+ wall. center . y as i32 + b_y,
128
+ 1 ,
129
+ -thickness,
130
+ ) , // 0
131
+ (
132
+ wall. center . x as i32 + b_x,
133
+ wall. center . y as i32 - b_y,
134
+ 1 ,
135
+ thickness,
136
+ ) , // 1
137
+ (
138
+ wall. center . x as i32 - b_x,
139
+ wall. center . y as i32 + b_y,
140
+ 1 ,
141
+ -thickness,
142
+ ) , // 2
143
+ (
144
+ wall. center . x as i32 - b_x,
145
+ wall. center . y as i32 - b_y,
146
+ 1 ,
147
+ thickness,
148
+ ) , // 3
149
+ (
150
+ wall. center . x as i32 + b_y,
151
+ wall. center . y as i32 + b_x,
152
+ -thickness,
153
+ 1 ,
154
+ ) , // 4
155
+ (
156
+ wall. center . x as i32 + b_y,
157
+ wall. center . y as i32 - b_x,
158
+ -thickness,
159
+ 1 ,
160
+ ) , // 5
161
+ (
162
+ wall. center . x as i32 - b_y,
163
+ wall. center . y as i32 + b_x,
164
+ thickness,
165
+ 1 ,
166
+ ) , // 6
167
+ (
168
+ wall. center . x as i32 - b_y,
169
+ wall. center . y as i32 - b_x,
170
+ thickness,
171
+ 1 ,
172
+ ) , // 7
173
+ ] {
174
+ if x >= 0
175
+ && x < SIMULATION_WIDTH as i32
176
+ && y >= 0
177
+ && y < SIMULATION_HEIGHT as i32
190
178
{
191
- for cur_x in if t_x > 0 { 0 ..t_x } else { ( t_x + 1 ) ..1 } {
192
- for cur_y in if t_y > 0 { 0 ..t_y } else { ( t_y + 1 ) ..1 } {
193
- let index =
194
- ( x + cur_x) as u32 + ( y + cur_y) as u32 * SIMULATION_WIDTH ;
195
- let r = raw_pixles[ index as usize ] . r ;
196
- let g = raw_pixles[ index as usize ] . g ;
197
- let b = raw_pixles[ index as usize ] . b ;
198
-
199
- raw_pixles[ index as usize ] = Pixel {
200
- r : map_range ( 0 , 255 , 100 , 175 , r as u32 ) as u8 ,
201
- g : map_range ( 0 , 255 , 80 , 80 , g as u32 ) as u8 ,
202
- b : map_range ( 0 , 255 , 80 , 80 , b as u32 ) as u8 ,
203
- a : 255 ,
204
- } ;
179
+ // angle in [0, 2pi)
180
+ let mut angle = if ( y - wall. center . y as i32 ) <= 0 {
181
+ ( ( x as f32 - wall. center . x as f32 ) / wall. radius as f32 ) . acos ( )
182
+ } else {
183
+ TAU - ( ( x as f32 - wall. center . x as f32 ) / wall. radius as f32 ) . acos ( )
184
+ } ;
185
+
186
+ angle = ( angle + wall. rotation_angle . to_radians ( ) ) % TAU ;
187
+
188
+ if angle >= wall. open_circ_segment . to_radians ( ) / 2.
189
+ && angle <= TAU - wall. open_circ_segment . to_radians ( ) / 2.
190
+ || !wall. is_hollow
191
+ {
192
+ for cur_x in if t_x > 0 { 0 ..t_x } else { ( t_x + 1 ) ..1 } {
193
+ for cur_y in if t_y > 0 { 0 ..t_y } else { ( t_y + 1 ) ..1 } {
194
+ let index =
195
+ ( x + cur_x) as u32 + ( y + cur_y) as u32 * SIMULATION_WIDTH ;
196
+ let r = raw_pixles[ index as usize ] . r ;
197
+ let g = raw_pixles[ index as usize ] . g ;
198
+ let b = raw_pixles[ index as usize ] . b ;
199
+
200
+ raw_pixles[ index as usize ] = Pixel {
201
+ r : map_range ( 0 , 255 , 100 , 175 , r as u32 ) as u8 ,
202
+ g : map_range ( 0 , 255 , 80 , 80 , g as u32 ) as u8 ,
203
+ b : map_range ( 0 , 255 , 80 , 80 , b as u32 ) as u8 ,
204
+ a : 255 ,
205
+ } ;
206
+ }
205
207
}
206
208
}
207
209
}
208
210
}
209
- }
210
211
211
- if d < 0 {
212
- d = d + 2 * b_x + 3 ;
213
- b_x += 1 ;
214
- } else {
215
- d = d + 2 * ( b_x - b_y) + 5 ;
216
- b_x += 1 ;
217
- b_y -= 1 ;
212
+ if d < 0 {
213
+ d = d + 2 * b_x + 3 ;
214
+ b_x += 1 ;
215
+ } else {
216
+ d = d + 2 * ( b_x - b_y) + 5 ;
217
+ b_x += 1 ;
218
+ b_y -= 1 ;
219
+ }
218
220
}
219
221
}
220
222
}
0 commit comments