@@ -43,7 +43,7 @@ struct Triangle {
43
43
c : Point ,
44
44
color : Option < Rgba < u8 > > ,
45
45
46
- spanDiv : Option < f32 > ,
46
+ span_div : Option < f32 > ,
47
47
}
48
48
49
49
impl Triangle {
@@ -53,36 +53,36 @@ impl Triangle {
53
53
b : b,
54
54
c : c,
55
55
color : None ,
56
- spanDiv : None ,
56
+ span_div : None ,
57
57
}
58
58
}
59
59
60
- fn spanDivSave ( & mut self ) {
61
- self . spanDiv = Some ( self . spanDiv ( ) ) ;
60
+ fn span_div_save ( & mut self ) {
61
+ self . span_div = Some ( self . span_div ( ) ) ;
62
62
}
63
63
64
- fn spanDiv ( & self ) -> f32 {
65
- match self . spanDiv {
64
+ fn span_div ( & self ) -> f32 {
65
+ match self . span_div {
66
66
Some ( div) => div,
67
67
None => {
68
- let spanA = Point { x : self . b . x - self . a . x , y : self . b . y - self . a . y } ;
69
- let spanB = Point { x : self . c . x - self . a . x , y : self . c . y - self . a . y } ;
68
+ let span_a = Point { x : self . b . x - self . a . x , y : self . b . y - self . a . y } ;
69
+ let span_b = Point { x : self . c . x - self . a . x , y : self . c . y - self . a . y } ;
70
70
71
- 1.0 / spanA . cross_product ( spanB ) as f32
71
+ 1.0 / span_a . cross_product ( span_b ) as f32
72
72
}
73
73
}
74
74
}
75
75
}
76
76
77
77
impl Primitive for Triangle {
78
78
fn is_inside_primitive ( & self , p : Point ) -> bool {
79
- let spanA = Point { x : self . b . x - self . a . x , y : self . b . y - self . a . y } ;
80
- let spanB = Point { x : self . c . x - self . a . x , y : self . c . y - self . a . y } ;
79
+ let span_a = Point { x : self . b . x - self . a . x , y : self . b . y - self . a . y } ;
80
+ let span_b = Point { x : self . c . x - self . a . x , y : self . c . y - self . a . y } ;
81
81
82
82
let q = Point { x : p. x - self . a . x , y : p. y - self . a . y } ;
83
83
84
- let s = q. cross_product ( spanB ) as f32 * self . spanDiv ( ) ;
85
- let t = spanA . cross_product ( q) as f32 * self . spanDiv ( ) ;
84
+ let s = q. cross_product ( span_b ) as f32 * self . span_div ( ) ;
85
+ let t = span_a . cross_product ( q) as f32 * self . span_div ( ) ;
86
86
87
87
( s >= 0.0 ) && ( t >= 0.0 ) && ( ( s + t) <= 1.0 )
88
88
}
@@ -189,13 +189,13 @@ impl Geometrify {
189
189
// for x in 0..image.width() {
190
190
let p = Point { x : x as i32 , y : y as i32 } ;
191
191
if primitive. is_inside_primitive ( p) {
192
- * image. get_pixel_mut ( x as u32 , y as u32 ) = Geometrify :: mixColor ( primitive. get_color ( ) . expect ( "color of triangle not set" ) , * image. get_pixel ( x as u32 , y as u32 ) ) ;
192
+ * image. get_pixel_mut ( x as u32 , y as u32 ) = Geometrify :: mix_color ( primitive. get_color ( ) . expect ( "color of triangle not set" ) , * image. get_pixel ( x as u32 , y as u32 ) ) ;
193
193
}
194
194
}
195
195
}
196
196
}
197
197
198
- fn mixColor ( first : Rgba < u8 > , second : Rgba < u8 > ) -> Rgba < u8 > {
198
+ fn mix_color ( first : Rgba < u8 > , second : Rgba < u8 > ) -> Rgba < u8 > {
199
199
let ( r1, g1, b1, a1) = first. channels4 ( ) ;
200
200
let ( r2, g2, b2, a2) = second. channels4 ( ) ;
201
201
@@ -241,16 +241,16 @@ impl Geometrify {
241
241
242
242
for y in bb. top_left . y ..bb. bottom_right . y {
243
243
for x in bb. top_left . x ..bb. bottom_right . x {
244
- let originalRgb = original. get_pixel ( x as u32 , y as u32 ) ;
245
- let resultRgb = if ( bb. top_left . x as u32 <= x as u32 ) && ( x as u32 <= bb. bottom_right . x as u32 )
244
+ let original_rgb = original. get_pixel ( x as u32 , y as u32 ) ;
245
+ let result_rgb = if ( bb. top_left . x as u32 <= x as u32 ) && ( x as u32 <= bb. bottom_right . x as u32 )
246
246
&& ( bb. top_left . y as u32 <= y as u32 ) && ( y as u32 <= bb. bottom_right . y as u32 )
247
247
&& ( primitive. is_inside_primitive ( Point { x : x as i32 , y : y as i32 } ) ) {
248
- Geometrify :: mixColor ( * current. get_pixel ( x as u32 , y as u32 ) , primitive. get_color ( ) . expect ( "triangle color not " ) )
248
+ Geometrify :: mix_color ( * current. get_pixel ( x as u32 , y as u32 ) , primitive. get_color ( ) . expect ( "triangle color not " ) )
249
249
} else {
250
250
* current. get_pixel ( x as u32 , y as u32 )
251
251
} ;
252
252
253
- d += Geometrify :: difference ( * originalRgb , resultRgb ) as u64 ;
253
+ d += Geometrify :: difference ( * original_rgb , result_rgb ) as u64 ;
254
254
}
255
255
}
256
256
@@ -280,32 +280,32 @@ impl Geometrify {
280
280
result
281
281
}
282
282
283
- pub fn apply ( & mut self , image : RgbaImage , numberOfIterations : i32 , numberOfSamples : i32 ) -> RgbaImage {
284
- let mut progress = ProgressBar :: new ( numberOfIterations as u64 ) ;
283
+ pub fn apply ( & mut self , image : RgbaImage , number_of_iterations : i32 , number_of_samples : i32 ) -> RgbaImage {
284
+ let mut progress = ProgressBar :: new ( number_of_iterations as u64 ) ;
285
285
progress. format ( "|#--|" ) ;
286
286
287
287
let mut destination = RgbaImage :: new ( image. width ( ) , image. height ( ) ) ;
288
288
289
- for _ in 0 ..numberOfIterations {
289
+ for _ in 0 ..number_of_iterations {
290
290
let difference_lut = Geometrify :: calculate_difference_lut ( & image, & destination) ;
291
291
292
- let primitives = ( 0 ..numberOfSamples )
292
+ let primitives = ( 0 ..number_of_samples )
293
293
. map ( |_| {
294
294
self . generate_primitive ( )
295
295
} )
296
296
. map ( |mut p| {
297
- p. spanDivSave ( ) ;
297
+ p. span_div_save ( ) ;
298
298
p
299
299
} ) . collect :: < Vec < Triangle > > ( ) ;
300
- let minPrimitive = primitives. par_iter ( )
300
+ let min_primitive = primitives. par_iter ( )
301
301
. map ( |primitive| {
302
302
let mut prim = * primitive;
303
303
prim. color = Some ( Geometrify :: calculate_color ( & image, & prim) ) ;
304
304
( prim, Geometrify :: calculate_difference ( & image, & destination, & difference_lut, & prim) )
305
305
} )
306
306
. min_by_key ( |tup| tup. 1 ) ;
307
307
308
- Geometrify :: add_to_image ( & mut destination, & minPrimitive . expect ( "no fitting triangle found" ) . 0 ) ;
308
+ Geometrify :: add_to_image ( & mut destination, & min_primitive . expect ( "no fitting triangle found" ) . 0 ) ;
309
309
progress. inc ( ) ;
310
310
}
311
311
progress. finish_print ( "done" ) ;
0 commit comments